diff --git a/src/akonadi/akonadidatasourcequeries.h b/src/akonadi/akonadidatasourcequeries.h --- a/src/akonadi/akonadidatasourcequeries.h +++ b/src/akonadi/akonadidatasourcequeries.h @@ -51,8 +51,6 @@ void changeDefaultSource(Domain::DataSource::Ptr source) Q_DECL_OVERRIDE; public: - DataSourceResult::Ptr findTasks() const Q_DECL_OVERRIDE; - DataSourceResult::Ptr findNotes() const Q_DECL_OVERRIDE; DataSourceResult::Ptr findTopLevel() const Q_DECL_OVERRIDE; DataSourceResult::Ptr findChildren(Domain::DataSource::Ptr source) const Q_DECL_OVERRIDE; @@ -70,8 +68,6 @@ LiveQueryHelpers::Ptr m_helpers; LiveQueryIntegrator::Ptr m_integrator; - mutable DataSourceQueryOutput::Ptr m_findTasks; - mutable DataSourceQueryOutput::Ptr m_findNotes; mutable DataSourceQueryOutput::Ptr m_findTopLevel; mutable QHash m_findChildren; QString m_searchTerm; diff --git a/src/akonadi/akonadidatasourcequeries.cpp b/src/akonadi/akonadidatasourcequeries.cpp --- a/src/akonadi/akonadidatasourcequeries.cpp +++ b/src/akonadi/akonadidatasourcequeries.cpp @@ -64,26 +64,6 @@ } } -DataSourceQueries::DataSourceResult::Ptr DataSourceQueries::findTasks() const -{ - auto fetch = m_helpers->fetchAllCollections(StorageInterface::Tasks); - auto predicate = [this] (const Akonadi::Collection &collection) { - return m_serializer->isTaskCollection(collection); - }; - m_integrator->bind(m_findTasks, fetch, predicate, SerializerInterface::FullPath); - return m_findTasks->result(); -} - -DataSourceQueries::DataSourceResult::Ptr DataSourceQueries::findNotes() const -{ - auto fetch = m_helpers->fetchAllCollections(StorageInterface::Notes); - auto predicate = [this] (const Akonadi::Collection &collection) { - return m_serializer->isNoteCollection(collection); - }; - m_integrator->bind(m_findNotes, fetch, predicate, SerializerInterface::FullPath); - return m_findNotes->result(); -} - DataSourceQueries::DataSourceResult::Ptr DataSourceQueries::findTopLevel() const { auto fetch = m_helpers->fetchCollections(Collection::root(), m_contentTypes); diff --git a/src/domain/datasourcequeries.h b/src/domain/datasourcequeries.h --- a/src/domain/datasourcequeries.h +++ b/src/domain/datasourcequeries.h @@ -65,9 +65,6 @@ virtual void changeDefaultSource(DataSource::Ptr source) = 0; public: - virtual QueryResult::Ptr findTasks() const = 0; - virtual QueryResult::Ptr findNotes() const = 0; - virtual QueryResult::Ptr findTopLevel() const = 0; virtual QueryResult::Ptr findChildren(DataSource::Ptr source) const = 0; diff --git a/src/presentation/applicationmodel.h b/src/presentation/applicationmodel.h --- a/src/presentation/applicationmodel.h +++ b/src/presentation/applicationmodel.h @@ -49,8 +49,6 @@ class ApplicationModel : public QObject { Q_OBJECT - Q_PROPERTY(QAbstractItemModel* dataSourcesModel READ dataSourcesModel) - Q_PROPERTY(Domain::DataSource::Ptr defaultDataSource READ defaultDataSource WRITE setDefaultDataSource) Q_PROPERTY(QObject* availableSources READ availableSources) Q_PROPERTY(QObject* availablePages READ availablePages) Q_PROPERTY(QObject* currentPage READ currentPage WRITE setCurrentPage NOTIFY currentPageChanged) @@ -69,9 +67,6 @@ const Domain::TagRepository::Ptr &tagRepository, QObject *parent = Q_NULLPTR); - QAbstractItemModel *dataSourcesModel(); - Domain::DataSource::Ptr defaultDataSource(); - QObject *availableSources(); QObject *availablePages(); QObject *currentPage(); @@ -81,28 +76,20 @@ public slots: void setCurrentPage(QObject *page); - virtual void setDefaultDataSource(const Domain::DataSource::Ptr &source) = 0; void setErrorHandler(ErrorHandler *errorHandler); signals: void currentPageChanged(QObject *page); private: - virtual Domain::QueryResult::Ptr createDataSourceQueryResult() = 0; - virtual bool isDefaultSource(const Domain::DataSource::Ptr &source) = 0; virtual AvailablePagesModelInterface *createAvailablePagesModel() = 0; - Domain::QueryResult::Ptr dataSources(); - QObject *m_availableSources; QObject *m_availablePages; QObject *m_currentPage; QObject *m_editor; protected: - Domain::QueryResult::Ptr m_dataSources; - QAbstractItemModel *m_dataSourcesModel; - Domain::ProjectQueries::Ptr m_projectQueries; Domain::ProjectRepository::Ptr m_projectRepository; diff --git a/src/presentation/applicationmodel.cpp b/src/presentation/applicationmodel.cpp --- a/src/presentation/applicationmodel.cpp +++ b/src/presentation/applicationmodel.cpp @@ -61,7 +61,6 @@ m_availablePages(Q_NULLPTR), m_currentPage(Q_NULLPTR), m_editor(Q_NULLPTR), - m_dataSourcesModel(Q_NULLPTR), m_projectQueries(projectQueries), m_projectRepository(projectRepository), m_contextQueries(contextQueries), @@ -78,42 +77,6 @@ MetaTypes::registerAll(); } -QAbstractItemModel *ApplicationModel::dataSourcesModel() -{ - if (!m_dataSourcesModel) { - m_dataSourcesModel = new DataSourceListModel([this] { return dataSources(); }, this); - } - - return m_dataSourcesModel; -} - -Domain::QueryResult::Ptr ApplicationModel::dataSources() -{ - if (!m_dataSources) { - m_dataSources = createDataSourceQueryResult(); - } - - return m_dataSources; -} - -Domain::DataSource::Ptr ApplicationModel::defaultDataSource() -{ - QList sources = dataSources()->data(); - - if (sources.isEmpty()) - return Domain::DataSource::Ptr(); - - auto source = std::find_if(sources.begin(), sources.end(), - [this] (const Domain::DataSource::Ptr &source) { - return isDefaultSource(source); - }); - - if (source != sources.end()) - return *source; - else - return sources.first(); -} - QObject *ApplicationModel::availableSources() { if (!m_availableSources) { diff --git a/src/presentation/noteapplicationmodel.h b/src/presentation/noteapplicationmodel.h --- a/src/presentation/noteapplicationmodel.h +++ b/src/presentation/noteapplicationmodel.h @@ -49,12 +49,7 @@ const Domain::TagRepository::Ptr &tagRepository, QObject *parent = Q_NULLPTR); -public slots: - void setDefaultDataSource(const Domain::DataSource::Ptr &source) Q_DECL_OVERRIDE; - private: - Domain::QueryResult::Ptr createDataSourceQueryResult() Q_DECL_OVERRIDE; - bool isDefaultSource(const Domain::DataSource::Ptr &source) Q_DECL_OVERRIDE; AvailablePagesModelInterface *createAvailablePagesModel() Q_DECL_OVERRIDE; Domain::NoteQueries::Ptr m_noteQueries; diff --git a/src/presentation/noteapplicationmodel.cpp b/src/presentation/noteapplicationmodel.cpp --- a/src/presentation/noteapplicationmodel.cpp +++ b/src/presentation/noteapplicationmodel.cpp @@ -57,21 +57,6 @@ { } -void NoteApplicationModel::setDefaultDataSource(const Domain::DataSource::Ptr &source) -{ - m_sourceQueries->setDefaultSource(source); -} - -Domain::QueryResult::Ptr NoteApplicationModel::createDataSourceQueryResult() -{ - return m_sourceQueries->findNotes(); -} - -bool NoteApplicationModel::isDefaultSource(const Domain::DataSource::Ptr &source) -{ - return m_sourceQueries->isDefaultSource(source); -} - AvailablePagesModelInterface *NoteApplicationModel::createAvailablePagesModel() { return new AvailableNotePagesModel(m_noteQueries, diff --git a/src/presentation/taskapplicationmodel.h b/src/presentation/taskapplicationmodel.h --- a/src/presentation/taskapplicationmodel.h +++ b/src/presentation/taskapplicationmodel.h @@ -46,12 +46,7 @@ const Domain::TagRepository::Ptr &tagRepository, QObject *parent = Q_NULLPTR); -public slots: - void setDefaultDataSource(const Domain::DataSource::Ptr &source) Q_DECL_OVERRIDE; - private: - Domain::QueryResult::Ptr createDataSourceQueryResult() Q_DECL_OVERRIDE; - bool isDefaultSource(const Domain::DataSource::Ptr &source) Q_DECL_OVERRIDE; AvailablePagesModelInterface *createAvailablePagesModel() Q_DECL_OVERRIDE; }; diff --git a/src/presentation/taskapplicationmodel.cpp b/src/presentation/taskapplicationmodel.cpp --- a/src/presentation/taskapplicationmodel.cpp +++ b/src/presentation/taskapplicationmodel.cpp @@ -55,21 +55,6 @@ { } -void TaskApplicationModel::setDefaultDataSource(const Domain::DataSource::Ptr &source) -{ - m_sourceQueries->setDefaultSource(source); -} - -Domain::QueryResult::Ptr TaskApplicationModel::createDataSourceQueryResult() -{ - return m_sourceQueries->findTasks(); -} - -bool TaskApplicationModel::isDefaultSource(const Domain::DataSource::Ptr &source) -{ - return m_sourceQueries->isDefaultSource(source); -} - AvailablePagesModelInterface *TaskApplicationModel::createAvailablePagesModel() { return new AvailableTaskPagesModel(m_projectQueries, diff --git a/src/renku/app/main.cpp b/src/renku/app/main.cpp --- a/src/renku/app/main.cpp +++ b/src/renku/app/main.cpp @@ -37,7 +37,6 @@ #include "widgets/applicationcomponents.h" #include "widgets/availablepagesview.h" #include "widgets/availablesourcesview.h" -#include "widgets/datasourcecombobox.h" #include "widgets/editorview.h" #include "widgets/pageview.h" @@ -62,13 +61,7 @@ components->setModel(Utils::DependencyManager::globalInstance().create()); auto layout = new QVBoxLayout; - - auto hbox = new QHBoxLayout; - hbox->addWidget(components->defaultSourceCombo()); - - layout->addLayout(hbox); layout->addWidget(components->pageView()); - widget->setLayout(layout); auto sourcesDock = new QDockWidget(QObject::tr("Sources")); @@ -83,27 +76,11 @@ editorDock->setObjectName("editorDock"); editorDock->setWidget(components->editorView()); - auto configureMenu = new QMenu(widget); - foreach (QAction *action, components->configureActions()) { - configureMenu->addAction(action); - } - - auto configureButton = new QToolButton(widget); - configureButton->setIcon(QIcon::fromTheme("configure")); - configureButton->setText(QObject::tr("Settings")); - configureButton->setToolTip(configureButton ->text()); - configureButton->setPopupMode(QToolButton::InstantPopup); - configureButton->setMenu(configureMenu); - auto window = new KMainWindow; window->resize(1024, 600); window->setAutoSaveSettings("MainWindow"); window->setCentralWidget(widget); - QToolBar *mainToolBar = window->addToolBar(QObject::tr("Main")); - mainToolBar->setObjectName("mainToolBar"); - mainToolBar->addWidget(configureButton); - window->addDockWidget(Qt::RightDockWidgetArea, editorDock); window->addDockWidget(Qt::LeftDockWidgetArea, pagesDock); window->addDockWidget(Qt::LeftDockWidgetArea, sourcesDock); diff --git a/src/renku/kontact/part.cpp b/src/renku/kontact/part.cpp --- a/src/renku/kontact/part.cpp +++ b/src/renku/kontact/part.cpp @@ -39,7 +39,6 @@ #include "widgets/applicationcomponents.h" #include "widgets/availablepagesview.h" #include "widgets/availablesourcesview.h" -#include "widgets/datasourcecombobox.h" #include "widgets/editorview.h" #include "widgets/pageview.h" @@ -69,10 +68,6 @@ splitter->addWidget(components->editorView()); setWidget(splitter); - foreach (QAction *action, components->configureActions()) { - actionCollection()->addAction(action->objectName(), action); - } - setXMLFile(KStandardDirs::locate("data", "renku/renku_part.rc")); } diff --git a/src/renku/kontact/renku_part.rc b/src/renku/kontact/renku_part.rc --- a/src/renku/kontact/renku_part.rc +++ b/src/renku/kontact/renku_part.rc @@ -1,11 +1,5 @@ - - - Configure Renku - - - diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -2,7 +2,6 @@ applicationcomponents.cpp availablepagesview.cpp availablesourcesview.cpp - datasourcecombobox.cpp datasourcedelegate.cpp editorview.cpp filterwidget.cpp diff --git a/src/widgets/applicationcomponents.h b/src/widgets/applicationcomponents.h --- a/src/widgets/applicationcomponents.h +++ b/src/widgets/applicationcomponents.h @@ -38,7 +38,6 @@ class AvailablePagesView; class AvailableSourcesView; -class DataSourceComboBox; class EditorView; class PageView; @@ -55,10 +54,6 @@ PageView *pageView() const; EditorView *editorView() const; - QList configureActions() const; - - DataSourceComboBox *defaultSourceCombo() const; - public slots: void setModel(const QObjectPtr &model); @@ -74,9 +69,6 @@ AvailablePagesView *m_availablePagesView; PageView *m_pageView; EditorView *m_editorView; - - QList m_configureActions; - DataSourceComboBox *m_defaultSourceCombo; }; } diff --git a/src/widgets/applicationcomponents.cpp b/src/widgets/applicationcomponents.cpp --- a/src/widgets/applicationcomponents.cpp +++ b/src/widgets/applicationcomponents.cpp @@ -32,7 +32,6 @@ #include "availablepagesview.h" #include "availablesourcesview.h" -#include "datasourcecombobox.h" #include "editorview.h" #include "pageview.h" @@ -46,8 +45,7 @@ m_availableSourcesView(Q_NULLPTR), m_availablePagesView(Q_NULLPTR), m_pageView(Q_NULLPTR), - m_editorView(Q_NULLPTR), - m_defaultSourceCombo(Q_NULLPTR) + m_editorView(Q_NULLPTR) { } @@ -127,48 +125,6 @@ return m_editorView; } -QList ApplicationComponents::configureActions() const -{ - if (m_configureActions.isEmpty()) { - QList actions; - - auto widget = new QWidget; - widget->setLayout(new QHBoxLayout); - widget->layout()->addWidget(new QLabel(tr("Default source"))); - widget->layout()->addWidget(defaultSourceCombo()); - - auto comboAction = new QWidgetAction(m_parent); - comboAction->setObjectName("settings_default_source"); - comboAction->setDefaultWidget(widget); - actions << comboAction; - - ApplicationComponents *self = const_cast(this); - self->m_configureActions = actions; - } - - return m_configureActions; -} - -DataSourceComboBox *ApplicationComponents::defaultSourceCombo() const -{ - if (!m_defaultSourceCombo) { - auto combo = new DataSourceComboBox(m_parent); - combo->setObjectName("defaultSourceCombo"); - combo->setFixedWidth(300); - if (m_model.data()) { - combo->setModel(m_model->property("dataSourcesModel").value()); - combo->setDefaultSourceProperty(m_model.data(), "defaultDataSource"); - connect(combo, SIGNAL(sourceActivated(Domain::DataSource::Ptr)), - m_model.data(), SLOT(setDefaultDataSource(Domain::DataSource::Ptr))); - } - - ApplicationComponents *self = const_cast(this); - self->m_defaultSourceCombo = combo; - } - - return m_defaultSourceCombo; -} - void ApplicationComponents::setModel(const QObjectPtr &model) { if (m_model == model) @@ -193,13 +149,6 @@ if (m_editorView) m_editorView->setModel(m_model->property("editor").value()); - - if (m_defaultSourceCombo) { - m_defaultSourceCombo->setModel(m_model->property("dataSourcesModel").value()); - m_defaultSourceCombo->setDefaultSourceProperty(m_model.data(), "defaultDataSource"); - connect(m_defaultSourceCombo, SIGNAL(sourceActivated(Domain::DataSource::Ptr)), - m_model.data(), SLOT(setDefaultDataSource(Domain::DataSource::Ptr))); - } } void ApplicationComponents::onCurrentPageChanged(QObject *page) diff --git a/src/widgets/datasourcecombobox.h b/src/widgets/datasourcecombobox.h deleted file mode 100644 --- a/src/widgets/datasourcecombobox.h +++ /dev/null @@ -1,70 +0,0 @@ -/* This file is part of Zanshin - - Copyright 2014 Kevin Ottens - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License or (at your option) version 3 or any later version - accepted by the membership of KDE e.V. (or its successor approved - by the membership of KDE e.V.), which shall act as a proxy - defined in Section 14 of version 3 of the license. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - USA. -*/ - - -#ifndef WIDGETS_DATASOURCECOMBOBOX_H -#define WIDGETS_DATASOURCECOMBOBOX_H - -#include - -#include "domain/datasource.h" - -class QAbstractItemModel; -class QComboBox; - -namespace Widgets { - -class DataSourceComboBox : public QWidget -{ - Q_OBJECT -public: - explicit DataSourceComboBox(QWidget *parent = Q_NULLPTR); - - int count() const; - int currentIndex() const; - - Domain::DataSource::Ptr itemSource(int index) const; - - QAbstractItemModel *model() const; - void setModel(QAbstractItemModel *model); - - QObject *defaultSourceObject() const; - QByteArray defaultSourceProperty() const; - void setDefaultSourceProperty(QObject *object, const char *property); - -signals: - void sourceActivated(const Domain::DataSource::Ptr &source); - -private slots: - void onRefreshDefaultSource(); - void onActivated(int index); - -private: - QComboBox *m_combo; - QObject *m_object; - QByteArray m_property; -}; - -} - -#endif // WIDGETS_DATASOURCECOMBOBOX_H diff --git a/src/widgets/datasourcecombobox.cpp b/src/widgets/datasourcecombobox.cpp deleted file mode 100644 --- a/src/widgets/datasourcecombobox.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* This file is part of Zanshin - - Copyright 2014 Kevin Ottens - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License or (at your option) version 3 or any later version - accepted by the membership of KDE e.V. (or its successor approved - by the membership of KDE e.V.), which shall act as a proxy - defined in Section 14 of version 3 of the license. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - USA. -*/ - - -#include "datasourcecombobox.h" - -#include -#include - -#include "presentation/querytreemodelbase.h" - -using namespace Widgets; - -DataSourceComboBox::DataSourceComboBox(QWidget *parent) - : QWidget(parent), - m_combo(new QComboBox(this)), - m_object(Q_NULLPTR) -{ - setFocusProxy(m_combo); - - auto layout = new QVBoxLayout; - layout->setContentsMargins(0, 0, 0, 0); - layout->addWidget(m_combo); - setLayout(layout); - - connect(m_combo, SIGNAL(activated(int)), this, SLOT(onActivated(int))); -} - -int DataSourceComboBox::count() const -{ - return m_combo->count(); -} - -int DataSourceComboBox::currentIndex() const -{ - return m_combo->currentIndex(); -} - -Domain::DataSource::Ptr DataSourceComboBox::itemSource(int index) const -{ - if (!m_combo->model()) - return Domain::DataSource::Ptr(); - - const QModelIndex modelIndex = m_combo->model()->index(index, 0); - if (!modelIndex.isValid()) - return Domain::DataSource::Ptr(); - - const QVariant data = modelIndex.data(Presentation::QueryTreeModelBase::ObjectRole); - const auto source = data.value(); - return source; -} - -QAbstractItemModel *DataSourceComboBox::model() const -{ - return m_combo->model(); -} - -void DataSourceComboBox::setModel(QAbstractItemModel *model) -{ - if (model == m_combo->model()) - return; - - disconnect(m_combo->model(), Q_NULLPTR, this, Q_NULLPTR); - - m_combo->setModel(model); - - connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(onRefreshDefaultSource())); - connect(model, SIGNAL(layoutChanged()), this, SLOT(onRefreshDefaultSource())); - connect(model, SIGNAL(modelReset()), this, SLOT(onRefreshDefaultSource())); - connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(onRefreshDefaultSource())); - connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(onRefreshDefaultSource())); - - onRefreshDefaultSource(); -} - -QObject *DataSourceComboBox::defaultSourceObject() const -{ - return m_object; -} - -QByteArray DataSourceComboBox::defaultSourceProperty() const -{ - return m_property; -} - -void DataSourceComboBox::setDefaultSourceProperty(QObject *object, const char *property) -{ - m_object = object; - m_property = property; - onRefreshDefaultSource(); -} - -void DataSourceComboBox::onRefreshDefaultSource() -{ - if (!m_object) - return; - - const QVariant data = m_object->property(m_property); - const auto defaultSource = data.value(); - - if (!defaultSource) - return; - - for (int index = 0; index < count(); index++) { - if (itemSource(index) == defaultSource) { - m_combo->setCurrentIndex(index); - return; - } - } -} - -void DataSourceComboBox::onActivated(int index) -{ - Domain::DataSource::Ptr source = itemSource(index); - - if (source) - emit sourceActivated(source); -} - diff --git a/src/zanshin/app/main.cpp b/src/zanshin/app/main.cpp --- a/src/zanshin/app/main.cpp +++ b/src/zanshin/app/main.cpp @@ -37,7 +37,6 @@ #include "widgets/applicationcomponents.h" #include "widgets/availablepagesview.h" #include "widgets/availablesourcesview.h" -#include "widgets/datasourcecombobox.h" #include "widgets/editorview.h" #include "widgets/pageview.h" @@ -72,13 +71,7 @@ components->setModel(Utils::DependencyManager::globalInstance().create()); auto layout = new QVBoxLayout; - - auto hbox = new QHBoxLayout; - hbox->addWidget(components->defaultSourceCombo()); - - layout->addLayout(hbox); layout->addWidget(components->pageView()); - widget->setLayout(layout); auto sourcesDock = new QDockWidget(QObject::tr("Sources")); @@ -93,27 +86,11 @@ editorDock->setObjectName("editorDock"); editorDock->setWidget(components->editorView()); - auto configureMenu = new QMenu(widget); - foreach (QAction *action, components->configureActions()) { - configureMenu->addAction(action); - } - - auto configureButton = new QToolButton(widget); - configureButton->setIcon(QIcon::fromTheme("configure")); - configureButton->setText(QObject::tr("Settings")); - configureButton->setToolTip(configureButton ->text()); - configureButton->setPopupMode(QToolButton::InstantPopup); - configureButton->setMenu(configureMenu); - auto window = new KMainWindow; window->resize(1024, 600); window->setAutoSaveSettings("MainWindow"); window->setCentralWidget(widget); - QToolBar *mainToolBar = window->addToolBar(QObject::tr("Main")); - mainToolBar->setObjectName("mainToolBar"); - mainToolBar->addWidget(configureButton); - window->addDockWidget(Qt::RightDockWidgetArea, editorDock); window->addDockWidget(Qt::LeftDockWidgetArea, pagesDock); window->addDockWidget(Qt::LeftDockWidgetArea, sourcesDock); diff --git a/src/zanshin/kontact/part.cpp b/src/zanshin/kontact/part.cpp --- a/src/zanshin/kontact/part.cpp +++ b/src/zanshin/kontact/part.cpp @@ -39,7 +39,6 @@ #include "widgets/applicationcomponents.h" #include "widgets/availablepagesview.h" #include "widgets/availablesourcesview.h" -#include "widgets/datasourcecombobox.h" #include "widgets/editorview.h" #include "widgets/pageview.h" @@ -69,10 +68,6 @@ splitter->addWidget(components->editorView()); setWidget(splitter); - foreach (QAction *action, components->configureActions()) { - actionCollection()->addAction(action->objectName(), action); - } - setXMLFile(KStandardDirs::locate("data", "zanshin/zanshin-next_part.rc")); } diff --git a/src/zanshin/kontact/zanshin-next_part.rc b/src/zanshin/kontact/zanshin-next_part.rc --- a/src/zanshin/kontact/zanshin-next_part.rc +++ b/src/zanshin/kontact/zanshin-next_part.rc @@ -1,11 +1,5 @@ - - - Configure Zanshin - - - diff --git a/tests/units/akonadi/akonadidatasourcequeriestest.cpp b/tests/units/akonadi/akonadidatasourcequeriestest.cpp --- a/tests/units/akonadi/akonadidatasourcequeriestest.cpp +++ b/tests/units/akonadi/akonadidatasourcequeriestest.cpp @@ -54,23 +54,6 @@ qRegisterMetaType(); } -private: - void generateDataTable() - { - QTest::addColumn("contentType"); - QTest::addColumn("queryFunction"); - - { - QueryFunction query = Utils::mem_fn(&Domain::DataSourceQueries::findNotes); - QTest::newRow("notes") << Akonadi::StorageInterface::Notes << query; - } - - { - QueryFunction query = Utils::mem_fn(&Domain::DataSourceQueries::findTasks); - QTest::newRow("tasks") << Akonadi::StorageInterface::Tasks << query; - } - } - private slots: void shouldCheckIfASourceIsDefaultFromSettings_data() { @@ -174,283 +157,6 @@ QCOMPARE(spy.count(), 1); } - void shouldListDataSources_data() - { - generateDataTable(); - } - - void shouldListDataSources() - { - // GIVEN - AkonadiFakeData data; - QFETCH(Akonadi::StorageInterface::FetchContentType, contentType); - QFETCH(QueryFunction, queryFunction); - - // Six top level collections, three with tasks, 3 with notes - data.createCollection(GenCollection().withId(42).withName("42Task").withRootAsParent().withTaskContent()); - data.createCollection(GenCollection().withId(43).withName("43Task").withRootAsParent().withTaskContent()); - data.createCollection(GenCollection().withId(44).withName("44Task").withRootAsParent().withTaskContent()); - data.createCollection(GenCollection().withId(45).withName("45Note").withRootAsParent().withNoteContent()); - data.createCollection(GenCollection().withId(46).withName("46Note").withRootAsParent().withNoteContent()); - data.createCollection(GenCollection().withId(47).withName("47Note").withRootAsParent().withNoteContent()); - - // WHEN - QScopedPointer queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes, - Akonadi::StorageInterface::Ptr(data.createStorage()), - Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer), - Akonadi::MonitorInterface::Ptr(data.createMonitor()))); - - Domain::QueryResult::Ptr result = queryFunction(queries.data()); - result->data(); - result = queryFunction(queries.data()); // Should not cause any problem or wrong data - - // THEN - QVERIFY(result->data().isEmpty()); - TestHelpers::waitForEmptyJobQueue(); - - QCOMPARE(result->data().size(), 3); - - if (contentType == Akonadi::StorageInterface::Tasks) { - QCOMPARE(result->data().at(0)->name(), QString("42Task")); - QCOMPARE(result->data().at(1)->name(), QString("43Task")); - QCOMPARE(result->data().at(2)->name(), QString("44Task")); - } else { - QCOMPARE(result->data().at(0)->name(), QString("45Note")); - QCOMPARE(result->data().at(1)->name(), QString("46Note")); - QCOMPARE(result->data().at(2)->name(), QString("47Note")); - } - } - - void shouldListDataSourcesOnlyOnce_data() - { - generateDataTable(); - } - - void shouldListDataSourcesOnlyOnce() - { - // GIVEN - AkonadiFakeData data; - QFETCH(Akonadi::StorageInterface::FetchContentType, contentType); - QFETCH(QueryFunction, queryFunction); - - // Two top level collections, one with tasks, one with notes - data.createCollection(GenCollection().withId(42).withName("42Task").withRootAsParent().withTaskContent()); - data.createCollection(GenCollection().withId(43).withName("43Note").withRootAsParent().withNoteContent()); - - // WHEN - QScopedPointer queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes, - Akonadi::StorageInterface::Ptr(data.createStorage()), - Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer), - Akonadi::MonitorInterface::Ptr(data.createMonitor()))); - - Domain::QueryResult::Ptr result1 = queryFunction(queries.data()); - QVERIFY(result1->data().isEmpty()); - TestHelpers::waitForEmptyJobQueue(); - QCOMPARE(result1->data().size(), 1); - - Domain::QueryResult::Ptr result2 = queryFunction(queries.data()); - - // THEN - QCOMPARE(result1->data().size(), 1); - QCOMPARE(result2->data().size(), 1); - TestHelpers::waitForEmptyJobQueue(); - - QCOMPARE(result1->data().size(), 1); - QCOMPARE(result2->data().size(), 1); - if (contentType == Akonadi::StorageInterface::Tasks) { - QCOMPARE(result1->data().at(0)->name(), QString("42Task")); - } else { - QCOMPARE(result2->data().at(0)->name(), QString("43Note")); - } - } - - void shouldIgnoreCollectionsWhichAreNotDataSources_data() - { - generateDataTable(); - } - - void shouldIgnoreCollectionsWhichAreNotDataSources() - { - // GIVEN - AkonadiFakeData data; - QFETCH(Akonadi::StorageInterface::FetchContentType, contentType); - QFETCH(QueryFunction, queryFunction); - - // Two top level collections with tasks, one not being a data source - data.createCollection(GenCollection().withId(42).withName("42Task").withRootAsParent().withTaskContent()); - data.createCollection(GenCollection().withId(-1).withName("43Task").withTaskContent()); // invalid data source - // One child collection - data.createCollection(GenCollection().withId(44).withName("44Task").withParent(42).withTaskContent()); - - // Two top level collections with notes, one not being a data source - data.createCollection(GenCollection().withId(45).withName("45Note").withRootAsParent().withNoteContent()); - data.createCollection(GenCollection().withId(-2).withName("46Note").withNoteContent()); // invalid data source - // One child collection - data.createCollection(GenCollection().withId(47).withName("47Note").withParent(45).withNoteContent()); - - // WHEN - QScopedPointer queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes, - Akonadi::StorageInterface::Ptr(data.createStorage()), - Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer), - Akonadi::MonitorInterface::Ptr(data.createMonitor()))); - - Domain::QueryResult::Ptr result = queryFunction(queries.data()); - - // THEN - QVERIFY(result->data().isEmpty()); - TestHelpers::waitForEmptyJobQueue(); - - if (contentType == Akonadi::StorageInterface::Tasks) { - QCOMPARE(result->data().size(), 2); - QCOMPARE(result->data().at(0)->name(), QString("42Task")); - QCOMPARE(result->data().at(1)->name(), QString("42Task/44Task")); // name is: parentName/childName - } else { - QCOMPARE(result->data().size(), 2); - QCOMPARE(result->data().at(0)->name(), QString("45Note")); - QCOMPARE(result->data().at(1)->name(), QString("45Note/47Note")); // name is: parentName/childName - } - } - - void shouldReactToCollectionAddsForCompatibleDataSourcesOnly_data() - { - generateDataTable(); - } - - void shouldReactToCollectionAddsForCompatibleDataSourcesOnly() - { - // GIVEN - AkonadiFakeData data; - QFETCH(Akonadi::StorageInterface::FetchContentType, contentType); - QFETCH(QueryFunction, queryFunction); - - QScopedPointer queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes, - Akonadi::StorageInterface::Ptr(data.createStorage()), - Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer), - Akonadi::MonitorInterface::Ptr(data.createMonitor()))) ; - - Domain::QueryResult::Ptr result = queryFunction(queries.data()); - TestHelpers::waitForEmptyJobQueue(); - QVERIFY(result->data().isEmpty()); - - // WHEN - data.createCollection(GenCollection().withId(42).withName("42Task").withRootAsParent().withTaskContent()); - data.createCollection(GenCollection().withId(43).withName("43Note").withRootAsParent().withNoteContent()); - - // THEN - QCOMPARE(result->data().size(), 1); - const QString expected = contentType == Akonadi::StorageInterface::Tasks ? "42Task" : "43Note"; - QCOMPARE(result->data().first()->name(), expected); - } - - void shouldReactToCollectionRemovesForDataSources_data() - { - generateDataTable(); - } - - void shouldReactToCollectionRemovesForDataSources() - { - // GIVEN - AkonadiFakeData data; - QFETCH(Akonadi::StorageInterface::FetchContentType, contentType); - QFETCH(QueryFunction, queryFunction); - - // Four top level collections, two with notes, two with tasks - data.createCollection(GenCollection().withId(42).withName("42Task").withRootAsParent().withTaskContent()); - data.createCollection(GenCollection().withId(43).withName("43Task").withRootAsParent().withTaskContent()); - data.createCollection(GenCollection().withId(45).withName("45Note").withRootAsParent().withNoteContent()); - data.createCollection(GenCollection().withId(46).withName("46Note").withRootAsParent().withNoteContent()); - - // One child collection with tasks - data.createCollection(GenCollection().withId(44).withName("44Task").withParent(43).withTaskContent()); - - // One child collection with notes - data.createCollection(GenCollection().withId(47).withName("47Note").withParent(46).withNoteContent()); - - QScopedPointer queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes, - Akonadi::StorageInterface::Ptr(data.createStorage()), - Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer), - Akonadi::MonitorInterface::Ptr(data.createMonitor()))); - - Domain::QueryResult::Ptr result = queryFunction(queries.data()); - TestHelpers::waitForEmptyJobQueue(); - QCOMPARE(result->data().size(), 3); - - // WHEN - data.removeCollection(Akonadi::Collection(44)); - data.removeCollection(Akonadi::Collection(47)); - TestHelpers::waitForEmptyJobQueue(); - - // THEN - QCOMPARE(result->data().size(), 2); - if (contentType == Akonadi::StorageInterface::Tasks) { - QCOMPARE(result->data().at(0)->name(), QString("42Task")); - QCOMPARE(result->data().at(1)->name(), QString("43Task")); - } else { - QCOMPARE(result->data().at(0)->name(), QString("45Note")); - QCOMPARE(result->data().at(1)->name(), QString("46Note")); - } - } - - void shouldReactToCollectionChangesForDataSources_data() - { - generateDataTable(); - } - - void shouldReactToCollectionChangesForDataSources() - { - // GIVEN - AkonadiFakeData data; - QFETCH(Akonadi::StorageInterface::FetchContentType, contentType); - QFETCH(QueryFunction, queryFunction); - - // Four top level collections, two tasks, two notes), - data.createCollection(GenCollection().withId(42).withName("42Task").withRootAsParent().withTaskContent()); - data.createCollection(GenCollection().withId(43).withName("43Task").withRootAsParent().withTaskContent()); - data.createCollection(GenCollection().withId(45).withName("45Note").withRootAsParent().withNoteContent()); - data.createCollection(GenCollection().withId(46).withName("46Note").withRootAsParent().withNoteContent()); - - // One child collection with tasks - data.createCollection(GenCollection().withId(44).withName("44Task").withParent(43).withTaskContent()); - - // One child collcetion with notes - data.createCollection(GenCollection().withId(47).withName("47Note").withParent(46).withNoteContent()); - - QScopedPointer queries(new Akonadi::DataSourceQueries(Akonadi::StorageInterface::Tasks | Akonadi::StorageInterface::Notes, - Akonadi::StorageInterface::Ptr(data.createStorage()), - Akonadi::SerializerInterface::Ptr(new Akonadi::Serializer), - Akonadi::MonitorInterface::Ptr(data.createMonitor()))); - - Domain::QueryResult::Ptr result = queryFunction(queries.data()); - // Even though the pointer didn't change it's convenient to user if we call - // the replace handlers - bool replaceHandlerCalled = false; - result->addPostReplaceHandler([&replaceHandlerCalled](const Domain::DataSource::Ptr &, int) { - replaceHandlerCalled = true; - }); - TestHelpers::waitForEmptyJobQueue(); - QCOMPARE(result->data().size(), 3); - - // WHEN - data.modifyCollection(GenCollection(data.collection(42)).withName("42TaskBis")); - data.modifyCollection(GenCollection(data.collection(45)).withName("45NoteBis")); - TestHelpers::waitForEmptyJobQueue(); - - // THEN - QCOMPARE(result->data().size(), 3); - - if (contentType == Akonadi::StorageInterface::Tasks) { - QCOMPARE(result->data().at(0)->name(), QString("42TaskBis")); - QCOMPARE(result->data().at(1)->name(), QString("43Task")); - QCOMPARE(result->data().at(2)->name(), QString("43Task/44Task")); // name is: parentName/childName - QVERIFY(replaceHandlerCalled); - } else { - QCOMPARE(result->data().at(0)->name(), QString("45NoteBis")); - QCOMPARE(result->data().at(1)->name(), QString("46Note")); - QCOMPARE(result->data().at(2)->name(), QString("46Note/47Note")); // name is: parentName/childName - QVERIFY(replaceHandlerCalled); - } - } - void shouldLookInAllReportedForTopLevelSources_data() { QTest::addColumn("contentTypes"); diff --git a/tests/units/presentation/applicationmodeltest.cpp b/tests/units/presentation/applicationmodeltest.cpp --- a/tests/units/presentation/applicationmodeltest.cpp +++ b/tests/units/presentation/applicationmodeltest.cpp @@ -101,23 +101,7 @@ { } -public slots: - void setDefaultDataSource(const Domain::DataSource::Ptr &) - { - } - private: - Domain::QueryResult::Ptr createDataSourceQueryResult() Q_DECL_OVERRIDE - { - auto provider = Domain::QueryResultProvider::Ptr::create(); - return Domain::QueryResult::create(provider); - } - - bool isDefaultSource(const Domain::DataSource::Ptr &) Q_DECL_OVERRIDE - { - return false; - } - Presentation::AvailablePagesModelInterface *createAvailablePagesModel() Q_DECL_OVERRIDE { return new FakeAvailablePagesModel(this); diff --git a/tests/units/presentation/noteapplicationmodeltest.cpp b/tests/units/presentation/noteapplicationmodeltest.cpp --- a/tests/units/presentation/noteapplicationmodeltest.cpp +++ b/tests/units/presentation/noteapplicationmodeltest.cpp @@ -69,243 +69,6 @@ // THEN QVERIFY(qobject_cast(available)); } - - void shouldProvideDataSourceModel() - { - // GIVEN - Utils::MockObject sourceQueriesMock; - sourceQueriesMock(&Domain::DataSourceQueries::findNotes).when().thenReturn(Domain::QueryResult::Ptr()); - - auto projectQueries = Domain::ProjectQueries::Ptr(); - auto projectRepository = Domain::ProjectRepository::Ptr(); - auto contextQueries = Domain::ContextQueries::Ptr(); - auto contextRepository = Domain::ContextRepository::Ptr(); - auto sourceRepository = Domain::DataSourceRepository::Ptr(); - auto taskQueries = Domain::TaskQueries::Ptr(); - auto taskRepository = Domain::TaskRepository::Ptr(); - auto noteQueries = Domain::NoteQueries::Ptr(); - auto noteRepository = Domain::NoteRepository::Ptr(); - auto tagQueries = Domain::TagQueries::Ptr(); - auto tagRepository = Domain::TagRepository::Ptr(); - Presentation::NoteApplicationModel app(projectQueries, - projectRepository, - contextQueries, - contextRepository, - sourceQueriesMock.getInstance(), - sourceRepository, - taskQueries, - taskRepository, - noteQueries, - noteRepository, - tagQueries, - tagRepository); - - // WHEN - auto notes = app.dataSourcesModel(); - - // THEN - QVERIFY(qobject_cast(notes)); - } - - void shouldRetrieveDefaultNoteCollectionFromQueries() - { - // GIVEN - - // A data source - auto expectedSource = Domain::DataSource::Ptr::create(); - - // A source list containing the source we expect as default - auto provider = Domain::QueryResultProvider::Ptr::create(); - provider->append(Domain::DataSource::Ptr::create()); - provider->append(Domain::DataSource::Ptr::create()); - provider->append(Domain::DataSource::Ptr::create()); - provider->append(expectedSource); - provider->append(Domain::DataSource::Ptr::create()); - auto sourceResult = Domain::QueryResult::create(provider); - - // Queries mock returning the list of data sources - Utils::MockObject sourceQueriesMock; - sourceQueriesMock(&Domain::DataSourceQueries::findNotes).when().thenReturn(sourceResult); - sourceQueriesMock(&Domain::DataSourceQueries::findTasks).when().thenReturn(Domain::QueryResult::Ptr()); - foreach (const Domain::DataSource::Ptr &source, provider->data()) { - sourceQueriesMock(&Domain::DataSourceQueries::isDefaultSource).when(source).thenReturn(source == expectedSource); - } - - auto projectQueries = Domain::ProjectQueries::Ptr(); - auto projectRepository = Domain::ProjectRepository::Ptr(); - auto contextQueries = Domain::ContextQueries::Ptr(); - auto contextRepository = Domain::ContextRepository::Ptr(); - auto sourceRepository = Domain::DataSourceRepository::Ptr(); - auto taskQueries = Domain::TaskQueries::Ptr(); - auto taskRepository = Domain::TaskRepository::Ptr(); - auto noteQueries = Domain::NoteQueries::Ptr(); - auto noteRepository = Domain::NoteRepository::Ptr(); - auto tagQueries = Domain::TagQueries::Ptr(); - auto tagRepository = Domain::TagRepository::Ptr(); - Presentation::NoteApplicationModel app(projectQueries, - projectRepository, - contextQueries, - contextRepository, - sourceQueriesMock.getInstance(), - sourceRepository, - taskQueries, - taskRepository, - noteQueries, - noteRepository, - tagQueries, - tagRepository); - - // WHEN - auto source = app.defaultDataSource(); - - // THEN - QCOMPARE(source, expectedSource); - QVERIFY(sourceQueriesMock(&Domain::DataSourceQueries::isDefaultSource).when(expectedSource).exactly(1)); - } - - void shouldGiveFirstNoteCollectionAsDefaultIfNoneMatched() - { - // GIVEN - - // A list of irrelevant sources - auto provider = Domain::QueryResultProvider::Ptr::create(); - provider->append(Domain::DataSource::Ptr::create()); - provider->append(Domain::DataSource::Ptr::create()); - provider->append(Domain::DataSource::Ptr::create()); - provider->append(Domain::DataSource::Ptr::create()); - auto sourceResult = Domain::QueryResult::create(provider); - - // Queries mock returning the list of data sources - Utils::MockObject sourceQueriesMock; - sourceQueriesMock(&Domain::DataSourceQueries::findNotes).when().thenReturn(sourceResult); - sourceQueriesMock(&Domain::DataSourceQueries::findTasks).when().thenReturn(Domain::QueryResult::Ptr()); - foreach (const Domain::DataSource::Ptr &source, provider->data()) { - sourceQueriesMock(&Domain::DataSourceQueries::isDefaultSource).when(source).thenReturn(false); - } - - auto projectQueries = Domain::ProjectQueries::Ptr(); - auto projectRepository = Domain::ProjectRepository::Ptr(); - auto contextQueries = Domain::ContextQueries::Ptr(); - auto contextRepository = Domain::ContextRepository::Ptr(); - auto sourceRepository = Domain::DataSourceRepository::Ptr(); - auto taskQueries = Domain::TaskQueries::Ptr(); - auto taskRepository = Domain::TaskRepository::Ptr(); - auto noteQueries = Domain::NoteQueries::Ptr(); - auto noteRepository = Domain::NoteRepository::Ptr(); - auto tagQueries = Domain::TagQueries::Ptr(); - auto tagRepository = Domain::TagRepository::Ptr(); - Presentation::NoteApplicationModel app(projectQueries, - projectRepository, - contextQueries, - contextRepository, - sourceQueriesMock.getInstance(), - sourceRepository, - taskQueries, - taskRepository, - noteQueries, - noteRepository, - tagQueries, - tagRepository); - - // WHEN - auto source = app.defaultDataSource(); - - // THEN - QCOMPARE(source, provider->data().first()); - } - - void shouldProvideNullPointerIfNoNoteSourceIsAvailable() - { - // GIVEN - - // An empty source list - auto provider = Domain::QueryResultProvider::Ptr::create(); - auto sourceResult = Domain::QueryResult::create(provider); - - // Queries mock returning the list of data sources - Utils::MockObject sourceQueriesMock; - sourceQueriesMock(&Domain::DataSourceQueries::findNotes).when().thenReturn(sourceResult); - sourceQueriesMock(&Domain::DataSourceQueries::findTasks).when().thenReturn(Domain::QueryResult::Ptr()); - - auto projectQueries = Domain::ProjectQueries::Ptr(); - auto projectRepository = Domain::ProjectRepository::Ptr(); - auto contextQueries = Domain::ContextQueries::Ptr(); - auto contextRepository = Domain::ContextRepository::Ptr(); - auto sourceRepository = Domain::DataSourceRepository::Ptr(); - auto taskQueries = Domain::TaskQueries::Ptr(); - auto taskRepository = Domain::TaskRepository::Ptr(); - auto noteQueries = Domain::NoteQueries::Ptr(); - auto noteRepository = Domain::NoteRepository::Ptr(); - auto tagQueries = Domain::TagQueries::Ptr(); - auto tagRepository = Domain::TagRepository::Ptr(); - Presentation::NoteApplicationModel app(projectQueries, - projectRepository, - contextQueries, - contextRepository, - sourceQueriesMock.getInstance(), - sourceRepository, - taskQueries, - taskRepository, - noteQueries, - noteRepository, - tagQueries, - tagRepository); - - // WHEN - auto source = app.defaultDataSource(); - - // THEN - QVERIFY(source.isNull()); - } - - void shouldForwardDefaultNoteCollectionToQueries() - { - // GIVEN - - // A data source - auto source = Domain::DataSource::Ptr::create(); - - // A dummy source list - auto provider = Domain::QueryResultProvider::Ptr::create(); - auto sourceResult = Domain::QueryResult::create(provider); - - // Queries mock returning the list of data sources - Utils::MockObject sourceQueriesMock; - sourceQueriesMock(&Domain::DataSourceQueries::findNotes).when().thenReturn(sourceResult); - sourceQueriesMock(&Domain::DataSourceQueries::findTasks).when().thenReturn(Domain::QueryResult::Ptr()); - sourceQueriesMock(&Domain::DataSourceQueries::isDefaultSource).when(source).thenReturn(false); - sourceQueriesMock(&Domain::DataSourceQueries::changeDefaultSource).when(source).thenReturn(); - - auto projectQueries = Domain::ProjectQueries::Ptr(); - auto projectRepository = Domain::ProjectRepository::Ptr(); - auto contextQueries = Domain::ContextQueries::Ptr(); - auto contextRepository = Domain::ContextRepository::Ptr(); - auto sourceRepository = Domain::DataSourceRepository::Ptr(); - auto taskQueries = Domain::TaskQueries::Ptr(); - auto taskRepository = Domain::TaskRepository::Ptr(); - auto noteQueries = Domain::NoteQueries::Ptr(); - auto noteRepository = Domain::NoteRepository::Ptr(); - auto tagQueries = Domain::TagQueries::Ptr(); - auto tagRepository = Domain::TagRepository::Ptr(); - Presentation::NoteApplicationModel app(projectQueries, - projectRepository, - contextQueries, - contextRepository, - sourceQueriesMock.getInstance(), - sourceRepository, - taskQueries, - taskRepository, - noteQueries, - noteRepository, - tagQueries, - tagRepository); - - // WHEN - app.setDefaultDataSource(source); - - // THEN - QVERIFY(sourceQueriesMock(&Domain::DataSourceQueries::changeDefaultSource).when(source).exactly(1)); - } }; QTEST_MAIN(NoteApplicationModelTest) diff --git a/tests/units/presentation/taskapplicationmodeltest.cpp b/tests/units/presentation/taskapplicationmodeltest.cpp --- a/tests/units/presentation/taskapplicationmodeltest.cpp +++ b/tests/units/presentation/taskapplicationmodeltest.cpp @@ -67,234 +67,6 @@ // THEN QVERIFY(qobject_cast(available)); } - - void shouldProvideDataSourceModels() - { - // GIVEN - Utils::MockObject sourceQueriesMock; - sourceQueriesMock(&Domain::DataSourceQueries::findTasks).when().thenReturn(Domain::QueryResult::Ptr()); - - auto projectQueries = Domain::ProjectQueries::Ptr(); - auto projectRepository = Domain::ProjectRepository::Ptr(); - auto contextQueries = Domain::ContextQueries::Ptr(); - auto contextRepository = Domain::ContextRepository::Ptr(); - auto sourceRepository = Domain::DataSourceRepository::Ptr(); - auto taskQueries = Domain::TaskQueries::Ptr(); - auto taskRepository = Domain::TaskRepository::Ptr(); - auto noteRepository = Domain::NoteRepository::Ptr(); - auto tagQueries = Domain::TagQueries::Ptr(); - auto tagRepository = Domain::TagRepository::Ptr(); - Presentation::TaskApplicationModel app(projectQueries, - projectRepository, - contextQueries, - contextRepository, - sourceQueriesMock.getInstance(), - sourceRepository, - taskQueries, - taskRepository, - noteRepository, - tagQueries, - tagRepository); - - // WHEN - auto tasks = app.dataSourcesModel(); - - // THEN - QVERIFY(qobject_cast(tasks)); - } - - void shouldRetrieveDefaultTaskCollectionFromRepository() - { - // GIVEN - - // A data source - auto expectedSource = Domain::DataSource::Ptr::create(); - - // A source list containing the source we expect as default - auto provider = Domain::QueryResultProvider::Ptr::create(); - provider->append(Domain::DataSource::Ptr::create()); - provider->append(Domain::DataSource::Ptr::create()); - provider->append(Domain::DataSource::Ptr::create()); - provider->append(expectedSource); - provider->append(Domain::DataSource::Ptr::create()); - auto sourceResult = Domain::QueryResult::create(provider); - - // Queries mock returning the list of data sources - Utils::MockObject sourceQueriesMock; - sourceQueriesMock(&Domain::DataSourceQueries::findNotes).when().thenReturn(Domain::QueryResult::Ptr()); - sourceQueriesMock(&Domain::DataSourceQueries::findTasks).when().thenReturn(sourceResult); - foreach (const Domain::DataSource::Ptr &source, provider->data()) { - sourceQueriesMock(&Domain::DataSourceQueries::isDefaultSource).when(source).thenReturn(source == expectedSource); - } - - auto projectQueries = Domain::ProjectQueries::Ptr(); - auto projectRepository = Domain::ProjectRepository::Ptr(); - auto contextQueries = Domain::ContextQueries::Ptr(); - auto contextRepository = Domain::ContextRepository::Ptr(); - auto sourceRepository = Domain::DataSourceRepository::Ptr(); - auto taskQueries = Domain::TaskQueries::Ptr(); - auto taskRepository = Domain::TaskRepository::Ptr(); - auto noteRepository = Domain::NoteRepository::Ptr(); - auto tagQueries = Domain::TagQueries::Ptr(); - auto tagRepository = Domain::TagRepository::Ptr(); - Presentation::TaskApplicationModel app(projectQueries, - projectRepository, - contextQueries, - contextRepository, - sourceQueriesMock.getInstance(), - sourceRepository, - taskQueries, - taskRepository, - noteRepository, - tagQueries, - tagRepository); - - // WHEN - auto source = app.defaultDataSource(); - - // THEN - QCOMPARE(source, expectedSource); - QVERIFY(sourceQueriesMock(&Domain::DataSourceQueries::isDefaultSource).when(expectedSource).exactly(1)); - } - - void shouldGiveFirstTaskCollectionAsDefaultIfNoneMatched() - { - // GIVEN - - // A list of irrelevant sources - auto provider = Domain::QueryResultProvider::Ptr::create(); - provider->append(Domain::DataSource::Ptr::create()); - provider->append(Domain::DataSource::Ptr::create()); - provider->append(Domain::DataSource::Ptr::create()); - provider->append(Domain::DataSource::Ptr::create()); - auto sourceResult = Domain::QueryResult::create(provider); - - // Queries mock returning the list of data sources - Utils::MockObject sourceQueriesMock; - sourceQueriesMock(&Domain::DataSourceQueries::findNotes).when().thenReturn(Domain::QueryResult::Ptr()); - sourceQueriesMock(&Domain::DataSourceQueries::findTasks).when().thenReturn(sourceResult); - foreach (const Domain::DataSource::Ptr &source, provider->data()) { - sourceQueriesMock(&Domain::DataSourceQueries::isDefaultSource).when(source).thenReturn(false); - } - - auto projectQueries = Domain::ProjectQueries::Ptr(); - auto projectRepository = Domain::ProjectRepository::Ptr(); - auto contextQueries = Domain::ContextQueries::Ptr(); - auto contextRepository = Domain::ContextRepository::Ptr(); - auto sourceRepository = Domain::DataSourceRepository::Ptr(); - auto taskQueries = Domain::TaskQueries::Ptr(); - auto taskRepository = Domain::TaskRepository ::Ptr(); - auto noteRepository = Domain::NoteRepository::Ptr(); - auto tagQueries = Domain::TagQueries::Ptr(); - auto tagRepository = Domain::TagRepository::Ptr(); - Presentation::TaskApplicationModel app(projectQueries, - projectRepository, - contextQueries, - contextRepository, - sourceQueriesMock.getInstance(), - sourceRepository, - taskQueries, - taskRepository, - noteRepository, - tagQueries, - tagRepository); - - // WHEN - auto source = app.defaultDataSource(); - - // THEN - QCOMPARE(source, provider->data().first()); - } - - void shouldProvideNullPointerIfNoTaskSourceIsAvailable() - { - // GIVEN - - // An empty source list - auto provider = Domain::QueryResultProvider::Ptr::create(); - auto sourceResult = Domain::QueryResult::create(provider); - - // Queries mock returning the list of data sources - Utils::MockObject sourceQueriesMock; - sourceQueriesMock(&Domain::DataSourceQueries::findNotes).when().thenReturn(Domain::QueryResult::Ptr()); - sourceQueriesMock(&Domain::DataSourceQueries::findTasks).when().thenReturn(sourceResult); - - auto projectQueries = Domain::ProjectQueries::Ptr(); - auto projectRepository = Domain::ProjectRepository::Ptr(); - auto contextQueries = Domain::ContextQueries::Ptr(); - auto contextRepository = Domain::ContextRepository::Ptr(); - auto sourceRepository = Domain::DataSourceRepository::Ptr(); - auto taskQueries = Domain::TaskQueries::Ptr(); - auto taskRepository = Domain::TaskRepository::Ptr(); - auto noteRepository = Domain::NoteRepository::Ptr(); - auto tagQueries = Domain::TagQueries::Ptr(); - auto tagRepository = Domain::TagRepository::Ptr(); - Presentation::TaskApplicationModel app(projectQueries, - projectRepository, - contextQueries, - contextRepository, - sourceQueriesMock.getInstance(), - sourceRepository, - taskQueries, - taskRepository, - noteRepository, - tagQueries, - tagRepository); - - // WHEN - auto source = app.defaultDataSource(); - - // THEN - QVERIFY(source.isNull()); - } - - void shouldForwardDefaultTaskCollectionToQueries() - { - // GIVEN - - // A data source - auto source = Domain::DataSource::Ptr::create(); - - // A dummy source list - auto provider = Domain::QueryResultProvider::Ptr::create(); - auto sourceResult = Domain::QueryResult::create(provider); - - // Queries mock returning the list of data sources - Utils::MockObject sourceQueriesMock; - sourceQueriesMock(&Domain::DataSourceQueries::findNotes).when().thenReturn(Domain::QueryResult::Ptr()); - sourceQueriesMock(&Domain::DataSourceQueries::findTasks).when().thenReturn(sourceResult); - sourceQueriesMock(&Domain::DataSourceQueries::isDefaultSource).when(source).thenReturn(false); - sourceQueriesMock(&Domain::DataSourceQueries::changeDefaultSource).when(source).thenReturn(); - - auto projectQueries = Domain::ProjectQueries::Ptr(); - auto projectRepository = Domain::ProjectRepository::Ptr(); - auto contextQueries = Domain::ContextQueries::Ptr(); - auto contextRepository = Domain::ContextRepository::Ptr(); - auto sourceRepository = Domain::DataSourceRepository::Ptr(); - auto taskQueries = Domain::TaskQueries::Ptr(); - auto taskRepository = Domain::TaskRepository::Ptr(); - auto noteRepository = Domain::NoteRepository::Ptr(); - auto tagQueries = Domain::TagQueries::Ptr(); - auto tagRepository = Domain::TagRepository::Ptr(); - Presentation::TaskApplicationModel app(projectQueries, - projectRepository, - contextQueries, - contextRepository, - sourceQueriesMock.getInstance(), - sourceRepository, - taskQueries, - taskRepository, - noteRepository, - tagQueries, - tagRepository); - - - // WHEN - app.setDefaultDataSource(source); - - // THEN - QVERIFY(sourceQueriesMock(&Domain::DataSourceQueries::changeDefaultSource).when(source).exactly(1)); - } }; QTEST_MAIN(TaskApplicationModelTest) diff --git a/tests/units/widgets/CMakeLists.txt b/tests/units/widgets/CMakeLists.txt --- a/tests/units/widgets/CMakeLists.txt +++ b/tests/units/widgets/CMakeLists.txt @@ -2,7 +2,6 @@ applicationcomponentstest availablepagesviewtest availablesourcesviewtest - datasourcecomboboxtest datasourcedelegatetest editorviewtest filterwidgettest diff --git a/tests/units/widgets/applicationcomponentstest.cpp b/tests/units/widgets/applicationcomponentstest.cpp --- a/tests/units/widgets/applicationcomponentstest.cpp +++ b/tests/units/widgets/applicationcomponentstest.cpp @@ -39,13 +39,9 @@ #include "widgets/applicationcomponents.h" #include "widgets/availablepagesview.h" #include "widgets/availablesourcesview.h" -#include "widgets/datasourcecombobox.h" #include "widgets/editorview.h" #include "widgets/pageview.h" -typedef std::function ComboGetterFunction; -Q_DECLARE_METATYPE(ComboGetterFunction) - class ApplicationModelStub : public QObject { Q_OBJECT @@ -202,7 +198,6 @@ : QObject(parent) { qputenv("ZANSHIN_UNIT_TEST_RUN", "1"); - qRegisterMetaType(); } private slots: @@ -429,61 +424,6 @@ QCOMPARE(editorModel.property("artifact").value(), pageModel.itemAtRow(index.row())); } - - void shouldApplySourceModelAndPropertyToComboBox() - { - // GIVEN - Widgets::ApplicationComponents components; - auto model = QObjectPtr::create(); - QAbstractItemModel *sourcesModel = new QStandardItemModel(model.data()); - model->setProperty("dataSourcesModel", QVariant::fromValue(sourcesModel)); - - // WHEN - components.setModel(model); - - // THEN - Widgets::DataSourceComboBox *combo = components.defaultSourceCombo(); - QCOMPARE(combo->model(), sourcesModel); - - QCOMPARE(combo->defaultSourceObject(), model.data()); - QCOMPARE(combo->defaultSourceProperty(), QByteArray("defaultDataSource")); - } - - void shouldApplySourceModelAndPropertyAlsoToCreatedComboBox() - { - // GIVEN - Widgets::ApplicationComponents components; - // Force creation - components.defaultSourceCombo(); - - auto model = QObjectPtr::create(); - QAbstractItemModel *sourcesModel = new QStandardItemModel(model.data()); - model->setProperty("dataSourcesModel", QVariant::fromValue(sourcesModel)); - - // WHEN - components.setModel(model); - - // THEN - Widgets::DataSourceComboBox *combo = components.defaultSourceCombo(); - QCOMPARE(combo->model(), sourcesModel); - - QCOMPARE(combo->defaultSourceObject(), model.data()); - QCOMPARE(combo->defaultSourceProperty(), QByteArray("defaultDataSource")); - } - - void shouldProvideSettingsAction() - { - // GIVEN - Widgets::ApplicationComponents components; - - // WHEN - QList actions = components.configureActions(); - auto defaultAction = qobject_cast(actions.at(0)); - - // THEN - QCOMPARE(defaultAction->defaultWidget()->findChild("defaultSourceCombo"), components.defaultSourceCombo()); - QCOMPARE(defaultAction->objectName(), QString("settings_default_source")); - } }; QTEST_MAIN(ApplicationComponentsTest) diff --git a/tests/units/widgets/datasourcecomboboxtest.cpp b/tests/units/widgets/datasourcecomboboxtest.cpp deleted file mode 100644 --- a/tests/units/widgets/datasourcecomboboxtest.cpp +++ /dev/null @@ -1,206 +0,0 @@ -/* This file is part of Zanshin - - Copyright 2014 Kevin Ottens - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License or (at your option) version 3 or any later version - accepted by the membership of KDE e.V. (or its successor approved - by the membership of KDE e.V.), which shall act as a proxy - defined in Section 14 of version 3 of the license. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - USA. -*/ - -#include - -#include -#include -#include -#include -#include - -#include "presentation/querytreemodelbase.h" -#include "widgets/datasourcecombobox.h" - -class DataSourceComboBoxTest : public QObject -{ - Q_OBJECT -private: - QStandardItem *createStandardItem(const QString &name) - { - auto source = Domain::DataSource::Ptr::create(); - source->setName(name); - return createStandardItem(source); - } - - QStandardItem *createStandardItem(const Domain::DataSource::Ptr &source) - { - QStandardItem *item = new QStandardItem; - item->setData(QVariant::fromValue(source), Presentation::QueryTreeModelBase::ObjectRole); - item->setData(source->name(), Qt::DisplayRole); - item->setData(source->iconName(), Presentation::QueryTreeModelBase::IconNameRole); - return item; - } - -private slots: - void shouldSelectDefaultSourceSilently() - { - // GIVEN - auto defaultSource = Domain::DataSource::Ptr::create(); - defaultSource->setName("Default"); - - QObject stub; - stub.setProperty("defaultSource", QVariant::fromValue(defaultSource)); - QStandardItemModel model; - model.appendRow(createStandardItem("Foo")); - model.appendRow(createStandardItem("Bar")); - model.appendRow(createStandardItem(defaultSource)); - model.appendRow(createStandardItem("Baz")); - - Widgets::DataSourceComboBox combo; - QSignalSpy spy(&combo, SIGNAL(sourceActivated(Domain::DataSource::Ptr))); - - // WHEN - combo.setModel(&model); - combo.setDefaultSourceProperty(&stub, "defaultSource"); - - // THEN - QVERIFY(spy.isValid()); - QVERIFY(spy.isEmpty()); - QCOMPARE(combo.count(), 4); - QCOMPARE(combo.currentIndex(), 2); - QCOMPARE(combo.itemSource(2), defaultSource); - } - - void shouldSelectDefaultSourceSilentlyIfItAppearsLater() - { - // GIVEN - auto defaultSource = Domain::DataSource::Ptr::create(); - defaultSource->setName("Default"); - - QObject stub; - QStandardItemModel model; - model.appendRow(createStandardItem("Foo")); - model.appendRow(createStandardItem("Bar")); - model.appendRow(createStandardItem("Baz")); - - Widgets::DataSourceComboBox combo; - QSignalSpy spy(&combo, SIGNAL(sourceActivated(Domain::DataSource::Ptr))); - combo.setDefaultSourceProperty(&stub, "defaultSource"); - combo.setModel(&model); - - QVERIFY(spy.isValid()); - QVERIFY(spy.isEmpty()); - QCOMPARE(combo.count(), 3); - QCOMPARE(combo.currentIndex(), 0); - - // WHEN - stub.setProperty("defaultSource", QVariant::fromValue(defaultSource)); - model.insertRow(2, createStandardItem(defaultSource)); - - // THEN - QVERIFY(spy.isEmpty()); - QCOMPARE(combo.count(), 4); - QCOMPARE(combo.currentIndex(), 2); - QCOMPARE(combo.itemSource(2), defaultSource); - } - - void shouldNotifyKeyboardUserChange() - { - // GIVEN - auto defaultSource = Domain::DataSource::Ptr::create(); - defaultSource->setName("Default"); - - auto userSelectedSource = Domain::DataSource::Ptr::create(); - userSelectedSource->setName("To Be Selected"); - - QObject stub; - stub.setProperty("defaultSource", QVariant::fromValue(defaultSource)); - QStandardItemModel model; - model.appendRow(createStandardItem("Foo")); - model.appendRow(createStandardItem("Bar")); - model.appendRow(createStandardItem(defaultSource)); - model.appendRow(createStandardItem(userSelectedSource)); - model.appendRow(createStandardItem("Baz")); - - Widgets::DataSourceComboBox combo; - QSignalSpy spy(&combo, SIGNAL(sourceActivated(Domain::DataSource::Ptr))); - combo.setModel(&model); - combo.setDefaultSourceProperty(&stub, "defaultSource"); - QVERIFY(spy.isValid()); - - // WHEN - QTest::keyClick(combo.focusProxy(), Qt::Key_Down); - - // THEN - QCOMPARE(spy.size(), 1); - QCOMPARE(spy.takeFirst().takeFirst().value(), userSelectedSource); - QCOMPARE(combo.currentIndex(), 3); - } - - void shouldNotifyMouseUserChange() - { - // GIVEN - auto defaultSource = Domain::DataSource::Ptr::create(); - defaultSource->setName("Default"); - - auto userSelectedSource = Domain::DataSource::Ptr::create(); - userSelectedSource->setName("To Be Selected"); - - QObject stub; - stub.setProperty("defaultSource", QVariant::fromValue(defaultSource)); - QStandardItemModel model; - model.appendRow(createStandardItem("Foo")); - model.appendRow(createStandardItem(userSelectedSource)); - model.appendRow(createStandardItem("Bar")); - model.appendRow(createStandardItem(defaultSource)); - model.appendRow(createStandardItem("Baz")); - - Widgets::DataSourceComboBox combo; - QSignalSpy spy(&combo, SIGNAL(sourceActivated(Domain::DataSource::Ptr))); - combo.setModel(&model); - combo.setDefaultSourceProperty(&stub, "defaultSource"); - QVERIFY(spy.isValid()); - - combo.show(); - QTest::qWaitForWindowShown(&combo); - - // WHEN - QComboBox *proxy = qobject_cast(combo.focusProxy()); - QVERIFY(proxy); - QTest::mouseClick(proxy, Qt::LeftButton, Q_NULLPTR, QPoint()); - - // Make sure the popup is on screen - QTest::qWaitForWindowShown(proxy->view()); - QTest::qWait(500); - - // Scan to find coordinates of the second item - const int x = proxy->view()->rect().center().x(); - for (int y = 0; y < proxy->view()->rect().height(); y += 4) { - const QPoint point(x, y); - if (proxy->view()->indexAt(point).row() == 1) { - QTest::mouseClick(proxy->view()->viewport(), Qt::LeftButton, Q_NULLPTR, point); - break; - } - } - - // THEN - QCOMPARE(spy.size(), 1); - QCOMPARE(spy.takeFirst().takeFirst().value(), userSelectedSource); - QCOMPARE(combo.currentIndex(), 1); - } -}; - -QTEST_MAIN(DataSourceComboBoxTest) - -#include "datasourcecomboboxtest.moc"