##// END OF EJS Templates
Merge branch 'feature/PluginTreeItem' into develop
Alexandre Leroux -
r87:d88ff9772a05 merge
parent child
Show More
@@ -0,0 +1,32
1 #ifndef SCIQLOP_DATASOURCETREEWIDGETITEM_H
2 #define SCIQLOP_DATASOURCETREEWIDGETITEM_H
3
4 #include <Common/spimpl.h>
5
6 #include <QLoggingCategory>
7 #include <QTreeWidgetItem>
8
9 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem)
10
11 class DataSourceItem;
12
13 /**
14 * @brief The DataSourceTreeWidgetItem is the graphical representation of a data source item. It is
15 * intended to be displayed in a QTreeWidget.
16 * @sa DataSourceItem
17 */
18 class DataSourceTreeWidgetItem : public QTreeWidgetItem {
19 public:
20 explicit DataSourceTreeWidgetItem(const DataSourceItem *data, int type = Type);
21 explicit DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data,
22 int type = Type);
23
24 virtual QVariant data(int column, int role) const override;
25 virtual void setData(int column, int role, const QVariant &value) override;
26
27 private:
28 class DataSourceTreeWidgetItemPrivate;
29 spimpl::unique_impl_ptr<DataSourceTreeWidgetItemPrivate> impl;
30 };
31
32 #endif // SCIQLOP_DATASOURCETREEWIDGETITEM_H
@@ -0,0 +1,33
1 #ifndef SCIQLOP_DATASOURCEWIDGET_H
2 #define SCIQLOP_DATASOURCEWIDGET_H
3
4 #include <Common/spimpl.h>
5
6 #include <QWidget>
7
8 class DataSourceItem;
9
10 /**
11 * @brief The DataSourceWidget handles the graphical representation (as a tree) of the data sources
12 * attached to SciQlop.
13 */
14 class DataSourceWidget : public QWidget {
15 Q_OBJECT
16
17 public:
18 explicit DataSourceWidget(QWidget *parent = 0);
19
20 public slots:
21 /**
22 * Adds a data source. An item associated to the data source is created and then added to the
23 * representation tree
24 * @param dataSource the data source to add
25 */
26 void addDataSource(DataSourceItem &dataSource) noexcept;
27
28 private:
29 class DataSourceWidgetPrivate;
30 spimpl::unique_impl_ptr<DataSourceWidgetPrivate> impl;
31 };
32
33 #endif // SCIQLOP_DATASOURCEWIDGET_H
@@ -0,0 +1,68
1 #include <DataSource/DataSourceItem.h>
2 #include <DataSource/DataSourceTreeWidgetItem.h>
3
4 #include <SqpApplication.h>
5
6 Q_LOGGING_CATEGORY(LOG_DataSourceTreeWidgetItem, "DataSourceTreeWidgetItem")
7
8 namespace {
9
10 QIcon itemIcon(const DataSourceItem *dataSource)
11 {
12 if (dataSource) {
13 auto dataSourceType = dataSource->type();
14 switch (dataSourceType) {
15 case DataSourceItemType::NODE:
16 return sqpApp->style()->standardIcon(QStyle::SP_DirIcon);
17 case DataSourceItemType::PRODUCT:
18 return sqpApp->style()->standardIcon(QStyle::SP_FileIcon);
19 default:
20 // No action
21 break;
22 }
23 }
24
25 // Default cases
26 return QIcon{};
27 }
28
29 } // namespace
30
31 struct DataSourceTreeWidgetItem::DataSourceTreeWidgetItemPrivate {
32 explicit DataSourceTreeWidgetItemPrivate(const DataSourceItem *data) : m_Data{data} {}
33
34 /// Model used to retrieve data source information
35 const DataSourceItem *m_Data;
36 };
37
38 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(const DataSourceItem *data, int type)
39 : DataSourceTreeWidgetItem{nullptr, data, type}
40 {
41 }
42
43 DataSourceTreeWidgetItem::DataSourceTreeWidgetItem(QTreeWidget *parent, const DataSourceItem *data,
44 int type)
45 : QTreeWidgetItem{parent, type},
46 impl{spimpl::make_unique_impl<DataSourceTreeWidgetItemPrivate>(data)}
47 {
48 // Sets the icon depending on the data source
49 setIcon(0, itemIcon(impl->m_Data));
50 }
51
52 QVariant DataSourceTreeWidgetItem::data(int column, int role) const
53 {
54 if (role == Qt::DisplayRole) {
55 return (impl->m_Data) ? impl->m_Data->data(column) : QVariant{};
56 }
57 else {
58 return QTreeWidgetItem::data(column, role);
59 }
60 }
61
62 void DataSourceTreeWidgetItem::setData(int column, int role, const QVariant &value)
63 {
64 // Data can't be changed by edition
65 if (role != Qt::EditRole) {
66 QTreeWidgetItem::setData(column, role, value);
67 }
68 }
@@ -0,0 +1,61
1 #include <DataSource/DataSourceWidget.h>
2
3 #include <ui_DataSourceWidget.h>
4
5 #include <DataSource/DataSourceItem.h>
6 #include <DataSource/DataSourceTreeWidgetItem.h>
7
8 namespace {
9
10 /// Number of columns displayed in the tree
11 const auto TREE_NB_COLUMNS = 1;
12
13 /// Header labels for the tree
14 const auto TREE_HEADER_LABELS = QStringList{QObject::tr("Name")};
15
16 /**
17 * Creates the item associated to a data source
18 * @param dataSource the data source for which to create the item
19 * @return the new item
20 */
21 DataSourceTreeWidgetItem *createTreeWidgetItem(DataSourceItem *dataSource)
22 {
23 // Creates item for the data source
24 auto item = new DataSourceTreeWidgetItem{dataSource};
25
26 // Generates items for the children of the data source
27 for (auto i = 0; i < dataSource->childCount(); ++i) {
28 item->addChild(createTreeWidgetItem(dataSource->child(i)));
29 }
30
31 return item;
32 }
33
34 } // namespace
35
36 class DataSourceWidget::DataSourceWidgetPrivate {
37 public:
38 explicit DataSourceWidgetPrivate(DataSourceWidget &widget)
39 : m_Ui{std::make_unique<Ui::DataSourceWidget>()}
40 {
41 m_Ui->setupUi(&widget);
42
43 // Set tree properties
44 m_Ui->treeWidget->setColumnCount(TREE_NB_COLUMNS);
45 m_Ui->treeWidget->setHeaderLabels(TREE_HEADER_LABELS);
46 }
47
48 std::unique_ptr<Ui::DataSourceWidget> m_Ui;
49 };
50
51 DataSourceWidget::DataSourceWidget(QWidget *parent)
52 : QWidget{parent}, impl{spimpl::make_unique_impl<DataSourceWidgetPrivate>(*this)}
53 {
54 }
55
56 void DataSourceWidget::addDataSource(DataSourceItem &dataSource) noexcept
57 {
58 // Creates the item associated to the source and adds it to the tree widget. The tree widget
59 // takes the ownership of the item
60 impl->m_Ui->treeWidget->addTopLevelItem(createTreeWidgetItem(&dataSource));
61 }
@@ -0,0 +1,24
1 <?xml version="1.0" encoding="UTF-8"?>
2 <ui version="4.0">
3 <class>DataSourceWidget</class>
4 <widget class="QWidget" name="DataSourceWidget">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>400</width>
10 <height>300</height>
11 </rect>
12 </property>
13 <property name="windowTitle">
14 <string>Data sources</string>
15 </property>
16 <layout class="QGridLayout" name="gridLayout">
17 <item row="0" column="0">
18 <widget class="QTreeWidget" name="treeWidget"/>
19 </item>
20 </layout>
21 </widget>
22 <resources/>
23 <connections/>
24 </ui>
@@ -25,6 +25,16
25 25 #include <SqpApplication.h>
26 26 #include <qglobal.h>
27 27
28 #include <Plugin/PluginManager.h>
29 #include <QDir>
30
31 namespace {
32
33 /// Name of the directory containing the plugins
34 const auto PLUGIN_DIRECTORY_NAME = QStringLiteral("plugins");
35
36 } // namespace
37
28 38 int main(int argc, char *argv[])
29 39 {
30 40 SqpApplication a{argc, argv};
@@ -34,5 +44,16 int main(int argc, char *argv[])
34 44 MainWindow w;
35 45 w.show();
36 46
47 // Loads plugins
48 auto pluginDir = QDir{sqpApp->applicationDirPath()};
49 pluginDir.mkdir(PLUGIN_DIRECTORY_NAME);
50 pluginDir.cd(PLUGIN_DIRECTORY_NAME);
51
52 qCDebug(LOG_PluginManager())
53 << QObject::tr("Plugin directory: %1").arg(pluginDir.absolutePath());
54
55 PluginManager pluginManager{};
56 pluginManager.loadPlugins(pluginDir);
57
37 58 return a.exec();
38 59 }
@@ -21,6 +21,11
21 21 ----------------------------------------------------------------------------*/
22 22 #include "MainWindow.h"
23 23 #include "ui_MainWindow.h"
24
25 #include <DataSource/DataSourceController.h>
26 #include <DataSource/DataSourceWidget.h>
27 #include <SqpApplication.h>
28
24 29 #include <QAction>
25 30 #include <QDate>
26 31 #include <QDateTime>
@@ -57,6 +62,11 MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_Ui(new Ui::Main
57 62 this->menuBar()->addAction("File");
58 63 auto mainToolBar = this->addToolBar("MainToolBar");
59 64 mainToolBar->addAction("A1");
65
66 // Widgets / controllers connections
67 connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem &)),
68 m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem &)));
69
60 70 /* QLopGUI::registerMenuBar(menuBar());
61 71 this->setWindowIcon(QIcon(":/sciqlopLOGO.svg"));
62 72 this->m_progressWidget = new QWidget();
@@ -85,7 +85,7
85 85 <number>0</number>
86 86 </property>
87 87 <item>
88 <widget class="QWidget" name="dateSourceWidget" native="true"/>
88 <widget class="DataSourceWidget" name="dataSourceWidget" native="true"/>
89 89 </item>
90 90 <item>
91 91 <widget class="QWidget" name="dateTimeWidget" native="true"/>
@@ -202,6 +202,12
202 202 <header location="global">sidepane/SqpSidePane.h</header>
203 203 <container>1</container>
204 204 </customwidget>
205 <customwidget>
206 <class>DataSourceWidget</class>
207 <extends>QWidget</extends>
208 <header location="global">DataSource/DataSourceWidget.h</header>
209 <container>1</container>
210 </customwidget>
205 211 </customwidgets>
206 212 <resources/>
207 213 <connections/>
@@ -49,7 +49,7 public slots:
49 49
50 50 signals:
51 51 /// Signal emitted when a structure has been set for a data source
52 void dataSourceItemSet(const DataSourceItem &dataSourceItem);
52 void dataSourceItemSet(DataSourceItem &dataSourceItem);
53 53
54 54 private:
55 55 void waitForFinish();
@@ -7,6 +7,11
7 7 #include <QVector>
8 8
9 9 /**
10 * Possible types of an item
11 */
12 enum class DataSourceItemType { NODE, PRODUCT };
13
14 /**
10 15 * @brief The DataSourceItem class aims to represent a structure element of a data source.
11 16 * A data source has a tree structure that is made up of a main DataSourceItem object (root)
12 17 * containing other DataSourceItem objects (children).
@@ -14,7 +19,7
14 19 */
15 20 class DataSourceItem {
16 21 public:
17 explicit DataSourceItem(QVector<QVariant> data = {});
22 explicit DataSourceItem(DataSourceItemType type, QVector<QVariant> data = {});
18 23
19 24 /**
20 25 * Adds a child to the item. The item takes ownership of the child.
@@ -44,6 +49,8 public:
44 49 */
45 50 DataSourceItem *parentItem() const noexcept;
46 51
52 DataSourceItemType type() const noexcept;
53
47 54 private:
48 55 class DataSourceItemPrivate;
49 56 spimpl::unique_impl_ptr<DataSourceItemPrivate> impl;
@@ -3,18 +3,19
3 3 #include <QVector>
4 4
5 5 struct DataSourceItem::DataSourceItemPrivate {
6 explicit DataSourceItemPrivate(QVector<QVariant> data)
7 : m_Parent{nullptr}, m_Children{}, m_Data{std::move(data)}
6 explicit DataSourceItemPrivate(DataSourceItemType type, QVector<QVariant> data)
7 : m_Parent{nullptr}, m_Children{}, m_Type{type}, m_Data{std::move(data)}
8 8 {
9 9 }
10 10
11 11 DataSourceItem *m_Parent;
12 12 std::vector<std::unique_ptr<DataSourceItem> > m_Children;
13 DataSourceItemType m_Type;
13 14 QVector<QVariant> m_Data;
14 15 };
15 16
16 DataSourceItem::DataSourceItem(QVector<QVariant> data)
17 : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(data)}
17 DataSourceItem::DataSourceItem(DataSourceItemType type, QVector<QVariant> data)
18 : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(type, std::move(data))}
18 19 {
19 20 }
20 21
@@ -48,3 +49,8 DataSourceItem *DataSourceItem::parentItem() const noexcept
48 49 {
49 50 return impl->m_Parent;
50 51 }
52
53 DataSourceItemType DataSourceItem::type() const noexcept
54 {
55 return impl->m_Type;
56 }
@@ -31,7 +31,8 void TestDataSourceController::testSetDataSourceItem()
31 31 // Create a data source item
32 32 auto source1Name = QStringLiteral("Source1");
33 33 auto source1Values = QVector<QVariant>{source1Name};
34 auto source1Item = std::make_unique<DataSourceItem>(std::move(source1Values));
34 auto source1Item
35 = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT, std::move(source1Values));
35 36
36 37 // Add data source item to the controller and check that a signal has been emitted after setting
37 38 // data source item in the controller
@@ -41,7 +42,8 void TestDataSourceController::testSetDataSourceItem()
41 42
42 43 // Try to a data source item with an unregistered uid and check that no signal has been emitted
43 44 auto unregisteredUid = QUuid::createUuid();
44 dataSourceController.setDataSourceItem(unregisteredUid, std::make_unique<DataSourceItem>());
45 dataSourceController.setDataSourceItem(
46 unregisteredUid, std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT));
45 47 QCOMPARE(signalSpy.count(), 1);
46 48 }
47 49
@@ -1,3 +1,6
1 1 # On ignore toutes les règles vera++ pour le fichier spimpl
2 2 Common/spimpl\.h:\d+:.*
3 3
4 # Ignore false positive relative to two class definitions in a same file
5 DataSourceItem\.h:\d+:.*IPSIS_S01.*
6
@@ -6,3 +6,7
6 6 # Ignore false positive relative to 'noexcept' keyword
7 7 .*IPSIS_S04_VARIABLE.*found: noexcept
8 8 .*IPSIS_S06.*found: noexcept
9
10 # Ignore false positive relative to 'override' keyword
11 .*IPSIS_S04_VARIABLE.*found: override
12 .*IPSIS_S06.*found: override
@@ -1,8 +1,11
1 # Ignore false positive relative to App macro
2 1 \.h:\d+:.IPSIS_S04.*found: ui
3 2 qcustomplot\.h:\d+:.IPSIS
4 3 qcustomplot\.cpp:\d+:.IPSIS
4
5 # Ignore false positive relative to App macro
5 6 SqpApplication\.h:\d+:.IPSIS_S03.*found: sqpApp
6 7 SqpApplication\.h:\d+:.IPSIS_S04_VARIABLE.*found: sqpApp
7 8
9 # Ignore false positive relative to unnamed namespace
10 DataSourceTreeWidgetItem\.cpp:\d+:.*IPSIS_F13.*
8 11
General Comments 0
You need to be logged in to leave comments. Login now