##// END OF EJS Templates
Merge branch 'feature/WidgetsNames' into develop
Alexandre Leroux -
r204:418c600ae7b7 merge
parent child
Show More
@@ -19,7 +19,7 class VisualizationGraphWidget : public QWidget, public IVisualizationWidget {
19 19 Q_OBJECT
20 20
21 21 public:
22 explicit VisualizationGraphWidget(QWidget *parent = 0);
22 explicit VisualizationGraphWidget(const QString name = {}, QWidget *parent = 0);
23 23 virtual ~VisualizationGraphWidget();
24 24
25 25 void addVariable(std::shared_ptr<Variable> variable);
@@ -3,8 +3,11
3 3
4 4 #include "Visualization/IVisualizationWidget.h"
5 5
6 #include <Common/spimpl.h>
7
6 8 #include <QWidget>
7 9
10 class Variable;
8 11 class VisualizationZoneWidget;
9 12
10 13 namespace Ui {
@@ -15,14 +18,19 class VisualizationTabWidget : public QWidget, public IVisualizationWidget {
15 18 Q_OBJECT
16 19
17 20 public:
18 explicit VisualizationTabWidget(QWidget *parent = 0);
21 explicit VisualizationTabWidget(const QString &name = {}, QWidget *parent = 0);
19 22 virtual ~VisualizationTabWidget();
20 23
21 24 /// Add a zone widget
22 25 void addZone(VisualizationZoneWidget *zoneWidget);
23 26
24 /// Create a zone using a Variable
25 VisualizationZoneWidget *createZone();
27 /**
28 * Creates a zone using a variable. The variable will be displayed in a new graph of the new
29 * zone.
30 * @param variable the variable for which to create the zone
31 * @return the pointer to the created zone
32 */
33 VisualizationZoneWidget *createZone(std::shared_ptr<Variable> variable);
26 34
27 35 /// Remove a zone
28 36 void removeZone(VisualizationZoneWidget *zone);
@@ -34,6 +42,9 public:
34 42
35 43 private:
36 44 Ui::VisualizationTabWidget *ui;
45
46 class VisualizationTabWidgetPrivate;
47 spimpl::unique_impl_ptr<VisualizationTabWidgetPrivate> impl;
37 48 };
38 49
39 50 #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H
@@ -3,26 +3,31
3 3
4 4 #include "Visualization/IVisualizationWidget.h"
5 5
6 class VisualizationGraphWidget;
7
8 6 #include <QWidget>
9 7
10 8 namespace Ui {
11 9 class VisualizationZoneWidget;
12 10 } // Ui
13 11
12 class Variable;
13 class VisualizationGraphWidget;
14
14 15 class VisualizationZoneWidget : public QWidget, public IVisualizationWidget {
15 16 Q_OBJECT
16 17
17 18 public:
18 explicit VisualizationZoneWidget(QWidget *parent = 0);
19 explicit VisualizationZoneWidget(const QString &name = {}, QWidget *parent = 0);
19 20 virtual ~VisualizationZoneWidget();
20 21
21 22 /// Add a graph widget
22 23 void addGraph(VisualizationGraphWidget *graphWidget);
23 24
24 /// Create a graph using a Variable
25 VisualizationGraphWidget *createGraph();
25 /**
26 * Creates a graph using a variable. The variable will be displayed in the new graph.
27 * @param variable the variable for which to create the graph
28 * @return the pointer to the created graph
29 */
30 VisualizationGraphWidget *createGraph(std::shared_ptr<Variable> variable);
26 31
27 32 /// Remove a graph
28 33 void removeGraph(VisualizationGraphWidget *graph);
@@ -22,13 +22,17 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
22 22 std::unordered_map<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMap;
23 23 };
24 24
25 VisualizationGraphWidget::VisualizationGraphWidget(QWidget *parent)
25 VisualizationGraphWidget::VisualizationGraphWidget(const QString name, QWidget *parent)
26 26 : QWidget{parent},
27 27 ui{new Ui::VisualizationGraphWidget},
28 28 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
29 29 {
30 30 ui->setupUi(this);
31 31
32 // qcpplot title
33 ui->widget->plotLayout()->insertRow(0);
34 ui->widget->plotLayout()->addElement(0, 0, new QCPTextElement{ui->widget, name});
35
32 36 // Set qcpplot properties :
33 37 // - Drag (on x-axis) and zoom are enabled
34 38 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
@@ -65,7 +69,12 void VisualizationGraphWidget::close()
65 69
66 70 QString VisualizationGraphWidget::name() const
67 71 {
68 return QStringLiteral("MainView");
72 if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) {
73 return title->text();
74 }
75 else {
76 return QString{};
77 }
69 78 }
70 79
71 80 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
@@ -3,9 +3,34
3 3
4 4 #include "Visualization/VisualizationZoneWidget.h"
5 5
6 namespace {
6 7
7 VisualizationTabWidget::VisualizationTabWidget(QWidget *parent)
8 : QWidget{parent}, ui{new Ui::VisualizationTabWidget}
8 /// Generates a default name for a new zone, according to the number of zones already displayed in
9 /// the tab
10 QString defaultZoneName(const QLayout &layout)
11 {
12 auto count = 0;
13 for (auto i = 0; i < layout.count(); ++i) {
14 if (dynamic_cast<VisualizationZoneWidget *>(layout.itemAt(i)->widget())) {
15 count++;
16 }
17 }
18
19 return QObject::tr("Zone %1").arg(count + 1);
20 }
21
22 } // namespace
23
24 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
25 explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {}
26
27 QString m_Name;
28 };
29
30 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent)
31 : QWidget{parent},
32 ui{new Ui::VisualizationTabWidget},
33 impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)}
9 34 {
10 35 ui->setupUi(this);
11 36 }
@@ -20,11 +45,14 void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget)
20 45 this->layout()->addWidget(zoneWidget);
21 46 }
22 47
23 VisualizationZoneWidget *VisualizationTabWidget::createZone()
48 VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable)
24 49 {
25 auto zoneWidget = new VisualizationZoneWidget{this};
50 auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*layout()), this};
26 51 this->addZone(zoneWidget);
27 52
53 // Creates a new graph into the zone
54 zoneWidget->createGraph(variable);
55
28 56 return zoneWidget;
29 57 }
30 58
@@ -45,5 +73,5 void VisualizationTabWidget::close()
45 73
46 74 QString VisualizationTabWidget::name() const
47 75 {
48 return QStringLiteral("MainView");
76 return impl->m_Name;
49 77 }
@@ -32,8 +32,9 VisualizationWidget::VisualizationWidget(QWidget *parent)
32 32 };
33 33
34 34 auto addTabView = [this, enableMinimumCornerWidgetSize]() {
35 auto index = ui->tabWidget->addTab(new VisualizationTabWidget(ui->tabWidget),
36 QString("View %1").arg(ui->tabWidget->count() + 1));
35 auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1),
36 ui->tabWidget};
37 auto index = ui->tabWidget->addTab(widget, widget->name());
37 38 if (ui->tabWidget->count() > 0) {
38 39 enableMinimumCornerWidgetSize(false);
39 40 }
@@ -54,6 +55,9 VisualizationWidget::VisualizationWidget(QWidget *parent)
54 55
55 56 connect(addTabViewButton, &QToolButton::clicked, addTabView);
56 57 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
58
59 // Adds default tab
60 addTabView();
57 61 }
58 62
59 63 VisualizationWidget::~VisualizationWidget()
@@ -96,16 +100,7 QString VisualizationWidget::name() const
96 100 void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept
97 101 {
98 102 if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) {
99 if (auto newZone = currentTab->createZone()) {
100 if (auto newGraph = newZone->createGraph()) {
101 newGraph->addVariable(variable);
102 }
103 else {
104 qCCritical(LOG_VisualizationWidget())
105 << tr("Can't display the variable : can't create the graph");
106 }
107 }
108 else {
103 if (!currentTab->createZone(variable)) {
109 104 qCCritical(LOG_VisualizationWidget())
110 105 << tr("Can't display the variable : can't create a new zone in the current tab");
111 106 }
@@ -3,10 +3,30
3 3
4 4 #include "Visualization/VisualizationGraphWidget.h"
5 5
6 VisualizationZoneWidget::VisualizationZoneWidget(QWidget *parent)
6 namespace {
7
8 /// Generates a default name for a new graph, according to the number of graphs already displayed in
9 /// the zone
10 QString defaultGraphName(const QLayout &layout)
11 {
12 auto count = 0;
13 for (auto i = 0; i < layout.count(); ++i) {
14 if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) {
15 count++;
16 }
17 }
18
19 return QObject::tr("Graph %1").arg(count + 1);
20 }
21
22 } // namespace
23
24 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
7 25 : QWidget{parent}, ui{new Ui::VisualizationZoneWidget}
8 26 {
9 27 ui->setupUi(this);
28
29 ui->zoneNameLabel->setText(name);
10 30 }
11 31
12 32 VisualizationZoneWidget::~VisualizationZoneWidget()
@@ -19,11 +39,14 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
19 39 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
20 40 }
21 41
22 VisualizationGraphWidget *VisualizationZoneWidget::createGraph()
42 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable)
23 43 {
24 auto graphWidget = new VisualizationGraphWidget{this};
44 auto graphWidget = new VisualizationGraphWidget{
45 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
25 46 this->addGraph(graphWidget);
26 47
48 graphWidget->addVariable(variable);
49
27 50 return graphWidget;
28 51 }
29 52
@@ -44,5 +67,5 void VisualizationZoneWidget::close()
44 67
45 68 QString VisualizationZoneWidget::name() const
46 69 {
47 return QStringLiteral("MainView");
70 return ui->zoneNameLabel->text();
48 71 }
@@ -17,25 +17,12
17 17 <item>
18 18 <widget class="QTabWidget" name="tabWidget">
19 19 <property name="currentIndex">
20 <number>0</number>
20 <number>-1</number>
21 21 </property>
22 <widget class="VisualizationTabWidget" name="firstView">
23 <attribute name="title">
24 <string>View 1</string>
25 </attribute>
26 </widget>
27 22 </widget>
28 23 </item>
29 24 </layout>
30 25 </widget>
31 <customwidgets>
32 <customwidget>
33 <class>VisualizationTabWidget</class>
34 <extends>QWidget</extends>
35 <header location="global">Visualization/VisualizationTabWidget.h</header>
36 <container>1</container>
37 </customwidget>
38 </customwidgets>
39 26 <resources/>
40 27 <connections/>
41 28 </ui>
@@ -14,23 +14,49
14 14 <string>Form</string>
15 15 </property>
16 16 <layout class="QVBoxLayout" name="verticalLayout_2">
17 <property name="spacing">
18 <number>3</number>
19 </property>
20 <property name="leftMargin">
21 <number>0</number>
22 </property>
23 <property name="topMargin">
24 <number>0</number>
25 </property>
26 <property name="rightMargin">
27 <number>0</number>
28 </property>
29 <property name="bottomMargin">
30 <number>0</number>
31 </property>
17 <item>
18 <widget class="QWidget" name="infobar" native="true">
19 <property name="sizePolicy">
20 <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
21 <horstretch>0</horstretch>
22 <verstretch>0</verstretch>
23 </sizepolicy>
24 </property>
25 <layout class="QHBoxLayout" name="horizontalLayout">
26 <property name="leftMargin">
27 <number>0</number>
28 </property>
29 <property name="topMargin">
30 <number>0</number>
31 </property>
32 <property name="rightMargin">
33 <number>0</number>
34 </property>
35 <property name="bottomMargin">
36 <number>0</number>
37 </property>
38 <item>
39 <widget class="QLabel" name="zoneNameLabel">
40 <property name="styleSheet">
41 <string notr="true">color: rgb(127, 127, 127);
42 </string>
43 </property>
44 <property name="text">
45 <string>TextLabel</string>
46 </property>
47 </widget>
48 </item>
49 </layout>
50 </widget>
51 </item>
32 52 <item>
33 53 <widget class="QFrame" name="visualizationZoneFrame">
54 <property name="sizePolicy">
55 <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
56 <horstretch>0</horstretch>
57 <verstretch>0</verstretch>
58 </sizepolicy>
59 </property>
34 60 <property name="frameShape">
35 61 <enum>QFrame::Box</enum>
36 62 </property>
@@ -8,4 +8,6 SqpApplication\.h:\d+:.IPSIS_S04_VARIABLE.*found: sqpApp
8 8
9 9 # Ignore false positive relative to unnamed namespace
10 10 DataSourceTreeWidgetItem\.cpp:\d+:.*IPSIS_F13.*
11 VisualizationTabWidget\.cpp:\d+:.*IPSIS_F13.*
12 VisualizationZoneWidget\.cpp:\d+:.*IPSIS_F13.*
11 13
General Comments 0
You need to be logged in to leave comments. Login now