From 9c439b3d7daf0955fbd3191b1cfac9ca630887c1 2019-10-30 18:25:03 From: Alexis Jeandet Date: 2019-10-30 18:25:03 Subject: [PATCH] New data sources system switch complete Signed-off-by: Alexis Jeandet --- diff --git a/app/PySide2-bindings/PyDataProvider.h b/app/PySide2-bindings/PyDataProvider.h index 37db653..87d610a 100644 --- a/app/PySide2-bindings/PyDataProvider.h +++ b/app/PySide2-bindings/PyDataProvider.h @@ -2,9 +2,10 @@ #include #include #include -#include #include #include +#include + #include #include // must be included last because of Python/Qt definition of slots @@ -68,8 +69,8 @@ class PyDataProvider : public IDataProvider public: PyDataProvider() { - auto& dataSourceController = sqpApp->dataSourceController(); - dataSourceController.registerProvider(this); + auto& dataSources = sqpApp->dataSources(); + dataSources.addProvider(this); } virtual ~PyDataProvider() {} @@ -118,12 +119,12 @@ public: inline void register_products(const QVector& products) { - auto& dataSourceController = sqpApp->dataSourceController(); + auto& dataSources = sqpApp->dataSources(); auto id = this->id(); auto data_source_name = this->name(); std::for_each(std::cbegin(products), std::cend(products), - [&id, &dataSourceController](const Product* product) { - dataSourceController.setDataSourceItem(id, product->path, product->metadata); + [&id, &dataSources](const Product* product) { + dataSources.addDataSourceItem(id, product->path, product->metadata); }); } }; diff --git a/app/src/MainWindow.cpp b/app/src/MainWindow.cpp index 514893f..799541e 100644 --- a/app/src/MainWindow.cpp +++ b/app/src/MainWindow.cpp @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -114,10 +113,6 @@ MainWindow::MainWindow(QWidget* parent) // Widgets / controllers connections - // DataSource - connect(&sqpApp->dataSourceController(), &DataSourceController::dataSourceItemSet, - m_Ui->dataSourceWidget, &DataSourceWidget::addDataSource); - // Time // connect(timeWidget, SIGNAL(timeUpdated(DateTimeRange)), &sqpApp->timeController(), // SLOT(onTimeToUpdate(DateTimeRange))); diff --git a/core b/core index b081849..46467fb 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit b081849458c211dcc59f72b11542959db2301162 +Subproject commit 46467fb43b8d07fe4f4a45df949ec4ae858ccf9d diff --git a/gui/include/DataSource/DataSourceTreeWidget.h b/gui/include/DataSource/DataSourceTreeWidget.h deleted file mode 100644 index 43141e3..0000000 --- a/gui/include/DataSource/DataSourceTreeWidget.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef SCIQLOP_DATASOURCETREEWIDGET_H -#define SCIQLOP_DATASOURCETREEWIDGET_H - -#include - -class DataSourceTreeWidget : public QTreeWidget { -public: - DataSourceTreeWidget(QWidget *parent); - -protected: - QMimeData *mimeData(const QList items) const override; - void startDrag(Qt::DropActions supportedActions) override; -}; - -#endif // SCIQLOP_DATASOURCETREEWIDGET_H diff --git a/gui/include/DataSource/DataSourceTreeWidgetHelper.h b/gui/include/DataSource/DataSourceTreeWidgetHelper.h deleted file mode 100644 index 9e1e849..0000000 --- a/gui/include/DataSource/DataSourceTreeWidgetHelper.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef SCIQLOP_DATASOURCETREEWIDGETHELPER_H -#define SCIQLOP_DATASOURCETREEWIDGETHELPER_H - -#include - -class DataSourceTreeWidgetItem; -class QTreeWidget; - -class DataSourceTreeWidgetHelper { -public: - /// Signature of the function associated to the filtering action - using FilterFunction = std::function; - - /** - * Filters a tree widget according to a function. If an item is valid according to this - * function, all of its ancestors and children are shown - * @param treeWidget the widget to filter - * @param fun the filter function - */ - static void filter(QTreeWidget &treeWidget, FilterFunction fun) noexcept; -}; - -#endif // SCIQLOP_DATASOURCETREEWIDGETHELPER_H diff --git a/gui/include/DataSource/DataSourceTreeWidgetItem.h b/gui/include/DataSource/DataSourceTreeWidgetItem.h deleted file mode 100644 index d58190f..0000000 --- a/gui/include/DataSource/DataSourceTreeWidgetItem.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef SCIQLOP_DATASOURCETREEWIDGETITEM_H -#define SCIQLOP_DATASOURCETREEWIDGETITEM_H - -#include - -#include -#include - -Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem) - -class DataSourceItem; - -/** - * @brief The DataSourceTreeWidgetItem is the graphical representation of a data source item. It is - * intended to be displayed in a QTreeWidget. - * @sa DataSourceItem - */ -class DataSourceTreeWidgetItem : public QTreeWidgetItem { -public: - explicit DataSourceTreeWidgetItem(const DataSourceItem *data, int type = Type); - explicit DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data, - int type = Type); - - const DataSourceItem *data() const; - - virtual QVariant data(int column, int role) const override; - virtual void setData(int column, int role, const QVariant &value) override; - - /// @return the actions associated to the item - QList actions() const noexcept; - -private: - class DataSourceTreeWidgetItemPrivate; - spimpl::unique_impl_ptr impl; -}; - -#endif // SCIQLOP_DATASOURCETREEWIDGETITEM_H diff --git a/gui/include/DataSource/DataSourceWidget.h b/gui/include/DataSource/DataSourceWidget.h index 388dbd8..1d18cc0 100644 --- a/gui/include/DataSource/DataSourceWidget.h +++ b/gui/include/DataSource/DataSourceWidget.h @@ -3,9 +3,10 @@ #include -#include +#include -namespace Ui { +namespace Ui +{ class DataSourceWidget; } // Ui @@ -15,33 +16,20 @@ class DataSourceItem; * @brief The DataSourceWidget handles the graphical representation (as a tree) of the data sources * attached to SciQlop. */ -class DataSourceWidget : public QWidget { +class DataSourceWidget : public QWidget +{ Q_OBJECT public: - explicit DataSourceWidget(QWidget *parent = 0); + explicit DataSourceWidget(QWidget* parent = 0); virtual ~DataSourceWidget() noexcept; -public slots: - /** - * Adds a data source. An item associated to the data source is created and then added to the - * representation tree - * @param dataSource the data source to add. The pointer has to be not null - */ - void addDataSource(DataSourceItem *dataSource) noexcept; - private: void updateTreeWidget() noexcept; - Ui::DataSourceWidget *ui; - std::unique_ptr m_Root; - -private slots: - /// Slot called when the filtering text has changed - void filterChanged(const QString &text) noexcept; + Ui::DataSourceWidget* ui; + QSortFilterProxyModel m_model_proxy; - /// Slot called when right clicking on an item in the tree (displays a menu) - void onTreeMenuRequested(const QPoint &pos) noexcept; }; #endif // SCIQLOP_DATASOURCEWIDGET_H diff --git a/gui/include/SqpApplication.h b/gui/include/SqpApplication.h index d0e7795..5b78583 100644 --- a/gui/include/SqpApplication.h +++ b/gui/include/SqpApplication.h @@ -22,6 +22,7 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_SqpApplication) #define sqpApp (static_cast(QCoreApplication::instance())) class DataSourceController; +class DataSources; class NetworkController; class TimeController; class VariableController; @@ -68,7 +69,8 @@ public: void initialize(); /// Accessors for the differents sciqlop controllers - DataSourceController& dataSourceController() noexcept; + //DataSourceController& dataSourceController() noexcept; + DataSources& dataSources() noexcept; NetworkController& networkController() noexcept; TimeController& timeController() noexcept; VariableController2& variableController() noexcept; diff --git a/gui/meson.build b/gui/meson.build index e6bdca2..8506312 100644 --- a/gui/meson.build +++ b/gui/meson.build @@ -7,9 +7,6 @@ gui_moc_headers = [ './include/DragAndDrop/DragDropScroller.h', './include/Settings/SqpSettingsDialog.h', './include/Settings/SqpSettingsGeneralWidget.h', - './include/DataSource/DataSourceTreeWidgetHelper.h', - './include/DataSource/DataSourceTreeWidget.h', - './include/DataSource/DataSourceTreeWidgetItem.h', './include/DataSource/DataSourceWidget.h', './include/Catalogue2/repositoriestreeview.h', './include/Catalogue2/browser.h', @@ -104,10 +101,7 @@ gui_sources = [ './src/DragAndDrop/DragDropGuiController.cpp', './src/Settings/SqpSettingsGeneralWidget.cpp', './src/Settings/SqpSettingsDialog.cpp', - './src/DataSource/DataSourceTreeWidgetItem.cpp', - './src/DataSource/DataSourceTreeWidgetHelper.cpp', './src/DataSource/DataSourceWidget.cpp', - './src/DataSource/DataSourceTreeWidget.cpp', './src/Catalogue2/eventstreeview.cpp', './src/Catalogue2/eventeditor.cpp', './src/Catalogue2/repositoriestreeview.cpp', diff --git a/gui/src/DataSource/DataSourceTreeWidget.cpp b/gui/src/DataSource/DataSourceTreeWidget.cpp deleted file mode 100644 index c95ebcd..0000000 --- a/gui/src/DataSource/DataSourceTreeWidget.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "DataSource/DataSourceTreeWidget.h" -#include "Common/MimeTypesDef.h" -#include "DataSource/DataSourceController.h" -#include "DataSource/DataSourceItem.h" -#include "DataSource/DataSourceTreeWidgetItem.h" - -#include "DragAndDrop/DragDropGuiController.h" -#include "SqpApplication.h" - -#include - -DataSourceTreeWidget::DataSourceTreeWidget(QWidget *parent) : QTreeWidget(parent) -{ -} - -QMimeData *DataSourceTreeWidget::mimeData(const QList items) const -{ - auto mimeData = new QMimeData; - - // Basic check to ensure the item are correctly typed - Q_ASSERT(items.isEmpty() || dynamic_cast(items.first()) != nullptr); - - QVariantList productData; - - for (auto item : items) { - auto dataSourceTreeItem = static_cast(item); - auto dataSource = dataSourceTreeItem->data(); - - if (dataSource->type() == DataSourceItemType::COMPONENT - || dataSource->type() == DataSourceItemType::PRODUCT) { - auto metaData = dataSource->data(); - productData << metaData; - } - } - - auto encodedData = sqpApp->dataSourceController().mimeDataForProductsData(productData); - mimeData->setData(MIME_TYPE_PRODUCT_LIST, encodedData); - - return mimeData; -} - -void DataSourceTreeWidget::startDrag(Qt::DropActions supportedActions) -{ - // Resets the drag&drop operations before it's starting - sqpApp->dragDropGuiController().resetDragAndDrop(); - QTreeWidget::startDrag(supportedActions); -} diff --git a/gui/src/DataSource/DataSourceTreeWidgetHelper.cpp b/gui/src/DataSource/DataSourceTreeWidgetHelper.cpp deleted file mode 100644 index b5b969b..0000000 --- a/gui/src/DataSource/DataSourceTreeWidgetHelper.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "DataSource/DataSourceTreeWidgetHelper.h" -#include "DataSource/DataSourceTreeWidgetItem.h" - -namespace { - -bool filterTreeItem(DataSourceTreeWidgetItem &treeItem, - DataSourceTreeWidgetHelper::FilterFunction fun, bool parentValid = false) -{ - auto selfValid = parentValid || fun(treeItem); - - auto childValid = false; - auto childCount = treeItem.childCount(); - for (auto i = 0; i < childCount; ++i) { - if (auto childItem = dynamic_cast(treeItem.child(i))) { - childValid |= filterTreeItem(*childItem, fun, selfValid); - } - } - - auto valid = selfValid || childValid; - - treeItem.setHidden(!valid); - - return valid; -} - -} // namespace - -void DataSourceTreeWidgetHelper::filter(QTreeWidget &treeWidget, FilterFunction fun) noexcept -{ - auto itemCount = treeWidget.topLevelItemCount(); - for (auto i = 0; i < itemCount; ++i) { - if (auto item = dynamic_cast(treeWidget.topLevelItem(i))) { - filterTreeItem(*item, fun); - } - } -} diff --git a/gui/src/DataSource/DataSourceTreeWidgetItem.cpp b/gui/src/DataSource/DataSourceTreeWidgetItem.cpp deleted file mode 100644 index 8815bb2..0000000 --- a/gui/src/DataSource/DataSourceTreeWidgetItem.cpp +++ /dev/null @@ -1,225 +0,0 @@ -#include -#include -#include - -#include - -Q_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem, "DataSourceTreeWidgetItem") - -namespace { - -// Column indexes -const auto NAME_COLUMN = 0; - -/** - * Generates the full name of an item. - * - * The full name of an item is its name possibly suffixed by the name of its plugin, in case there - * are items of the same name in its relatives - * @param item the item for which to generate the complete name - * @return the complete name of the item - */ -QString completeName(const DataSourceItem &item) -{ - auto name = item.name(); - - if (item.type() == DataSourceItemType::NODE) { - return name; - } - - auto parentItem = item.parentItem(); - if (!parentItem) { - return name; - } - - // Finds in item's relatives items that have the same name - bool foundSameName = false; - for (auto i = 0, count = parentItem->childCount(); i < count && !foundSameName; ++i) { - auto child = parentItem->child(i); - foundSameName = child != &item - && QString::compare(child->name(), item.name(), Qt::CaseInsensitive) == 0; - } - - // If the name of the item is not unique, it is completed by the plugin suffix - return foundSameName - ? QString{"%1 (%2)"}.arg(name, item.data(DataSourceItem::PLUGIN_DATA_KEY).toString()) - : name; -} - -QIcon itemIcon(const DataSourceItem *dataSource) -{ - if (dataSource) { - auto dataSourceType = dataSource->type(); - switch (dataSourceType) { - case DataSourceItemType::NODE: { - return dataSource->isRoot() ? QIcon{":/icones/dataSourceRoot.png"} - : QIcon{":/icones/dataSourceNode.png"}; - } - case DataSourceItemType::PRODUCT: - return QIcon{":/icones/dataSourceProduct.png"}; - case DataSourceItemType::COMPONENT: - return QIcon{":/icones/dataSourceComponent.png"}; - default: - // No action - break; - } - - qCWarning(LOG_DataSourceTreeWidgetItem()) - << QObject::tr("Can't set data source icon : unknown data source type"); - } - else { - qCCritical(LOG_DataSourceTreeWidgetItem()) - << QObject::tr("Can't set data source icon : the data source is null"); - } - - // Default cases - return QIcon{}; -} - -/// @return the tooltip text for a variant. The text depends on whether the data is a simple variant -/// or a list of variants -QString tooltipValue(const QVariant &variant) noexcept -{ - // If the variant is a list of variants, the text of the tooltip is of the form: {val1, val2, - // ...} - if (variant.canConvert()) { - auto valueString = QStringLiteral("{"); - - auto variantList = variant.value(); - for (auto it = variantList.cbegin(), end = variantList.cend(); it != end; ++it) { - valueString.append(it->toString()); - - if (std::distance(it, end) != 1) { - valueString.append(", "); - } - } - - valueString.append(QStringLiteral("}")); - - return valueString; - } - else { - return variant.toString(); - } -} - -QString itemTooltip(const DataSourceItem *dataSource) noexcept -{ - // The tooltip displays all item's data - if (dataSource) { - auto result = QString{}; - - const auto &data = dataSource->data(); - for (auto it = data.cbegin(), end = data.cend(); it != end; ++it) { - result.append(QString{"%1: %2
"}.arg(it.key(), tooltipValue(it.value()))); - } - - return result; - } - else { - qCCritical(LOG_DataSourceTreeWidgetItem()) - << QObject::tr("Can't set data source tooltip : the data source is null"); - - return QString{}; - } -} - -} // namespace - -struct DataSourceTreeWidgetItem::DataSourceTreeWidgetItemPrivate { - explicit DataSourceTreeWidgetItemPrivate(const DataSourceItem *data) - : m_Data{data}, m_Name{completeName(*m_Data)} - { - } - - /// Model used to retrieve data source information - const DataSourceItem *m_Data; - /// Name displayed - QString m_Name; - /// Actions associated to the item. The parent of the item (QTreeWidget) takes the ownership of - /// the actions - QList m_Actions; //TODO check if no memory leak here -}; - -DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(const DataSourceItem *data, int type) - : DataSourceTreeWidgetItem{nullptr, data, type} -{ -} - -DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data, - int type) - : QTreeWidgetItem{parent, type}, - impl{spimpl::make_unique_impl(data)} -{ - // Sets the icon and the tooltip depending on the data source - setIcon(0, itemIcon(impl->m_Data)); - setToolTip(0, itemTooltip(impl->m_Data)); - - // Generates tree actions based on the item actions - auto createTreeAction = [this, &parent](const auto &itemAction) { - auto treeAction = new QAction{itemAction->name(), parent}; - - // Executes item action when tree action is triggered - QObject::connect(treeAction, &QAction::triggered, itemAction, - &DataSourceItemAction::execute); - - return treeAction; - }; - - auto itemActions = impl->m_Data->actions(); - std::transform(std::cbegin(itemActions), std::cend(itemActions), - std::back_inserter(impl->m_Actions), createTreeAction); - - // Sets the flags of the items - auto flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled; - if (data->type() == DataSourceItemType::COMPONENT - || data->type() == DataSourceItemType::PRODUCT) { - flags |= Qt::ItemIsDragEnabled; - } - - setFlags(flags); -} - -const DataSourceItem *DataSourceTreeWidgetItem::data() const -{ - return impl->m_Data; -} - -QVariant DataSourceTreeWidgetItem::data(int column, int role) const -{ - if (role == Qt::DisplayRole) { - if (impl->m_Data) { - switch (column) { - case NAME_COLUMN: - return impl->m_Name; - default: - // No action - break; - } - - qCWarning(LOG_DataSourceTreeWidgetItem()) - << QObject::tr("Can't get data (unknown column %1)").arg(column); - } - else { - qCCritical(LOG_DataSourceTreeWidgetItem()) << QObject::tr("Can't get data (null item)"); - } - - return QVariant{}; - } - else { - return QTreeWidgetItem::data(column, role); - } -} - -void DataSourceTreeWidgetItem::setData(int column, int role, const QVariant &value) -{ - // Data can't be changed by edition - if (role != Qt::EditRole) { - QTreeWidgetItem::setData(column, role, value); - } -} - -QList DataSourceTreeWidgetItem::actions() const noexcept -{ - return impl->m_Actions; -} diff --git a/gui/src/DataSource/DataSourceWidget.cpp b/gui/src/DataSource/DataSourceWidget.cpp index b4eaeae..4b0a9cb 100644 --- a/gui/src/DataSource/DataSourceWidget.cpp +++ b/gui/src/DataSource/DataSourceWidget.cpp @@ -2,11 +2,10 @@ #include -#include -#include -#include +#include + +#include -#include namespace { @@ -17,47 +16,23 @@ const auto TREE_NB_COLUMNS = 1; /// Header labels for the tree const auto TREE_HEADER_LABELS = QStringList { QObject::tr("Name") }; -/** - * Creates the item associated to a data source - * @param dataSource the data source for which to create the item - * @return the new item - */ -DataSourceTreeWidgetItem* createTreeWidgetItem(DataSourceItem* dataSource) -{ - // Creates item for the data source - auto item = new DataSourceTreeWidgetItem { dataSource }; - // Generates items for the children of the data source - std::for_each(dataSource->cbegin(), dataSource->cend(), - [&item](const std::unique_ptr& child) { - item->addChild(createTreeWidgetItem(child.get())); - }); - return item; -} - } // namespace DataSourceWidget::DataSourceWidget(QWidget* parent) : QWidget { parent } , ui { new Ui::DataSourceWidget } - , m_Root { std::make_unique( - DataSourceItemType::NODE, QStringLiteral("Sources")) } { ui->setupUi(this); - - // Set tree properties - ui->treeWidget->setColumnCount(TREE_NB_COLUMNS); - ui->treeWidget->setHeaderLabels(TREE_HEADER_LABELS); - ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu); - - // Connection to show a menu when right clicking on the tree - connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this, - &DataSourceWidget::onTreeMenuRequested); + m_model_proxy.setSourceModel(&(sqpApp->dataSources())); + ui->treeView->setModel(&m_model_proxy); + ui->treeView->setDragEnabled(true); + m_model_proxy.setFilterRole(Qt::ToolTipRole); + m_model_proxy.setRecursiveFilteringEnabled(true); // Connection to filter tree - connect(ui->filterLineEdit, &QLineEdit::textChanged, this, &DataSourceWidget::filterChanged); + connect(ui->filterLineEdit, &QLineEdit::textChanged, &m_model_proxy, static_cast( + &QSortFilterProxyModel::setFilterRegExp)); - // First init - updateTreeWidget(); } DataSourceWidget::~DataSourceWidget() noexcept @@ -65,60 +40,3 @@ DataSourceWidget::~DataSourceWidget() noexcept delete ui; } -void DataSourceWidget::addDataSource(DataSourceItem* dataSource) noexcept -{ - // Merges the data source (without taking its root) - if (dataSource) - { - std::for_each(std::cbegin(*dataSource), std::cend(*dataSource), - [this](const auto& child) { this->m_Root->merge(*child.get()); }); - updateTreeWidget(); - } -} - -void DataSourceWidget::updateTreeWidget() noexcept -{ - ui->treeWidget->clear(); - - auto rootItem = createTreeWidgetItem(m_Root.get()); - ui->treeWidget->addTopLevelItem(rootItem); - rootItem->setExpanded(true); - - // Sorts tree - ui->treeWidget->setSortingEnabled(true); - ui->treeWidget->sortByColumn(0, Qt::AscendingOrder); -} - -void DataSourceWidget::filterChanged(const QString& text) noexcept -{ - auto validateItem = [&text](const DataSourceTreeWidgetItem& item) { - auto regExp = QRegExp { text, Qt::CaseInsensitive, QRegExp::Wildcard }; - - // An item is valid if any of its metadata validates the text filter - auto itemMetadata = item.data()->data(); - auto itemMetadataEnd = itemMetadata.cend(); - auto acceptFilter - = [®Exp](const auto& variant) { return variant.toString().contains(regExp); }; - - return std::find_if(itemMetadata.cbegin(), itemMetadataEnd, acceptFilter) - != itemMetadataEnd; - }; - - // Applies filter on tree widget - DataSourceTreeWidgetHelper::filter(*ui->treeWidget, validateItem); -} - -void DataSourceWidget::onTreeMenuRequested(const QPoint& pos) noexcept -{ - // Retrieves the selected item in the tree, and build the menu from its actions - if (auto selectedItem = dynamic_cast(ui->treeWidget->itemAt(pos))) - { - QMenu treeMenu {}; - treeMenu.addActions(selectedItem->actions()); - - if (!treeMenu.isEmpty()) - { - treeMenu.exec(QCursor::pos()); - } - } -} diff --git a/gui/src/DragAndDrop/DragDropGuiController.cpp b/gui/src/DragAndDrop/DragDropGuiController.cpp index e0f077b..724cc71 100644 --- a/gui/src/DragAndDrop/DragDropGuiController.cpp +++ b/gui/src/DragAndDrop/DragDropGuiController.cpp @@ -7,10 +7,9 @@ #include "Visualization/VisualizationWidget.h" #include "Visualization/operations/FindVariableOperation.h" -#include "DataSource/DataSourceController.h" #include "Variable/VariableController2.h" -#include "Common/MimeTypesDef.h" +#include "MimeTypes/MimeTypes.h" #include "Common/VisualizationDef.h" #include @@ -252,10 +251,10 @@ bool DragDropGuiController::checkMimeDataForVisualization( auto result = false; - if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) + if (mimeData->hasFormat(MIME::MIME_TYPE_VARIABLE_LIST)) { auto variables = sqpApp->variableController().variables( - Variable2::IDs(mimeData->data(MIME_TYPE_VARIABLE_LIST))); + Variable2::IDs(mimeData->data(MIME::MIME_TYPE_VARIABLE_LIST))); if (variables.size() == 1) { @@ -306,10 +305,10 @@ bool DragDropGuiController::checkMimeDataForVisualization( // result = false: cannot drop multiple variables in the visualisation } } - else if (mimeData->hasFormat(MIME_TYPE_PRODUCT_LIST)) + else if (mimeData->hasFormat(MIME::MIME_TYPE_PRODUCT_LIST)) { - auto productDataList = sqpApp->dataSourceController().productsDataForMimeData( - mimeData->data(MIME_TYPE_PRODUCT_LIST)); + auto productDataList = MIME::decode( + mimeData->data(MIME::MIME_TYPE_PRODUCT_LIST)); if (productDataList.count() == 1) { result = true; diff --git a/gui/src/SqpApplication.cpp b/gui/src/SqpApplication.cpp index 4b09291..294c8bb 100644 --- a/gui/src/SqpApplication.cpp +++ b/gui/src/SqpApplication.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include @@ -26,7 +26,8 @@ public: // /////////////////////////////// // // VariableController <-> DataSourceController - connect(&m_DataSourceController, &DataSourceController::createVariable, + connect(&m_DataSources, static_cast)>(&DataSources::createVariable), [](const QString& variableName, const QVariantHash& variableMetadata, std::shared_ptr variableProvider) { sqpApp->variableController().createVariable(variableName, variableMetadata, @@ -34,8 +35,6 @@ public: }); - m_DataSourceController.moveToThread(&m_DataSourceControllerThread); - m_DataSourceControllerThread.setObjectName("DataSourceControllerThread"); m_NetworkController.moveToThread(&m_NetworkControllerThread); m_NetworkControllerThread.setObjectName("NetworkControllerThread"); @@ -45,20 +44,17 @@ public: virtual ~SqpApplicationPrivate() { - m_DataSourceControllerThread.quit(); - m_DataSourceControllerThread.wait(); m_NetworkControllerThread.quit(); m_NetworkControllerThread.wait(); } - DataSourceController m_DataSourceController; + DataSources m_DataSources; std::shared_ptr m_VariableController; TimeController m_TimeController; NetworkController m_NetworkController; CatalogueController m_CatalogueController; - QThread m_DataSourceControllerThread; QThread m_NetworkControllerThread; DragDropGuiController m_DragDropGuiController; @@ -77,17 +73,11 @@ SqpApplication::SqpApplication(int& argc, char** argv) QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - connect(&impl->m_DataSourceControllerThread, &QThread::started, &impl->m_DataSourceController, - &DataSourceController::initialize); - connect(&impl->m_DataSourceControllerThread, &QThread::finished, &impl->m_DataSourceController, - &DataSourceController::finalize); - connect(&impl->m_NetworkControllerThread, &QThread::started, &impl->m_NetworkController, &NetworkController::initialize); connect(&impl->m_NetworkControllerThread, &QThread::finished, &impl->m_NetworkController, &NetworkController::finalize); - impl->m_DataSourceControllerThread.start(); impl->m_NetworkControllerThread.start(); } @@ -95,9 +85,14 @@ SqpApplication::~SqpApplication() {} void SqpApplication::initialize() {} -DataSourceController& SqpApplication::dataSourceController() noexcept +//DataSourceController& SqpApplication::dataSourceController() noexcept +//{ +// return impl->m_DataSourceController; +//} + +DataSources& SqpApplication::dataSources() noexcept { - return impl->m_DataSourceController; + return impl->m_DataSources; } NetworkController& SqpApplication::networkController() noexcept diff --git a/gui/src/TimeWidget/TimeWidget.cpp b/gui/src/TimeWidget/TimeWidget.cpp index 9b3e69d..aa2627e 100644 --- a/gui/src/TimeWidget/TimeWidget.cpp +++ b/gui/src/TimeWidget/TimeWidget.cpp @@ -2,7 +2,7 @@ #include "ui_TimeWidget.h" #include -#include +#include #include #include @@ -80,7 +80,7 @@ void TimeWidget::onTimeUpdateRequested() void TimeWidget::dragEnterEvent(QDragEnterEvent* event) { - if (event->mimeData()->hasFormat(MIME_TYPE_TIME_RANGE)) + if (event->mimeData()->hasFormat(MIME::MIME_TYPE_TIME_RANGE)) { event->acceptProposedAction(); setStyleSheet("QDateTimeEdit{background-color: #BBD5EE; border:2px solid #2A7FD4}"); @@ -98,9 +98,9 @@ void TimeWidget::dragLeaveEvent(QDragLeaveEvent* event) void TimeWidget::dropEvent(QDropEvent* event) { - if (event->mimeData()->hasFormat(MIME_TYPE_TIME_RANGE)) + if (event->mimeData()->hasFormat(MIME::MIME_TYPE_TIME_RANGE)) { - auto mimeData = event->mimeData()->data(MIME_TYPE_TIME_RANGE); + auto mimeData = event->mimeData()->data(MIME::MIME_TYPE_TIME_RANGE); auto timeRange = TimeController::timeRangeForMimeData(mimeData); setTimeRange(timeRange); @@ -142,7 +142,7 @@ void TimeWidget::mouseMoveEvent(QMouseEvent* event) auto mimeData = new QMimeData; auto timeData = TimeController::mimeDataForTimeRange(timeRange()); - mimeData->setData(MIME_TYPE_TIME_RANGE, timeData); + mimeData->setData(MIME::MIME_TYPE_TIME_RANGE, timeData); drag->setMimeData(mimeData); diff --git a/gui/src/Variable/VariableInspectorWidget.cpp b/gui/src/Variable/VariableInspectorWidget.cpp index ac45b4e..8f969b4 100644 --- a/gui/src/Variable/VariableInspectorWidget.cpp +++ b/gui/src/Variable/VariableInspectorWidget.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -139,8 +139,8 @@ VariableInspectorWidget::VariableInspectorWidget(QWidget* parent) m_model = new VariableModel2(); ui->tableView->setModel(m_model); - connect(m_model, &VariableModel2::createVariable, [](const QVariantHash& productData) { - sqpApp->dataSourceController().requestVariable(productData); + connect(m_model, &VariableModel2::createVariable, [](const QString& productPath) { + sqpApp->dataSources().createVariable(productPath); }); auto vc = &(sqpApp->variableController()); connect(vc, &VariableController2::variableAdded, m_model, &VariableModel2::variableAdded); diff --git a/gui/src/Visualization/VisualizationGraphWidget.cpp b/gui/src/Visualization/VisualizationGraphWidget.cpp index 05ef611..0426a3a 100644 --- a/gui/src/Visualization/VisualizationGraphWidget.cpp +++ b/gui/src/Visualization/VisualizationGraphWidget.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include #include @@ -731,17 +731,17 @@ QMimeData* VisualizationGraphWidget::mimeData(const QPoint& position) const if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones && selectionZoneItemUnderCursor) { - mimeData->setData(MIME_TYPE_TIME_RANGE, + mimeData->setData(MIME::MIME_TYPE_TIME_RANGE, TimeController::mimeDataForTimeRange(selectionZoneItemUnderCursor->range())); - mimeData->setData(MIME_TYPE_SELECTION_ZONE, + mimeData->setData(MIME::MIME_TYPE_SELECTION_ZONE, TimeController::mimeDataForTimeRange(selectionZoneItemUnderCursor->range())); } else { - mimeData->setData(MIME_TYPE_GRAPH, QByteArray {}); + mimeData->setData(MIME::MIME_TYPE_GRAPH, QByteArray {}); auto timeRangeData = TimeController::mimeDataForTimeRange(graphRange()); - mimeData->setData(MIME_TYPE_TIME_RANGE, timeRangeData); + mimeData->setData(MIME::MIME_TYPE_TIME_RANGE, timeRangeData); } return mimeData; diff --git a/gui/src/Visualization/VisualizationTabWidget.cpp b/gui/src/Visualization/VisualizationTabWidget.cpp index 1c094cc..af9190f 100644 --- a/gui/src/Visualization/VisualizationTabWidget.cpp +++ b/gui/src/Visualization/VisualizationTabWidget.cpp @@ -7,10 +7,10 @@ #include "Visualization/MacScrollBarStyle.h" -#include "DataSource/DataSourceController.h" +#include "DataSource/datasources.h" #include "Variable/VariableController2.h" -#include "Common/MimeTypesDef.h" +#include "MimeTypes/MimeTypes.h" #include "DragAndDrop/DragDropGuiController.h" #include "SqpApplication.h" @@ -95,13 +95,13 @@ VisualizationTabWidget::VisualizationTabWidget(const QString& name, QWidget* par ui->dragDropContainer->layout()->setContentsMargins(0, 0, 0, 12); ui->dragDropContainer->layout()->setSpacing(0); ui->dragDropContainer->setMimeType( - MIME_TYPE_GRAPH, VisualizationDragDropContainer::DropBehavior::Inserted); + MIME::MIME_TYPE_GRAPH, VisualizationDragDropContainer::DropBehavior::Inserted); ui->dragDropContainer->setMimeType( - MIME_TYPE_ZONE, VisualizationDragDropContainer::DropBehavior::Inserted); + MIME::MIME_TYPE_ZONE, VisualizationDragDropContainer::DropBehavior::Inserted); ui->dragDropContainer->setMimeType( - MIME_TYPE_VARIABLE_LIST, VisualizationDragDropContainer::DropBehavior::Inserted); + MIME::MIME_TYPE_VARIABLE_LIST, VisualizationDragDropContainer::DropBehavior::Inserted); ui->dragDropContainer->setMimeType( - MIME_TYPE_PRODUCT_LIST, VisualizationDragDropContainer::DropBehavior::Inserted); + MIME::MIME_TYPE_PRODUCT_LIST, VisualizationDragDropContainer::DropBehavior::Inserted); ui->dragDropContainer->setAcceptMimeDataFunction([this](auto mimeData) { return sqpApp->dragDropGuiController().checkMimeDataForVisualization( @@ -231,24 +231,24 @@ QLayout& VisualizationTabWidget::tabLayout() const noexcept void VisualizationTabWidget::dropMimeData(int index, const QMimeData* mimeData) { - if (mimeData->hasFormat(MIME_TYPE_GRAPH)) + if (mimeData->hasFormat(MIME::MIME_TYPE_GRAPH)) { impl->dropGraph(index, this); } - else if (mimeData->hasFormat(MIME_TYPE_ZONE)) + else if (mimeData->hasFormat(MIME::MIME_TYPE_ZONE)) { impl->dropZone(index, this); } - else if (mimeData->hasFormat(MIME_TYPE_VARIABLE_LIST)) + else if (mimeData->hasFormat(MIME::MIME_TYPE_VARIABLE_LIST)) { auto variables = sqpApp->variableController().variables( - Variable2::IDs(mimeData->data(MIME_TYPE_VARIABLE_LIST))); + Variable2::IDs(mimeData->data(MIME::MIME_TYPE_VARIABLE_LIST))); impl->dropVariables(variables, index, this); } - else if (mimeData->hasFormat(MIME_TYPE_PRODUCT_LIST)) + else if (mimeData->hasFormat(MIME::MIME_TYPE_PRODUCT_LIST)) { - auto productsData = sqpApp->dataSourceController().productsDataForMimeData( - mimeData->data(MIME_TYPE_PRODUCT_LIST)); + auto productsData = MIME::decode( + mimeData->data(MIME::MIME_TYPE_PRODUCT_LIST)); impl->dropProducts(productsData, index, this); } else @@ -409,7 +409,7 @@ void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropProducts( }, Qt::QueuedConnection); - auto productData = productsMetaData.first().toHash(); - QMetaObject::invokeMethod(&sqpApp->dataSourceController(), "requestVariable", - Qt::QueuedConnection, Q_ARG(QVariantHash, productData)); + auto productPath = productsMetaData.first().toString(); + QMetaObject::invokeMethod(&sqpApp->dataSources(), "createVariable", + Qt::QueuedConnection, Q_ARG(QString, productPath)); } diff --git a/gui/src/Visualization/VisualizationZoneWidget.cpp b/gui/src/Visualization/VisualizationZoneWidget.cpp index be3ed75..b7f407c 100644 --- a/gui/src/Visualization/VisualizationZoneWidget.cpp +++ b/gui/src/Visualization/VisualizationZoneWidget.cpp @@ -6,12 +6,12 @@ #include "Visualization/VisualizationWidget.h" #include "ui_VisualizationZoneWidget.h" -#include "Common/MimeTypesDef.h" +#include "MimeTypes/MimeTypes.h" #include "Common/VisualizationDef.h" #include #include -#include +#include #include