Rename IWizard::Kind --> IWizard::WizardKind, add some logic for which wizard kinds to collapse/expand.

This commit is contained in:
con
2010-01-14 14:14:39 +01:00
parent d4be77b48f
commit 4a46d0864b
16 changed files with 113 additions and 36 deletions

View File

@@ -53,7 +53,8 @@ using namespace Core::Internal;
NewDialog::NewDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Core::Internal::Ui::NewDialog),
m_okButton(0)
m_okButton(0),
m_preferredWizardKinds(0)
{
typedef QMap<QString, QTreeWidgetItem *> CategoryItemMap;
m_ui->setupUi(this);
@@ -79,6 +80,11 @@ bool wizardLessThan(const IWizard *w1, const IWizard *w2)
return w1->id().compare(w2->id()) < 0;
}
void NewDialog::setPreferredWizardKinds(IWizard::WizardKinds kinds)
{
m_preferredWizardKinds = kinds;
}
void NewDialog::setWizards(QList<IWizard*> wizards)
{
typedef QMap<QString, QTreeWidgetItem *> CategoryItemMap;
@@ -112,11 +118,34 @@ void NewDialog::setWizards(QList<IWizard*> wizards)
Core::IWizard *NewDialog::showDialog()
{
m_ui->templatesTree->expandAll();
if (QTreeWidgetItem *rootItem = m_ui->templatesTree->topLevelItem(0)) {
m_ui->templatesTree->scrollToItem(rootItem);
if (rootItem->childCount())
m_ui->templatesTree->setCurrentItem(rootItem->child(0));
QTreeWidgetItem *itemToSelect = 0;
if (m_preferredWizardKinds == 0) {
m_ui->templatesTree->expandAll();
if (QTreeWidgetItem *rootItem = m_ui->templatesTree->topLevelItem(0)) {
if (rootItem->childCount())
itemToSelect = rootItem->child(0);
}
} else {
for (int i = 0; i < m_ui->templatesTree->topLevelItemCount(); ++i) {
QTreeWidgetItem *category = m_ui->templatesTree->topLevelItem(i);
bool hasOnlyPreferred = true;
for (int j = 0; j < category->childCount(); ++j) {
QTreeWidgetItem *item = category->child(j);
if (!(item->data(0, Qt::UserRole).value<IWizard*>()
->kind() & m_preferredWizardKinds)) {
hasOnlyPreferred = false;
break;
}
}
category->setExpanded(hasOnlyPreferred);
if (hasOnlyPreferred && itemToSelect == 0 && category->childCount() > 0) {
itemToSelect = category->child(0);
}
}
}
if (itemToSelect) {
m_ui->templatesTree->scrollToItem(itemToSelect);
m_ui->templatesTree->setCurrentItem(itemToSelect);
}
updateOkButton();
if (exec() != Accepted)