forked from qt-creator/qt-creator
C++: introduce the unique ProjectPart::id()
And change the code-model inspector dialog to use them in the ProjectParts tab to sync the master/details view, and in the CppPreProcessorDialog to save/reload the selected part. Change-Id: I7cc8ac1c21d31122f8650985d0b85177ebabdfb8 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
committed by
Nikolai Kosjar
parent
eedd47657f
commit
8b2cff4b8b
@@ -954,7 +954,7 @@ public:
|
||||
const ProjectPart::Ptr ¤tEditorsProjectPart);
|
||||
|
||||
QModelIndex indexForCurrentEditorsProjectPart() const;
|
||||
ProjectPart::Ptr projectPartForProjectFile(const QString &projectFilePath) const;
|
||||
ProjectPart::Ptr projectPartForProjectId(const QString &projectPartId) const;
|
||||
|
||||
enum Columns { PartNameColumn, PartFilePathColumn, ColumnCount };
|
||||
|
||||
@@ -997,10 +997,10 @@ QModelIndex ProjectPartsModel::indexForCurrentEditorsProjectPart() const
|
||||
return createIndex(m_currentEditorsProjectPartIndex, PartFilePathColumn);
|
||||
}
|
||||
|
||||
ProjectPart::Ptr ProjectPartsModel::projectPartForProjectFile(const QString &projectFilePath) const
|
||||
ProjectPart::Ptr ProjectPartsModel::projectPartForProjectId(const QString &projectPartId) const
|
||||
{
|
||||
foreach (const ProjectPart::Ptr &part, m_projectPartsList) {
|
||||
if (part->projectFile == projectFilePath)
|
||||
if (part->id() == projectPartId)
|
||||
return part;
|
||||
}
|
||||
return ProjectPart::Ptr();
|
||||
@@ -1025,6 +1025,8 @@ QVariant ProjectPartsModel::data(const QModelIndex &index, int role) const
|
||||
return m_projectPartsList.at(row)->displayName;
|
||||
else if (column == PartFilePathColumn)
|
||||
return QDir::toNativeSeparators(m_projectPartsList.at(row)->projectFile);
|
||||
} else if (role == Qt::UserRole) {
|
||||
return m_projectPartsList.at(row)->id();
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
@@ -1307,9 +1309,8 @@ void CppCodeModelInspectorDialog::onProjectPartSelected(const QModelIndex &curre
|
||||
QModelIndex index = m_proxyProjectPartsModel->mapToSource(current);
|
||||
if (index.isValid()) {
|
||||
index = m_projectPartsModel->index(index.row(), ProjectPartsModel::PartFilePathColumn);
|
||||
const QString projectFilePath = QDir::fromNativeSeparators(
|
||||
m_projectPartsModel->data(index, Qt::DisplayRole).toString());
|
||||
updateProjectPartData(m_projectPartsModel->projectPartForProjectFile(projectFilePath));
|
||||
const QString projectPartId = m_projectPartsModel->data(index, Qt::UserRole).toString();
|
||||
updateProjectPartData(m_projectPartsModel->projectPartForProjectId(projectPartId));
|
||||
}
|
||||
} else {
|
||||
clearProjectPartData();
|
||||
|
||||
@@ -57,7 +57,7 @@ CppPreProcessorDialog::CppPreProcessorDialog(QWidget *parent, const QString &fil
|
||||
|
||||
CppSnippetProvider().decorateEditor(m_ui->editWidget);
|
||||
|
||||
const QString ¤tProjectFile = ProjectExplorer::SessionManager::value(
|
||||
const QString &projectPartIdToUse = ProjectExplorer::SessionManager::value(
|
||||
QLatin1String(Constants::CPP_PREPROCESSOR_PROJECT_PREFIX) + m_filePath).toString();
|
||||
int currentIndex = 0;
|
||||
|
||||
@@ -70,7 +70,7 @@ CppPreProcessorDialog::CppPreProcessorDialog(QWidget *parent, const QString &fil
|
||||
addition.projectPart = projectPart;
|
||||
addition.additionalDirectives = ProjectExplorer::SessionManager::value(
|
||||
projectPart->projectFile + QLatin1Char(',') + m_filePath).toString();
|
||||
if (projectPart->projectFile == currentProjectFile)
|
||||
if (projectPart->id() == projectPartIdToUse)
|
||||
currentIndex = m_ui->projectComboBox->count() - 1;
|
||||
m_partAdditions << addition;
|
||||
}
|
||||
@@ -95,7 +95,7 @@ int CppPreProcessorDialog::exec()
|
||||
|
||||
ProjectExplorer::SessionManager::setValue(
|
||||
QLatin1String(Constants::CPP_PREPROCESSOR_PROJECT_PREFIX) + m_filePath,
|
||||
m_partAdditions[m_ui->projectComboBox->currentIndex()].projectPart->projectFile);
|
||||
m_partAdditions[m_ui->projectComboBox->currentIndex()].projectPart->id());
|
||||
|
||||
foreach (ProjectPartAddition partAddition, m_partAdditions) {
|
||||
const QString &previousDirectives = ProjectExplorer::SessionManager::value(
|
||||
|
||||
@@ -113,6 +113,11 @@ ProjectPart::Ptr ProjectPart::copy() const
|
||||
return Ptr(new ProjectPart(*this));
|
||||
}
|
||||
|
||||
QString ProjectPart::id() const
|
||||
{
|
||||
return QDir::fromNativeSeparators(projectFile) + QLatin1Char(' ') + displayName;
|
||||
}
|
||||
|
||||
QByteArray ProjectPart::readProjectConfigFile(const ProjectPart::Ptr &part)
|
||||
{
|
||||
QByteArray result;
|
||||
|
||||
@@ -106,6 +106,8 @@ public: // methods
|
||||
|
||||
Ptr copy() const;
|
||||
|
||||
QString id() const;
|
||||
|
||||
static QByteArray readProjectConfigFile(const ProjectPart::Ptr &part);
|
||||
|
||||
public: // fields
|
||||
|
||||
Reference in New Issue
Block a user