Fix selection of project files to add new files/classes to

Commit ac8e371486 did reorder the path list in
ProjectWizardPage, while ProjceFileWizardExtension still assumed
that the list displayed to the user is exactly the same as passed
to ProjectWizardPage.

The patch removes the index based communication between the
classes altogether and directly stores the ProjectNode in the
UserRole of the ComboBox entry.
This commit is contained in:
Kai Koehne
2009-07-17 18:06:08 +10:00
parent 0f7394323d
commit 063f0476da
3 changed files with 34 additions and 27 deletions

View File

@@ -141,20 +141,8 @@ QList<QWizardPage *> ProjectFileWizardExtension::extensionPages(const Core::IWiz
// Disable "add project to project"
const bool hasProjects = !m_context->projects.empty();
if (hasProjects) {
// Compile list of names and find current project if there is one
QStringList projectNames;
ProjectNode *current = currentProject();
int currentIndex = -1;
const int count = m_context->projects.size();
for (int i = 0; i < count; i++) {
ProjectNode *pn = m_context->projects.at(i);
projectNames.push_back(QFileInfo(pn->path()).fileName());
if (current == pn)
currentIndex = i;
}
m_context->page->setProjects(projectNames);
if (currentIndex != -1)
m_context->page->setCurrentProjectIndex(currentIndex);
m_context->page->setProjects(m_context->projects);
m_context->page->setCurrentProject(currentProject());
}
m_context->page->setAddToProjectEnabled(hasProjects && wizard->kind() != Core::IWizard::ProjectWizard);
@@ -166,7 +154,7 @@ bool ProjectFileWizardExtension::process(const QList<Core::GeneratedFile> &files
typedef QMultiMap<FileType, QString> TypeFileMap;
// Add files to project && version control
if (m_context->page->addToProject()) {
ProjectNode *project = m_context->projects.at(m_context->page->currentProjectIndex());
ProjectNode *project = m_context->page->currentProject();
// Split into lists by file type and add
TypeFileMap typeFileMap;
foreach (const Core::GeneratedFile &generatedFile, files) {

View File

@@ -29,13 +29,17 @@
#include "projectwizardpage.h"
#include "ui_projectwizardpage.h"
#include "projectnodes.h"
#include <QtCore/QDebug>
#include <QtCore/QFileInfo>
#include <QtCore/QTextStream>
using namespace ProjectExplorer;
using namespace Internal;
Q_DECLARE_METATYPE(ProjectExplorer::ProjectNode*)
ProjectWizardPage::ProjectWizardPage(QWidget *parent) :
QWizardPage(parent),
m_ui(new Ui::WizardPage)
@@ -51,13 +55,19 @@ ProjectWizardPage::~ProjectWizardPage()
delete m_ui;
}
void ProjectWizardPage::setProjects(const QStringList &l)
void ProjectWizardPage::setProjects(const QList<ProjectNode*> &projectNodes)
{
QStringList list = l;
list.removeDuplicates();
list.sort();
QMap<QString,ProjectNode*> projectMap;
foreach (ProjectNode *node, projectNodes) {
QString name = QFileInfo(node->path()).fileName();
if (!projectMap.contains(name))
projectMap.insert(name, node);
}
m_ui->projectComboBox->clear();
m_ui->projectComboBox->addItems(list);
foreach (const QString &name, projectMap.keys()) {
m_ui->projectComboBox->addItem(name, qVariantFromValue(projectMap.value(name)));
}
}
void ProjectWizardPage::setAddToProjectEnabled(bool b)
@@ -69,14 +79,22 @@ void ProjectWizardPage::setAddToProjectEnabled(bool b)
m_ui->projectComboBox->setEnabled(b);
}
int ProjectWizardPage::currentProjectIndex() const
ProjectNode *ProjectWizardPage::currentProject() const
{
return m_ui->projectComboBox->currentIndex();
QVariant variant = m_ui->projectComboBox->itemData(m_ui->projectComboBox->currentIndex());
return qVariantValue<ProjectNode*>(variant);
}
void ProjectWizardPage::setCurrentProjectIndex(int i)
void ProjectWizardPage::setCurrentProject(ProjectNode *projectNode)
{
m_ui->projectComboBox->setCurrentIndex(i);
if (!projectNode)
return;
for (int i = 0; i < m_ui->projectComboBox->count(); ++i) {
if (qVariantValue<ProjectNode*>(m_ui->projectComboBox->itemData(i)) == projectNode) {
m_ui->projectComboBox->setCurrentIndex(i);
return;
}
}
}
bool ProjectWizardPage::addToProject() const

View File

@@ -55,9 +55,10 @@ public:
explicit ProjectWizardPage(QWidget *parent = 0);
virtual ~ProjectWizardPage();
void setProjects(const QStringList &);
void setCurrentProjectIndex(int);
int currentProjectIndex() const;
void setProjects(const QList<ProjectNode *> &);
void setCurrentProject(ProjectNode *);
ProjectNode *currentProject() const;
void setAddToProjectEnabled(bool b);
bool addToProject() const;