1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "sourcefileshandler.h"
35 #include <QtCore/QDebug>
36 #include <QtCore/QFileInfo>
38 #include <QtGui/QSortFilterProxyModel>
43 SourceFilesHandler::SourceFilesHandler()
45 QSortFilterProxyModel *proxy = new QSortFilterProxyModel(this);
46 proxy->setSourceModel(this);
50 void SourceFilesHandler::clearModel()
52 if (m_shortNames.isEmpty())
59 QVariant SourceFilesHandler::headerData(int section,
60 Qt::Orientation orientation, int role) const
62 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
63 static QString headers[] = {
64 tr("Internal name") + " ",
65 tr("Full name") + " ",
67 return headers[section];
72 Qt::ItemFlags SourceFilesHandler::flags(const QModelIndex &index) const
74 if (index.row() >= m_fullNames.size())
76 QFileInfo fi(m_fullNames.at(index.row()));
77 return fi.isReadable() ? QAbstractItemModel::flags(index) : Qt::ItemFlags(0);
80 QVariant SourceFilesHandler::data(const QModelIndex &index, int role) const
82 int row = index.row();
83 if (row < 0 || row >= m_shortNames.size())
86 switch (index.column()) {
88 if (role == Qt::DisplayRole)
89 return m_shortNames.at(row);
91 //if (role == Qt::DecorationRole)
92 // return module.symbolsRead ? icon2 : icon;
95 if (role == Qt::DisplayRole)
96 return m_fullNames.at(row);
97 //if (role == Qt::DecorationRole)
98 // return module.symbolsRead ? icon2 : icon;
104 void SourceFilesHandler::setSourceFiles(const QMap<QString, QString> &sourceFiles)
106 m_shortNames.clear();
108 QMap<QString, QString>::ConstIterator it = sourceFiles.begin();
109 QMap<QString, QString>::ConstIterator et = sourceFiles.end();
110 for (; it != et; ++it) {
111 m_shortNames.append(it.key());
112 m_fullNames.append(it.value());
117 void SourceFilesHandler::removeAll()
119 setSourceFiles(QMap<QString, QString>());
120 //header()->setResizeMode(0, QHeaderView::ResizeToContents);
123 } // namespace Internal
124 } // namespace Debugger