Files
qt-creator/src/plugins/qt4projectmanager/qt-maemo/maemopublishedprojectmodel.cpp

117 lines
3.6 KiB
C++
Raw Normal View History

/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of Qt Creator.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "maemopublishedprojectmodel.h"
namespace Qt4ProjectManager {
namespace Internal {
namespace {
const int IncludeColumn = 2;
} // anonymous namespace
MaemoPublishedProjectModel::MaemoPublishedProjectModel(QObject *parent)
: QFileSystemModel(parent)
{
}
int MaemoPublishedProjectModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return IncludeColumn + 1;
}
int MaemoPublishedProjectModel::rowCount(const QModelIndex &parent) const
{
if (isDir(parent) && m_filesToExclude.contains(filePath(parent)))
return 0;
return QFileSystemModel::rowCount(parent);
}
QVariant MaemoPublishedProjectModel::headerData(int section,
Qt::Orientation orientation, int role) const
{
if (orientation != Qt::Horizontal || section != IncludeColumn)
return QFileSystemModel::headerData(section, orientation, role);
return tr("Include in package");
}
Qt::ItemFlags MaemoPublishedProjectModel::flags(const QModelIndex &index) const
{
if (index.column() != IncludeColumn)
return QFileSystemModel::flags(index);
return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable;
}
QVariant MaemoPublishedProjectModel::data(const QModelIndex &index,
int role) const
{
if (index.column() != IncludeColumn)
return QFileSystemModel::data(index, role);
const bool include = !m_filesToExclude.contains(filePath(index));
if (role == Qt::DisplayRole)
return include ? tr("Include") : tr("Don't include");
else if (role == Qt::CheckStateRole)
return include ? Qt::Checked : Qt::Unchecked;
else
return QVariant();
}
bool MaemoPublishedProjectModel::setData(const QModelIndex &index,
const QVariant &value, int role)
{
if (index.column() != IncludeColumn)
return QFileSystemModel::setData(index, value, role);
if (role == Qt::CheckStateRole) {
if (value == Qt::Checked) {
m_filesToExclude.remove(filePath(index));
} else {
m_filesToExclude.insert(filePath(index));
}
if (isDir(index))
emit layoutChanged();
return true;
}
return false;
}
} // namespace Internal
} // namespace Qt4ProjectManager