OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / vcsbase / submitfilemodel.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "submitfilemodel.h"
35 #include "vcsbaseconstants.h"
36
37 #include <QtGui/QStandardItem>
38 #include <QtCore/QDebug>
39
40 namespace VCSBase {
41
42 SubmitFileModel::SubmitFileModel(QObject *parent) :
43     QStandardItemModel(0, 2, parent)
44 {
45     // setColumnCount(2);
46     QStringList headerLabels;
47     headerLabels << tr("State") << tr("File");
48     setHorizontalHeaderLabels(headerLabels);
49 }
50
51 QList<QStandardItem *> SubmitFileModel::createFileRow(const QString &fileName, const QString &status, bool checked)
52 {
53     if (VCSBase::Constants::Internal::debug)
54         qDebug() << Q_FUNC_INFO << fileName << status << checked;
55     QStandardItem *statusItem = new QStandardItem(status);
56     statusItem->setCheckable(true);
57     statusItem->setCheckState(checked ? Qt::Checked : Qt::Unchecked);
58     statusItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
59     QStandardItem *fileItem = new QStandardItem(fileName);
60     fileItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
61     QList<QStandardItem *> row;
62     row << statusItem << fileItem;
63     return row;
64 }
65
66 QList<QStandardItem *> SubmitFileModel::addFile(const QString &fileName, const QString &status, bool checked)
67 {
68     const QList<QStandardItem *> row = createFileRow(fileName, status, checked);
69     appendRow(row);
70     return row;
71 }
72
73 QList<QStandardItem *> SubmitFileModel::rowAt(int row) const
74 {
75     const int colCount = columnCount();
76     QList<QStandardItem *> rc;
77     for (int c = 0; c < colCount; c++)
78         rc.push_back(item(row, c));
79     return rc;
80 }
81
82 QList<QStandardItem *> SubmitFileModel::findRow(const QString &text, int column) const
83 {
84     // Single item
85     const QList<QStandardItem *> items = findItems(text, Qt::MatchExactly, column);
86     if (items.empty())
87         return items;
88     // Compile row
89     return rowAt(items.front()->row());
90  }
91
92 unsigned SubmitFileModel::filter(const QStringList &filter, int column)
93 {
94     unsigned rc = 0;
95     for (int r = rowCount() - 1; r >= 0; r--)
96         if (const QStandardItem *i = item(r, column))
97             if (!filter.contains(i->text())) {
98                 qDeleteAll(takeRow(r));
99                 rc++;
100             }
101     if (VCSBase::Constants::Internal::debug)
102         qDebug() << Q_FUNC_INFO << " deleted " << rc << " items using " << filter << " , remaining " << rowCount();
103     return rc;
104 }
105 }