forked from qt-creator/qt-creator
CppTools: Show file kind in code model inspector
Change-Id: I5cdc6ec672a970a6fcfa52dfa14c2f515cf27f6d Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -201,6 +201,84 @@ void FilterableView::clearFilter()
|
||||
lineEdit->clear();
|
||||
}
|
||||
|
||||
// --- ProjectFilesModel --------------------------------------------------------------------------
|
||||
|
||||
class ProjectFilesModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectFilesModel(QObject *parent);
|
||||
void configure(const QVector<ProjectFile> &files);
|
||||
void clear();
|
||||
|
||||
enum Columns { FileKindColumn, FilePathColumn, ColumnCount };
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||
|
||||
private:
|
||||
QVector<ProjectFile> m_files;
|
||||
};
|
||||
|
||||
ProjectFilesModel::ProjectFilesModel(QObject *parent) : QAbstractListModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void ProjectFilesModel::configure(const QVector<ProjectFile> &files)
|
||||
{
|
||||
emit layoutAboutToBeChanged();
|
||||
m_files = files;
|
||||
emit layoutChanged();
|
||||
}
|
||||
|
||||
void ProjectFilesModel::clear()
|
||||
{
|
||||
emit layoutAboutToBeChanged();
|
||||
m_files.clear();
|
||||
emit layoutChanged();
|
||||
}
|
||||
|
||||
int ProjectFilesModel::rowCount(const QModelIndex &/*parent*/) const
|
||||
{
|
||||
return m_files.size();
|
||||
}
|
||||
|
||||
int ProjectFilesModel::columnCount(const QModelIndex &/*parent*/) const
|
||||
{
|
||||
return ProjectFilesModel::ColumnCount;
|
||||
}
|
||||
|
||||
QVariant ProjectFilesModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole) {
|
||||
const int row = index.row();
|
||||
const int column = index.column();
|
||||
if (column == FileKindColumn) {
|
||||
return CMI::Utils::toString(m_files.at(row).kind);
|
||||
} else if (column == FilePathColumn) {
|
||||
return m_files.at(row).path;
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant ProjectFilesModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
||||
switch (section) {
|
||||
case FileKindColumn:
|
||||
return QLatin1String("File Kind");
|
||||
case FilePathColumn:
|
||||
return QLatin1String("File Path");
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
// --- KeyValueModel ------------------------------------------------------------------------------
|
||||
|
||||
class KeyValueModel : public QAbstractListModel
|
||||
@@ -1175,6 +1253,7 @@ CppCodeModelInspectorDialog::CppCodeModelInspectorDialog(QWidget *parent)
|
||||
, m_projectPartsModel(new ProjectPartsModel(this))
|
||||
, m_proxyProjectPartsModel(new QSortFilterProxyModel(this))
|
||||
, m_partGenericInfoModel(new KeyValueModel(this))
|
||||
, m_projectFilesModel(new ProjectFilesModel(this))
|
||||
, m_workingCopyView(new FilterableView(this))
|
||||
, m_workingCopyModel(new WorkingCopyModel(this))
|
||||
, m_proxyWorkingCopyModel(new QSortFilterProxyModel(this))
|
||||
@@ -1201,6 +1280,7 @@ CppCodeModelInspectorDialog::CppCodeModelInspectorDialog(QWidget *parent)
|
||||
m_proxyProjectPartsModel->setFilterKeyColumn(ProjectPartsModel::PartFilePathColumn);
|
||||
m_projectPartsView->setModel(m_proxyProjectPartsModel);
|
||||
m_ui->partGeneralView->setModel(m_partGenericInfoModel);
|
||||
m_ui->projectFilesView->setModel(m_projectFilesModel);
|
||||
|
||||
m_proxyWorkingCopyModel->setSourceModel(m_workingCopyModel);
|
||||
m_proxyWorkingCopyModel->setFilterKeyColumn(WorkingCopyModel::FilePathColumn);
|
||||
@@ -1584,8 +1664,8 @@ static QString partTabName(int tabIndex, int numberOfEntries = -1)
|
||||
void CppCodeModelInspectorDialog::clearProjectPartData()
|
||||
{
|
||||
m_partGenericInfoModel->clear();
|
||||
m_projectFilesModel->clear();
|
||||
|
||||
m_ui->partProjectFilesEdit->clear();
|
||||
m_ui->projectPartTab->setTabText(ProjectPartFilesTab, partTabName(ProjectPartFilesTab));
|
||||
|
||||
m_ui->partToolchainDefinesEdit->clear();
|
||||
@@ -1632,7 +1712,7 @@ void CppCodeModelInspectorDialog::updateProjectPartData(const ProjectPart::Ptr &
|
||||
resizeColumns<KeyValueModel>(m_ui->partGeneralView);
|
||||
|
||||
// Project Files
|
||||
m_ui->partProjectFilesEdit->setPlainText(CMI::Utils::toString(part->files));
|
||||
m_projectFilesModel->configure(part->files);
|
||||
m_ui->projectPartTab->setTabText(ProjectPartFilesTab,
|
||||
partTabName(ProjectPartFilesTab, part->files.size()));
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ class IncludesModel;
|
||||
class KeyValueModel;
|
||||
class MacrosModel;
|
||||
class ProjectPartsModel;
|
||||
class ProjectFilesModel;
|
||||
class SnapshotModel;
|
||||
class SymbolsModel;
|
||||
class TokensModel;
|
||||
@@ -110,6 +111,7 @@ private:
|
||||
ProjectPartsModel *m_projectPartsModel;
|
||||
QSortFilterProxyModel *m_proxyProjectPartsModel;
|
||||
KeyValueModel *m_partGenericInfoModel;
|
||||
ProjectFilesModel *m_projectFilesModel;
|
||||
|
||||
// Working Copy
|
||||
FilterableView *m_workingCopyView;
|
||||
|
||||
@@ -212,11 +212,7 @@
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_14">
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="partProjectFilesEdit">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QTreeView" name="projectFilesView"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
||||
@@ -138,15 +138,6 @@ QString Utils::toString(ProjectPart::QtVersion qtVersion)
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString Utils::toString(const QVector<ProjectFile> &projectFiles)
|
||||
{
|
||||
QStringList filesList;
|
||||
foreach (const ProjectFile &projectFile, projectFiles)
|
||||
filesList << QDir::toNativeSeparators(projectFile.path);
|
||||
::Utils::sort(filesList);
|
||||
return filesList.join(QLatin1Char('\n'));
|
||||
}
|
||||
|
||||
QString Utils::toString(ProjectFile::Kind kind)
|
||||
{
|
||||
#define CASE_PROFECTFILEKIND(x) case ProjectFile::x: return QLatin1String(#x)
|
||||
|
||||
Reference in New Issue
Block a user