Commit 5c568a68 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Disable targets in the targetselectionpage

 * Allow to restrict possible targets in the targetselectionpage
 * Only show the page when it makes sense

Reviewed-by: Friedemann Kleint
parent c47b3812
......@@ -203,11 +203,16 @@ void BaseQt4ProjectWizardDialog::addModulesPage(int id)
}
}
void BaseQt4ProjectWizardDialog::addTargetsPage(int id)
void BaseQt4ProjectWizardDialog::addTargetsPage(QSet<QString> targets, int id)
{
if (!m_targetsPage)
return;
m_targetsPage->setValidTargets(targets);
if (!m_targetsPage->needToDisplayPage())
return;
if (id >= 0)
setPage(id, m_targetsPage);
else
......
......@@ -35,6 +35,7 @@
#include <coreplugin/basefilewizard.h>
#include <QtCore/QSet>
namespace Qt4ProjectManager {
namespace Internal {
......@@ -101,7 +102,7 @@ protected:
QWidget *parent = 0);
void addModulesPage(int id = -1);
void addTargetsPage(int id = -1);
void addTargetsPage(QSet<QString> targets = QSet<QString>(), int id = -1);
public:
QString selectedModules() const;
......
......@@ -100,11 +100,28 @@ TargetsPage::TargetsPage(QWidget *parent)
emit completeChanged();
}
void TargetsPage::setValidTargets(const QSet<QString> &targets)
{
if (targets.isEmpty())
return;
for (int i = 0; i < m_treeWidget->topLevelItemCount(); ++i) {
QTreeWidgetItem *currentTargetItem = m_treeWidget->topLevelItem(i);
QString currentTarget = currentTargetItem->data(0, Qt::UserRole).toString();
if (targets.contains(currentTarget))
currentTargetItem->setHidden(false);
else
currentTargetItem->setHidden(true);
}
}
QSet<QString> TargetsPage::selectedTargets() const
{
QSet<QString> result;
for (int i = 0; i < m_treeWidget->topLevelItemCount(); ++i) {
QString target = m_treeWidget->topLevelItem(i)->data(0, Qt::UserRole).toString();
QTreeWidgetItem * targetItem = m_treeWidget->topLevelItem(i);
QString target = targetItem->data(0, Qt::UserRole).toString();
QList<int> versions = selectedVersionIdsForTarget(target);
if (!versions.isEmpty())
result.insert(target);
......@@ -118,7 +135,7 @@ QList<int> TargetsPage::selectedVersionIdsForTarget(const QString &t) const
for (int i = 0; i < m_treeWidget->topLevelItemCount(); ++i) {
QTreeWidgetItem * current = m_treeWidget->topLevelItem(i);
QString target = current->data(0, Qt::UserRole).toString();
if (t != target)
if (t != target || current->isHidden())
continue;
for (int j = 0; j < current->childCount(); ++j) {
......@@ -140,3 +157,20 @@ bool TargetsPage::isComplete() const
{
return !selectedTargets().isEmpty();
}
bool TargetsPage::needToDisplayPage() const
{
int targetCount = 0;
for (int i = 0; i < m_treeWidget->topLevelItemCount(); ++i) {
QTreeWidgetItem * current = m_treeWidget->topLevelItem(i);
if (current->isHidden())
continue;
++targetCount;
if (targetCount > 1)
return true;
if (current->childCount() > 1)
return true;
}
return false;
}
......@@ -50,15 +50,20 @@ class TargetsPage : public QWizardPage
public:
explicit TargetsPage(QWidget* parent = 0);
void setValidTargets(const QSet<QString> &targets);
QSet<QString> selectedTargets() const;
QList<int> selectedVersionIdsForTarget(const QString &) const;
bool isComplete() const;
bool needToDisplayPage() const;
private slots:
void itemWasClicked();
private:
QSet<QString> m_validTargets;
QTreeWidget * m_treeWidget;
bool m_isComplete;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment