OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / debugger / sourcefileshandler.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 (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "sourcefileshandler.h"
34
35 #include <QtCore/QDebug>
36 #include <QtCore/QFileInfo>
37
38 #include <QtGui/QSortFilterProxyModel>
39
40 namespace Debugger {
41 namespace Internal {
42
43 SourceFilesHandler::SourceFilesHandler()
44 {
45     QSortFilterProxyModel *proxy = new QSortFilterProxyModel(this);
46     proxy->setSourceModel(this);
47     m_proxyModel = proxy;
48 }
49
50 void SourceFilesHandler::clearModel()
51 {
52     if (m_shortNames.isEmpty())
53         return;
54     m_shortNames.clear();
55     m_fullNames.clear();
56     reset();
57 }
58
59 QVariant SourceFilesHandler::headerData(int section,
60     Qt::Orientation orientation, int role) const
61 {
62     if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
63         static QString headers[] = {
64             tr("Internal name") + "        ",
65             tr("Full name") + "        ",
66         };
67         return headers[section];
68     }
69     return QVariant();
70 }
71
72 Qt::ItemFlags SourceFilesHandler::flags(const QModelIndex &index) const
73 {
74     if (index.row() >= m_fullNames.size())
75         return 0;
76     QFileInfo fi(m_fullNames.at(index.row()));
77     return fi.isReadable() ? QAbstractItemModel::flags(index) : Qt::ItemFlags(0);
78 }
79
80 QVariant SourceFilesHandler::data(const QModelIndex &index, int role) const
81 {
82     int row = index.row();
83     if (row < 0 || row >= m_shortNames.size())
84         return QVariant();
85
86     switch (index.column()) {
87         case 0:
88             if (role == Qt::DisplayRole)
89                 return m_shortNames.at(row);
90             // FIXME: add icons
91             //if (role == Qt::DecorationRole)
92             //    return module.symbolsRead ? icon2 : icon;
93             break;
94         case 1:
95             if (role == Qt::DisplayRole)
96                 return m_fullNames.at(row);
97             //if (role == Qt::DecorationRole)
98             //    return module.symbolsRead ? icon2 : icon;
99             break;
100     }
101     return QVariant();
102 }
103
104 void SourceFilesHandler::setSourceFiles(const QMap<QString, QString> &sourceFiles)
105 {
106     m_shortNames.clear();
107     m_fullNames.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());
113     }
114     reset();
115 }
116
117 void SourceFilesHandler::removeAll()
118 {
119     setSourceFiles(QMap<QString, QString>());
120     //header()->setResizeMode(0, QHeaderView::ResizeToContents);
121 }
122
123 } // namespace Internal
124 } // namespace Debugger