2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-01-12 17:44:04 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
2009-01-12 17:44:04 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-01-12 17:44:04 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2009-01-12 17:44:04 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-01-12 17:44:04 +01:00
|
|
|
|
|
|
|
|
#include "submitfilemodel.h"
|
|
|
|
|
#include "vcsbaseconstants.h"
|
|
|
|
|
|
2011-11-10 16:51:50 +01:00
|
|
|
#include <coreplugin/fileiconprovider.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QStandardItem>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QDebug>
|
2009-01-12 17:44:04 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
namespace VcsBase {
|
2009-01-12 17:44:04 +01:00
|
|
|
|
2011-10-19 15:49:13 +00:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// Helpers:
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
2013-01-02 22:19:04 +02:00
|
|
|
enum { fileColumn = 1 };
|
|
|
|
|
|
2011-10-19 15:49:13 +00:00
|
|
|
static QList<QStandardItem *> createFileRow(const QString &fileName, const QString &status,
|
2012-12-25 19:38:07 +02:00
|
|
|
CheckMode checked, const QVariant &v)
|
2011-10-19 15:49:13 +00:00
|
|
|
{
|
|
|
|
|
QStandardItem *statusItem = new QStandardItem(status);
|
2012-12-25 19:38:07 +02:00
|
|
|
statusItem->setCheckable(checked != Uncheckable);
|
|
|
|
|
if (checked != Uncheckable)
|
|
|
|
|
statusItem->setCheckState(checked == Checked ? Qt::Checked : Qt::Unchecked);
|
2011-10-19 15:49:13 +00:00
|
|
|
statusItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
|
|
|
|
|
statusItem->setData(v);
|
|
|
|
|
QStandardItem *fileItem = new QStandardItem(fileName);
|
|
|
|
|
fileItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
|
2011-11-10 16:51:50 +01:00
|
|
|
fileItem->setIcon(Core::FileIconProvider::instance()->icon(QFileInfo(fileName)));
|
2011-10-19 15:49:13 +00:00
|
|
|
QList<QStandardItem *> row;
|
|
|
|
|
row << statusItem << fileItem;
|
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// SubmitFileModel:
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
2011-03-28 14:19:17 +02:00
|
|
|
/*!
|
2012-01-07 12:31:48 +01:00
|
|
|
\class VcsBase::SubmitFileModel
|
2011-03-28 14:19:17 +02:00
|
|
|
|
|
|
|
|
\brief A 2-column (checkable, state, file name) model to be used to list the files
|
|
|
|
|
in the submit editor. Provides header items and a convience to add files.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-01-12 17:44:04 +01:00
|
|
|
SubmitFileModel::SubmitFileModel(QObject *parent) :
|
|
|
|
|
QStandardItemModel(0, 2, parent)
|
|
|
|
|
{
|
|
|
|
|
// setColumnCount(2);
|
|
|
|
|
QStringList headerLabels;
|
|
|
|
|
headerLabels << tr("State") << tr("File");
|
|
|
|
|
setHorizontalHeaderLabels(headerLabels);
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-25 19:38:07 +02:00
|
|
|
QList<QStandardItem *> SubmitFileModel::addFile(const QString &fileName, const QString &status, CheckMode checkMode,
|
2011-10-19 15:49:13 +00:00
|
|
|
const QVariant &v)
|
2009-01-13 10:06:06 +01:00
|
|
|
{
|
2012-12-25 19:38:07 +02:00
|
|
|
const QList<QStandardItem *> row = createFileRow(fileName, status, checkMode, v);
|
2009-01-12 17:44:04 +01:00
|
|
|
appendRow(row);
|
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-19 14:58:12 +00:00
|
|
|
QString SubmitFileModel::state(int row) const
|
|
|
|
|
{
|
|
|
|
|
if (row < 0 || row >= rowCount())
|
|
|
|
|
return QString();
|
|
|
|
|
return item(row)->text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString SubmitFileModel::file(int row) const
|
|
|
|
|
{
|
|
|
|
|
if (row < 0 || row >= rowCount())
|
|
|
|
|
return QString();
|
2013-01-02 22:19:04 +02:00
|
|
|
return item(row, fileColumn)->text();
|
2011-10-19 14:58:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SubmitFileModel::checked(int row) const
|
|
|
|
|
{
|
|
|
|
|
if (row < 0 || row >= rowCount())
|
|
|
|
|
return false;
|
|
|
|
|
return (item(row)->checkState() == Qt::Checked);
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-25 18:27:38 +02:00
|
|
|
void SubmitFileModel::setChecked(int row, bool check)
|
|
|
|
|
{
|
|
|
|
|
if (row >= 0 || row < rowCount())
|
|
|
|
|
item(row)->setCheckState(check ? Qt::Checked : Qt::Unchecked);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-02 22:19:04 +02:00
|
|
|
void SubmitFileModel::setAllChecked(bool check)
|
|
|
|
|
{
|
|
|
|
|
int rows = rowCount();
|
|
|
|
|
for (int row = 0; row < rows; ++row)
|
|
|
|
|
item(row)->setCheckState(check ? Qt::Checked : Qt::Unchecked);
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-19 15:33:20 +01:00
|
|
|
QVariant SubmitFileModel::extraData(int row) const
|
2011-10-19 15:49:13 +00:00
|
|
|
{
|
|
|
|
|
if (row < 0 || row >= rowCount())
|
|
|
|
|
return false;
|
|
|
|
|
return item(row)->data();
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-19 14:58:12 +00:00
|
|
|
bool SubmitFileModel::hasCheckedFiles() const
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < rowCount(); ++i) {
|
|
|
|
|
if (checked(i))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-02 22:19:04 +02:00
|
|
|
unsigned int SubmitFileModel::filterFiles(const QStringList &filter)
|
2009-01-12 17:44:04 +01:00
|
|
|
{
|
2013-01-02 22:19:04 +02:00
|
|
|
unsigned int rc = 0;
|
2009-01-12 17:44:04 +01:00
|
|
|
for (int r = rowCount() - 1; r >= 0; r--)
|
2013-01-02 22:19:04 +02:00
|
|
|
if (!filter.contains(file(r))) {
|
|
|
|
|
removeRow(r);
|
|
|
|
|
rc++;
|
|
|
|
|
}
|
2009-01-12 17:44:04 +01:00
|
|
|
return rc;
|
|
|
|
|
}
|
2011-11-10 16:51:50 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
} // namespace VcsBase
|