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