Polish the Qt Designer custom widget wizard

Start editing the class name when wizard page
is initialized. Show a disabled widget page
for the dummy widget item (least surprise).
Add +/- buttons. Refuse invalid class names
(by introducing an item model with setData()
validation. Code polishing, explicitness, etc.
Task-number: QTCREATORBUG-1123
This commit is contained in:
Friedemann Kleint
2010-04-13 16:13:06 +02:00
parent 656899842c
commit 44ce228a6a
8 changed files with 266 additions and 110 deletions

View File

@@ -32,9 +32,13 @@
#include "plugingenerator.h"
#include "classdefinition.h"
#include <coreplugin/coreconstants.h>
#include <QtCore/QFileInfo>
#include <QtCore/QTimer>
#include <QtGui/QStackedLayout>
#include <QtGui/QIcon>
namespace Qt4ProjectManager {
namespace Internal {
@@ -42,13 +46,25 @@ namespace Internal {
CustomWidgetWidgetsWizardPage::CustomWidgetWidgetsWizardPage(QWidget *parent) :
QWizardPage(parent),
m_ui(new Ui::CustomWidgetWidgetsWizardPage),
m_tabStackLayout(new QStackedLayout),
m_complete(false)
{
m_ui->setupUi(this);
m_tabStack = new QStackedLayout(m_ui->tabStackWidget);
m_dummyTab = new QWidget(m_ui->tabStackWidget);
m_tabStack->addWidget(m_dummyTab);
connect(m_ui->classList, SIGNAL(currentRowChanged(int)), m_tabStack, SLOT(setCurrentIndex(int)));
m_ui->tabStackWidget->setLayout(m_tabStackLayout);
m_ui->addButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_PLUS)));
connect(m_ui->addButton, SIGNAL(clicked()), m_ui->classList, SLOT(startEditingNewClassItem()));
m_ui->deleteButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_MINUS)));
connect(m_ui->deleteButton, SIGNAL(clicked()), m_ui->classList, SLOT(removeCurrentClass()));
m_ui->deleteButton->setEnabled(false);
// Disabled dummy for <new class> column>.
ClassDefinition *dummy = new ClassDefinition;
dummy->setFileNamingParameters(m_fileNamingParameters);
dummy->setEnabled(false);
m_tabStackLayout->addWidget(dummy);
connect(m_ui->classList, SIGNAL(currentRowChanged(int)),
this, SLOT(slotCurrentRowChanged(int)));
}
CustomWidgetWidgetsWizardPage::~CustomWidgetWidgetsWizardPage()
@@ -61,15 +77,28 @@ bool CustomWidgetWidgetsWizardPage::isComplete() const
return m_complete;
}
void CustomWidgetWidgetsWizardPage::initializePage()
{
// Takes effect only if visible.
QTimer::singleShot(0, m_ui->classList, SLOT(startEditingNewClassItem()));
}
void CustomWidgetWidgetsWizardPage::slotCurrentRowChanged(int row)
{
const bool onDummyItem = row == m_tabStackLayout->count() - 1;
m_ui->deleteButton->setEnabled(!onDummyItem);
m_tabStackLayout->setCurrentIndex(row);
}
void CustomWidgetWidgetsWizardPage::on_classList_classAdded(const QString &name)
{
ClassDefinition *cdef = new ClassDefinition(m_ui->tabStackWidget);
ClassDefinition *cdef = new ClassDefinition;
cdef->setFileNamingParameters(m_fileNamingParameters);
const int index = m_uiClassDefs.count();
m_tabStack->insertWidget(index, cdef);
m_tabStack->setCurrentIndex(index);
m_tabStackLayout->insertWidget(index, cdef);
m_tabStackLayout->setCurrentIndex(index);
m_uiClassDefs.append(cdef);
cdef->on_libraryRadio_toggled();
cdef->enableButtons();
on_classList_classRenamed(index, name);
// First class or collection class, re-check.
slotCheckCompleteness();
@@ -77,7 +106,7 @@ void CustomWidgetWidgetsWizardPage::on_classList_classAdded(const QString &name)
void CustomWidgetWidgetsWizardPage::on_classList_classDeleted(int index)
{
delete m_tabStack->widget(index);
delete m_tabStackLayout->widget(index);
m_uiClassDefs.removeAt(index);
if (m_uiClassDefs.empty())
slotCheckCompleteness();
@@ -90,7 +119,7 @@ void CustomWidgetWidgetsWizardPage::on_classList_classRenamed(int index, const Q
QString CustomWidgetWidgetsWizardPage::classNameAt(int i) const
{
return m_ui->classList->item(i)->text();
return m_ui->classList->className(i);
}
QList<PluginOptions::WidgetOptions> CustomWidgetWidgetsWizardPage::widgetOptions() const