diff --git a/src/widgets/newprojectdialog.h b/src/widgets/newprojectdialog.h --- a/src/widgets/newprojectdialog.h +++ b/src/widgets/newprojectdialog.h @@ -50,24 +50,19 @@ void accept() Q_DECL_OVERRIDE; void setDataSourcesModel(QAbstractItemModel *model) Q_DECL_OVERRIDE; - void setPageType(PageType type) Q_DECL_OVERRIDE; QString name() const Q_DECL_OVERRIDE; - PageType pageType() const Q_DECL_OVERRIDE; Domain::DataSource::Ptr dataSource() const Q_DECL_OVERRIDE; private slots: void onNameTextChanged(const QString &text); - void onTypeIndexChanged(int index); private: - int indexOfType(NewProjectDialogInterface::PageType type); void applyDefaultSource(const QModelIndex &root); Ui::NewProjectDialog *ui; KDescendantsProxyModel *m_flattenProxy; QString m_name; - PageType m_pageType; Domain::DataSource::Ptr m_source; }; diff --git a/src/widgets/newprojectdialog.cpp b/src/widgets/newprojectdialog.cpp --- a/src/widgets/newprojectdialog.cpp +++ b/src/widgets/newprojectdialog.cpp @@ -56,19 +56,13 @@ NewProjectDialog::NewProjectDialog(QWidget *parent) : QDialog(parent), ui(new Ui::NewProjectDialog), - m_flattenProxy(new KDescendantsProxyModel(this)), - m_pageType(Project) + m_flattenProxy(new KDescendantsProxyModel(this)) { ui->setupUi(this); QObject::connect(ui->nameEdit, SIGNAL(textChanged(QString)), this, SLOT(onNameTextChanged(QString))); - QObject::connect(ui->typeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onTypeIndexChanged(int))); onNameTextChanged(m_name); - ui->typeCombo->addItem(tr("Project"), QVariant::fromValue(Project)); - ui->typeCombo->addItem(tr("Context"), QVariant::fromValue(Context)); - ui->typeCombo->addItem(tr("Tag"), QVariant::fromValue(Tag)); - auto taskSourceProxy = new TaskSourceProxy(this); taskSourceProxy->setSourceModel(m_flattenProxy); ui->sourceCombo->setModel(taskSourceProxy); @@ -92,7 +86,6 @@ m_source = ui->sourceCombo->itemData(ui->sourceCombo->currentIndex(), Presentation::QueryTreeModelBase::ObjectRole) .value(); - m_pageType = ui->typeCombo->itemData(ui->typeCombo->currentIndex()).value(); QDialog::accept(); } @@ -108,23 +101,11 @@ } } -void NewProjectDialog::setPageType(PageType type) -{ - int index = indexOfType(type); - Q_ASSERT(index != -1); - ui->typeCombo->setCurrentIndex(index); -} - QString NewProjectDialog::name() const { return m_name; } -NewProjectDialogInterface::PageType NewProjectDialog::pageType() const -{ - return m_pageType; -} - Domain::DataSource::Ptr NewProjectDialog::dataSource() const { return m_source; @@ -135,24 +116,3 @@ auto buttonOk = ui->buttonBox->button(QDialogButtonBox::Ok); buttonOk->setEnabled(!text.isEmpty()); } - -void NewProjectDialog::onTypeIndexChanged(int index) -{ - if (index == -1) - return; - - const PageType selectedType = ui->typeCombo->itemData(index).value(); - ui->sourceLabel->setVisible(selectedType == Project); - ui->sourceCombo->setVisible(selectedType == Project); -} - -int NewProjectDialog::indexOfType(PageType type) -{ - const int count = ui->typeCombo->count(); - for (int index = 0 ; index < count ; index++ ) { - const PageType pt = ui->typeCombo->itemData(index).value(); - if (pt == type) - return index; - } - return -1; -} diff --git a/src/widgets/newprojectdialog.ui b/src/widgets/newprojectdialog.ui --- a/src/widgets/newprojectdialog.ui +++ b/src/widgets/newprojectdialog.ui @@ -14,6 +14,9 @@ Add a project + + QLayout::SetFixedSize + @@ -34,23 +37,13 @@ - - - Type - - - - - - - Source - + diff --git a/src/widgets/newprojectdialoginterface.h b/src/widgets/newprojectdialoginterface.h --- a/src/widgets/newprojectdialoginterface.h +++ b/src/widgets/newprojectdialoginterface.h @@ -36,27 +36,17 @@ class NewProjectDialogInterface { public: - enum PageType { - Project = 0, - Context, - Tag - }; - typedef QSharedPointer Ptr; virtual ~NewProjectDialogInterface(); virtual int exec() = 0; virtual void setDataSourcesModel(QAbstractItemModel *model) = 0; - virtual void setPageType(PageType type) = 0; virtual QString name() const = 0; - virtual PageType pageType() const = 0; virtual Domain::DataSource::Ptr dataSource() const = 0; }; } -Q_DECLARE_METATYPE(Widgets::NewProjectDialogInterface::PageType) - #endif // WIDGETS_NEWPROJECTDIALOGINTERFACE_H diff --git a/tests/units/widgets/availablepagesviewtest.cpp b/tests/units/widgets/availablepagesviewtest.cpp --- a/tests/units/widgets/availablepagesviewtest.cpp +++ b/tests/units/widgets/availablepagesviewtest.cpp @@ -68,16 +68,6 @@ sourceModel = model; } - void setPageType(PageType type) Q_DECL_OVERRIDE - { - lastPageAdded = type; - } - - PageType pageType() const Q_DECL_OVERRIDE - { - return lastPageAdded; - } - QString name() const Q_DECL_OVERRIDE { return "name"; @@ -92,7 +82,6 @@ int execCount; QAbstractItemModel *sourceModel; Domain::DataSource::Ptr source; - PageType lastPageAdded; }; class AvailablePagesModelStub : public QObject diff --git a/tests/units/widgets/newprojectdialogtest.cpp b/tests/units/widgets/newprojectdialogtest.cpp --- a/tests/units/widgets/newprojectdialogtest.cpp +++ b/tests/units/widgets/newprojectdialogtest.cpp @@ -40,7 +40,7 @@ Q_OBJECT public: explicit UserInputSimulator(QObject *parent = Q_NULLPTR) - : QObject(parent), dialog(Q_NULLPTR), reject(false), sourceComboIndex(-1), typeComboIndex(-1) {} + : QObject(parent), dialog(Q_NULLPTR), reject(false), sourceComboIndex(-1) {} void exec() { @@ -62,11 +62,6 @@ sourceCombo->setCurrentIndex(sourceComboIndex); } - if (typeComboIndex >= 0) { - auto typeCombo = dialog->findChild("typeCombo"); - typeCombo->setCurrentIndex(typeComboIndex); - } - auto buttonBox = dialog->findChild("buttonBox"); if (reject) buttonBox->button(QDialogButtonBox::Cancel)->click(); @@ -79,7 +74,6 @@ bool reject; QString nameInput; int sourceComboIndex; - int typeComboIndex; }; class NewProjectDialogTest : public QObject @@ -132,34 +126,17 @@ } private slots: - int indexOfType(Widgets::NewProjectDialog *dialog, const Widgets::NewProjectDialogInterface::PageType type) - { - auto typeCombo = dialog->findChild("typeCombo"); - const int count = typeCombo->count(); - for (int index = 0 ; index < count ; index++ ) { - auto pt = typeCombo->itemData(index).value(); - if (pt == type) - return index; - } - return -1; - } - void shouldHaveDefaultState() { Widgets::NewProjectDialog dialog; QVERIFY(dialog.name().isEmpty()); - QCOMPARE(dialog.pageType(), Widgets::NewProjectDialogInterface::Project); QVERIFY(dialog.dataSource().isNull()); auto nameEdit = dialog.findChild("nameEdit"); QVERIFY(nameEdit); QVERIFY(nameEdit->isVisibleTo(&dialog)); - auto typeCombo = dialog.findChild("typeCombo"); - QVERIFY(typeCombo); - QVERIFY(typeCombo->isVisibleTo(&dialog)); - auto sourceCombo = dialog.findChild("sourceCombo"); QVERIFY(sourceCombo); QVERIFY(sourceCombo->isVisibleTo(&dialog)); @@ -177,18 +154,13 @@ Widgets::NewProjectDialog dialog; auto sourceModel = createSourceModel(); auto sourceCombo = dialog.findChild("sourceCombo"); - auto pageTypeCombo = dialog.findChild("typeCombo"); - auto pageType = Widgets::NewProjectDialogInterface::Project; // WHEN dialog.setDataSourcesModel(sourceModel); // THEN QCOMPARE(sourceCombo->currentIndex(), 2); QCOMPARE(sourceCombo->currentText(), QString("Root 2 / Task 2.1")); - - QVariant indexVariant = pageTypeCombo->itemData(pageTypeCombo->currentIndex()); - QCOMPARE(indexVariant.value(), pageType); } void shouldProvideUserInputWhenAccepted() @@ -251,7 +223,6 @@ UserInputSimulator userInput; userInput.dialog = &dialog; userInput.sourceComboIndex = 0; - userInput.typeComboIndex = 0; userInput.nameInput = QString(); userInput.reject = true; @@ -264,45 +235,6 @@ QCOMPARE(dialog.name(), QString()); QCOMPARE(dialog.dataSource(), Domain::DataSource::Ptr()); } - - void shouldHideSourceComboForNonProjectType_data() - { - QTest::addColumn("pageType"); - - QTest::newRow("typeComboWithContext") << Widgets::NewProjectDialogInterface::Context; - QTest::newRow("typeComboWithTag") << Widgets::NewProjectDialogInterface::Tag; - } - - void shouldHideSourceComboForNonProjectType() - { - // GIVEN - QFETCH(Widgets::NewProjectDialogInterface::PageType, pageType); - Widgets::NewProjectDialog dialog; - - int nonProjectIndex = indexOfType(&dialog, pageType); - Q_ASSERT(nonProjectIndex != -1); - - auto sourceModel = createSourceModel(); - dialog.setDataSourcesModel(sourceModel); - - UserInputSimulator userInput; - userInput.dialog = &dialog; - userInput.sourceComboIndex = 0; - userInput.typeComboIndex = nonProjectIndex; - userInput.nameInput = "name"; - userInput.reject = false; - - // WHEN - userInput.exec(); - - // THEN - auto sourceCombo = dialog.findChild("sourceCombo"); - auto sourceLabel = dialog.findChild("sourceLabel"); - - QVERIFY(sourceCombo->isHidden()); - QVERIFY(sourceLabel->isHidden()); - QCOMPARE(dialog.name(), userInput.nameInput); - } }; QTEST_MAIN(NewProjectDialogTest)