@@ -1,94 +1,101 | |||||
1 | #include "Visualization/VisualizationZoneWidget.h" |
|
1 | #include "Visualization/VisualizationZoneWidget.h" | |
2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
2 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
3 | #include "ui_VisualizationZoneWidget.h" |
|
3 | #include "ui_VisualizationZoneWidget.h" | |
4 |
|
4 | |||
5 | #include "Visualization/VisualizationGraphWidget.h" |
|
5 | #include "Visualization/VisualizationGraphWidget.h" | |
6 |
|
6 | |||
|
7 | #include <SqpApplication.h> | |||
|
8 | ||||
7 | Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget") |
|
9 | Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget") | |
8 |
|
10 | |||
9 | namespace { |
|
11 | namespace { | |
10 |
|
12 | |||
11 | /// Generates a default name for a new graph, according to the number of graphs already displayed in |
|
13 | /// Generates a default name for a new graph, according to the number of graphs already displayed in | |
12 | /// the zone |
|
14 | /// the zone | |
13 | QString defaultGraphName(const QLayout &layout) |
|
15 | QString defaultGraphName(const QLayout &layout) | |
14 | { |
|
16 | { | |
15 | auto count = 0; |
|
17 | auto count = 0; | |
16 | for (auto i = 0; i < layout.count(); ++i) { |
|
18 | for (auto i = 0; i < layout.count(); ++i) { | |
17 | if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) { |
|
19 | if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) { | |
18 | count++; |
|
20 | count++; | |
19 | } |
|
21 | } | |
20 | } |
|
22 | } | |
21 |
|
23 | |||
22 | return QObject::tr("Graph %1").arg(count + 1); |
|
24 | return QObject::tr("Graph %1").arg(count + 1); | |
23 | } |
|
25 | } | |
24 |
|
26 | |||
25 | } // namespace |
|
27 | } // namespace | |
26 |
|
28 | |||
27 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) |
|
29 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) | |
28 | : QWidget{parent}, ui{new Ui::VisualizationZoneWidget} |
|
30 | : QWidget{parent}, ui{new Ui::VisualizationZoneWidget} | |
29 | { |
|
31 | { | |
30 | ui->setupUi(this); |
|
32 | ui->setupUi(this); | |
31 |
|
33 | |||
32 | ui->zoneNameLabel->setText(name); |
|
34 | ui->zoneNameLabel->setText(name); | |
|
35 | ||||
|
36 | // 'Close' options : widget is deleted when closed | |||
|
37 | setAttribute(Qt::WA_DeleteOnClose); | |||
|
38 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close); | |||
|
39 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); | |||
33 | } |
|
40 | } | |
34 |
|
41 | |||
35 | VisualizationZoneWidget::~VisualizationZoneWidget() |
|
42 | VisualizationZoneWidget::~VisualizationZoneWidget() | |
36 | { |
|
43 | { | |
37 | delete ui; |
|
44 | delete ui; | |
38 | } |
|
45 | } | |
39 |
|
46 | |||
40 | void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) |
|
47 | void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) | |
41 | { |
|
48 | { | |
42 | ui->visualizationZoneFrame->layout()->addWidget(graphWidget); |
|
49 | ui->visualizationZoneFrame->layout()->addWidget(graphWidget); | |
43 | } |
|
50 | } | |
44 |
|
51 | |||
45 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable) |
|
52 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable) | |
46 | { |
|
53 | { | |
47 | auto graphWidget = new VisualizationGraphWidget{ |
|
54 | auto graphWidget = new VisualizationGraphWidget{ | |
48 | defaultGraphName(*ui->visualizationZoneFrame->layout()), this}; |
|
55 | defaultGraphName(*ui->visualizationZoneFrame->layout()), this}; | |
49 | this->addGraph(graphWidget); |
|
56 | this->addGraph(graphWidget); | |
50 |
|
57 | |||
51 | graphWidget->addVariable(variable); |
|
58 | graphWidget->addVariable(variable); | |
52 |
|
59 | |||
53 | return graphWidget; |
|
60 | return graphWidget; | |
54 | } |
|
61 | } | |
55 |
|
62 | |||
56 | void VisualizationZoneWidget::removeGraph(VisualizationGraphWidget *graph) |
|
63 | void VisualizationZoneWidget::removeGraph(VisualizationGraphWidget *graph) | |
57 | { |
|
64 | { | |
58 | } |
|
65 | } | |
59 |
|
66 | |||
60 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
67 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) | |
61 | { |
|
68 | { | |
62 | if (visitor) { |
|
69 | if (visitor) { | |
63 | visitor->visitEnter(this); |
|
70 | visitor->visitEnter(this); | |
64 |
|
71 | |||
65 | // Apply visitor to graph children |
|
72 | // Apply visitor to graph children | |
66 | auto layout = ui->visualizationZoneFrame->layout(); |
|
73 | auto layout = ui->visualizationZoneFrame->layout(); | |
67 | for (auto i = 0; i < layout->count(); ++i) { |
|
74 | for (auto i = 0; i < layout->count(); ++i) { | |
68 | if (auto item = layout->itemAt(i)) { |
|
75 | if (auto item = layout->itemAt(i)) { | |
69 | // Widgets different from graphs are not visited (no action) |
|
76 | // Widgets different from graphs are not visited (no action) | |
70 | if (auto visualizationGraphWidget |
|
77 | if (auto visualizationGraphWidget | |
71 | = dynamic_cast<VisualizationGraphWidget *>(item->widget())) { |
|
78 | = dynamic_cast<VisualizationGraphWidget *>(item->widget())) { | |
72 | visualizationGraphWidget->accept(visitor); |
|
79 | visualizationGraphWidget->accept(visitor); | |
73 | } |
|
80 | } | |
74 | } |
|
81 | } | |
75 | } |
|
82 | } | |
76 |
|
83 | |||
77 | visitor->visitLeave(this); |
|
84 | visitor->visitLeave(this); | |
78 | } |
|
85 | } | |
79 | else { |
|
86 | else { | |
80 | qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null"); |
|
87 | qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null"); | |
81 | } |
|
88 | } | |
82 | } |
|
89 | } | |
83 |
|
90 | |||
84 | bool VisualizationZoneWidget::canDrop(const Variable &variable) const |
|
91 | bool VisualizationZoneWidget::canDrop(const Variable &variable) const | |
85 | { |
|
92 | { | |
86 | // A tab can always accomodate a variable |
|
93 | // A tab can always accomodate a variable | |
87 | Q_UNUSED(variable); |
|
94 | Q_UNUSED(variable); | |
88 | return true; |
|
95 | return true; | |
89 | } |
|
96 | } | |
90 |
|
97 | |||
91 | QString VisualizationZoneWidget::name() const |
|
98 | QString VisualizationZoneWidget::name() const | |
92 | { |
|
99 | { | |
93 | return ui->zoneNameLabel->text(); |
|
100 | return ui->zoneNameLabel->text(); | |
94 | } |
|
101 | } |
@@ -1,76 +1,86 | |||||
1 | <?xml version="1.0" encoding="UTF-8"?> |
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |
2 | <ui version="4.0"> |
|
2 | <ui version="4.0"> | |
3 | <class>VisualizationZoneWidget</class> |
|
3 | <class>VisualizationZoneWidget</class> | |
4 | <widget class="QWidget" name="VisualizationZoneWidget"> |
|
4 | <widget class="QWidget" name="VisualizationZoneWidget"> | |
5 | <property name="geometry"> |
|
5 | <property name="geometry"> | |
6 | <rect> |
|
6 | <rect> | |
7 | <x>0</x> |
|
7 | <x>0</x> | |
8 | <y>0</y> |
|
8 | <y>0</y> | |
9 | <width>400</width> |
|
9 | <width>400</width> | |
10 | <height>300</height> |
|
10 | <height>300</height> | |
11 | </rect> |
|
11 | </rect> | |
12 | </property> |
|
12 | </property> | |
13 | <property name="windowTitle"> |
|
13 | <property name="windowTitle"> | |
14 | <string>Form</string> |
|
14 | <string>Form</string> | |
15 | </property> |
|
15 | </property> | |
16 | <layout class="QVBoxLayout" name="verticalLayout_2"> |
|
16 | <layout class="QVBoxLayout" name="verticalLayout_2"> | |
17 | <item> |
|
17 | <item> | |
18 | <widget class="QWidget" name="infobar" native="true"> |
|
18 | <widget class="QWidget" name="infobar" native="true"> | |
19 | <property name="sizePolicy"> |
|
19 | <property name="sizePolicy"> | |
20 | <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> |
|
20 | <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> | |
21 | <horstretch>0</horstretch> |
|
21 | <horstretch>0</horstretch> | |
22 | <verstretch>0</verstretch> |
|
22 | <verstretch>0</verstretch> | |
23 | </sizepolicy> |
|
23 | </sizepolicy> | |
24 | </property> |
|
24 | </property> | |
25 | <layout class="QHBoxLayout" name="horizontalLayout"> |
|
25 | <layout class="QHBoxLayout" name="horizontalLayout"> | |
26 | <property name="leftMargin"> |
|
26 | <property name="leftMargin"> | |
27 | <number>0</number> |
|
27 | <number>0</number> | |
28 | </property> |
|
28 | </property> | |
29 | <property name="topMargin"> |
|
29 | <property name="topMargin"> | |
30 | <number>0</number> |
|
30 | <number>0</number> | |
31 | </property> |
|
31 | </property> | |
32 | <property name="rightMargin"> |
|
32 | <property name="rightMargin"> | |
33 | <number>0</number> |
|
33 | <number>0</number> | |
34 | </property> |
|
34 | </property> | |
35 | <property name="bottomMargin"> |
|
35 | <property name="bottomMargin"> | |
36 | <number>0</number> |
|
36 | <number>0</number> | |
37 | </property> |
|
37 | </property> | |
38 | <item> |
|
38 | <item> | |
39 | <widget class="QLabel" name="zoneNameLabel"> |
|
39 | <widget class="QLabel" name="zoneNameLabel"> | |
40 | <property name="styleSheet"> |
|
40 | <property name="styleSheet"> | |
41 | <string notr="true">color: rgb(127, 127, 127); |
|
41 | <string notr="true">color: rgb(127, 127, 127); | |
42 | </string> |
|
42 | </string> | |
43 | </property> |
|
43 | </property> | |
44 | <property name="text"> |
|
44 | <property name="text"> | |
45 | <string>TextLabel</string> |
|
45 | <string>TextLabel</string> | |
46 | </property> |
|
46 | </property> | |
47 | </widget> |
|
47 | </widget> | |
48 | </item> |
|
48 | </item> | |
|
49 | <item> | |||
|
50 | <widget class="QToolButton" name="closeButton"> | |||
|
51 | <property name="styleSheet"> | |||
|
52 | <string notr="true">background-color: transparent;</string> | |||
|
53 | </property> | |||
|
54 | <property name="text"> | |||
|
55 | <string>Close</string> | |||
|
56 | </property> | |||
|
57 | </widget> | |||
|
58 | </item> | |||
49 | </layout> |
|
59 | </layout> | |
50 | </widget> |
|
60 | </widget> | |
51 | </item> |
|
61 | </item> | |
52 | <item> |
|
62 | <item> | |
53 | <widget class="QFrame" name="visualizationZoneFrame"> |
|
63 | <widget class="QFrame" name="visualizationZoneFrame"> | |
54 | <property name="sizePolicy"> |
|
64 | <property name="sizePolicy"> | |
55 | <sizepolicy hsizetype="Preferred" vsizetype="Expanding"> |
|
65 | <sizepolicy hsizetype="Preferred" vsizetype="Expanding"> | |
56 | <horstretch>0</horstretch> |
|
66 | <horstretch>0</horstretch> | |
57 | <verstretch>0</verstretch> |
|
67 | <verstretch>0</verstretch> | |
58 | </sizepolicy> |
|
68 | </sizepolicy> | |
59 | </property> |
|
69 | </property> | |
60 | <property name="frameShape"> |
|
70 | <property name="frameShape"> | |
61 | <enum>QFrame::Box</enum> |
|
71 | <enum>QFrame::Box</enum> | |
62 | </property> |
|
72 | </property> | |
63 | <property name="frameShadow"> |
|
73 | <property name="frameShadow"> | |
64 | <enum>QFrame::Raised</enum> |
|
74 | <enum>QFrame::Raised</enum> | |
65 | </property> |
|
75 | </property> | |
66 | <property name="lineWidth"> |
|
76 | <property name="lineWidth"> | |
67 | <number>1</number> |
|
77 | <number>1</number> | |
68 | </property> |
|
78 | </property> | |
69 | <layout class="QVBoxLayout" name="verticalLayout"/> |
|
79 | <layout class="QVBoxLayout" name="verticalLayout"/> | |
70 | </widget> |
|
80 | </widget> | |
71 | </item> |
|
81 | </item> | |
72 | </layout> |
|
82 | </layout> | |
73 | </widget> |
|
83 | </widget> | |
74 | <resources/> |
|
84 | <resources/> | |
75 | <connections/> |
|
85 | <connections/> | |
76 | </ui> |
|
86 | </ui> |
General Comments 0
You need to be logged in to leave comments.
Login now