Skip to content

Commit a1684cb

Browse files
committed
Refactoring code to new updates of QSimapleScada
1 parent 65e581e commit a1684cb

File tree

5 files changed

+229
-128
lines changed

5 files changed

+229
-128
lines changed

mainwindow.cpp

Lines changed: 4 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,13 @@ MainWindow::MainWindow(QWidget *parent) :
2323
mController = new QScadaBoardController();
2424
mController->initBoardForDeviceIp("127.0.0.0");
2525
mController->setEditingMode(true);
26+
mController->setParametersDialod(ui->widgetObjectParametrs);
2627

2728
mBoard = mController->getBoardListForDeviceIp("127.0.0.0").at(0);
28-
connect(mBoard, SIGNAL(objectSelected(QScadaObject *)), this, SLOT(updateObjectInfoDialog(QScadaObject *)));
2929

30+
//adding controller to central widget
3031
QGridLayout *mainLayout = new QGridLayout(ui->centralWidget);
31-
32-
connect(ui->widgetObjectParametrs, SIGNAL(deletePressed(QScadaObjectInfo*)), this, SLOT(deleteObject(QScadaObjectInfo *)));
33-
connect(ui->widgetObjectParametrs, SIGNAL(savePressed(QScadaObjectInfo*)), this, SLOT(updateSavedObject(QScadaObjectInfo *)));
34-
35-
mObjectInfoDialog = ui->widgetObjectParametrs;
36-
mainLayout->addWidget(mBoard);
37-
38-
ui->centralWidget->setContextMenuPolicy(Qt::CustomContextMenu);
39-
connect(ui->centralWidget, SIGNAL(customContextMenuRequested(const QPoint&)),this, SLOT(showContextMenu(const QPoint&)));
32+
mainLayout->addWidget(mController);
4033

4134
mTimer = new QTimer(this);
4235
connect(mTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
@@ -54,87 +47,6 @@ MainWindow::~MainWindow()
5447
delete ui;
5548
}
5649

57-
void MainWindow::showContextMenu(const QPoint &pos)
58-
{
59-
bool lShowOrder = (mBoard->getSeletedObjects().count() > 0);
60-
QMenu lContextMenu{this};
61-
62-
QMenu lAddWidget(tr("Add Object"));
63-
lContextMenu.addMenu(&lAddWidget);
64-
65-
for (QMLWidgetsConfig group : QMLConfig::instance().QMLWidgets()) {
66-
QMenu *lWidgetMenu = lAddWidget.addMenu(group.info.groupTitle);
67-
68-
for (QString widget : group.widgets()) {
69-
QString lWidgetTitle = widget.split(".").at(0);
70-
QIcon lIcon(group.info.groupPath + lWidgetTitle +".png");
71-
QAction *lWidgetAction = new QAction(lIcon, lWidgetTitle);//remove qml from name
72-
lWidgetAction->setData(QVariant::fromValue<QMLWidgetsConfig>(group));
73-
74-
lWidgetMenu->addAction(lWidgetAction);
75-
connect(lWidgetAction, SIGNAL(triggered()), this, SLOT(addNewObject()));
76-
}
77-
}
78-
79-
QMenu *lOrder = lContextMenu.addMenu("Order");
80-
lOrder->setEnabled(lShowOrder);
81-
82-
if (lShowOrder) {
83-
lOrder->addAction(tr("Bring to front"), this, SLOT(bringToFront()));
84-
lOrder->addAction(tr("Send to back"), this, SLOT(sendToBack()));
85-
}
86-
87-
lContextMenu.exec(ui->centralWidget->mapToGlobal(pos));
88-
}
89-
90-
void MainWindow::addNewObject()
91-
{
92-
QAction *lSender = static_cast<QAction*>(QObject::sender());
93-
QMLWidgetsConfig lConfig = lSender->data().value<QMLWidgetsConfig>();
94-
95-
QString lQMLFilePath = lConfig.info.groupPath + lSender->text() + ".qml";//add qml to name
96-
97-
mBoard->createQMLObject(lQMLFilePath);
98-
}
99-
100-
void MainWindow::bringToFront()
101-
{
102-
if (!mBoard->getSeletedObjects().isEmpty()) {
103-
QScadaObject *lObject = mBoard->getSeletedObjects().first();
104-
mBoard->bringToFront(lObject);
105-
}
106-
}
107-
108-
void MainWindow::sendToBack()
109-
{
110-
if (!mBoard->getSeletedObjects().isEmpty()) {
111-
QScadaObject *lObject = mBoard->getSeletedObjects().first();
112-
mBoard->sendToBack(lObject);
113-
}
114-
}
115-
116-
void MainWindow::updateObjectInfoDialog(QScadaObject *object)
117-
{
118-
if (object != nullptr) {
119-
mObjectInfoDialog->updateWithObjectInfo(object->info());
120-
} else {
121-
mObjectInfoDialog->updateWithObjectInfo(nullptr);
122-
}
123-
}
124-
125-
void MainWindow::deleteObject(QScadaObjectInfo *info)
126-
{
127-
if (info != nullptr) {
128-
mBoard->deleteObjectWithId(info->id());
129-
}
130-
}
131-
132-
void MainWindow::updateSavedObject(QScadaObjectInfo *info)
133-
{
134-
if (info != nullptr) {
135-
mBoard->updateObjectWithId(info->id());
136-
}
137-
}
13850
//this method is called with timer
13951
//You can use it to update statuses ok markers.
14052
void MainWindow::updateStatus()
@@ -206,7 +118,7 @@ void MainWindow::open()
206118
tr("Open Project"), QDir::currentPath(), tr("iReDS Project (*.irp)"));
207119

208120
if (!lFileName.isEmpty()) {
209-
mObjectInfoDialog->updateWithObjectInfo(nullptr);
121+
mController->getParametersDialod()->updateWithObjectInfo(nullptr);
210122

211123
for (QScadaObject *object : *mBoard->objects()) {
212124
mBoard->deleteObject(object);

mainwindow.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,10 @@ class MainWindow : public QMainWindow
1919
Q_OBJECT
2020

2121
public:
22-
explicit MainWindow(QWidget *parent = 0);
22+
explicit MainWindow(QWidget *parent = nullptr);
2323
~MainWindow();
2424

2525
private slots:
26-
void showContextMenu(const QPoint&);
27-
void addNewObject();
28-
void bringToFront();
29-
void sendToBack();
30-
void updateObjectInfoDialog(QScadaObject *);
31-
void deleteObject(QScadaObjectInfo *);
32-
void updateSavedObject(QScadaObjectInfo *);
3326
void updateStatus();
3427

3528
void save();
@@ -40,7 +33,6 @@ private slots:
4033

4134
QScadaBoardController *mController;
4235
QScadaBoard *mBoard;
43-
QScadaObjectInfoDialog *mObjectInfoDialog;
4436
QTimer *mTimer;
4537
};
4638

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>Form</class>
4+
<widget class="QWidget" name="Form">
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>Form</string>
15+
</property>
16+
<layout class="QGridLayout" name="gridLayout">
17+
<item row="0" column="0">
18+
<widget class="QGroupBox" name="groupBox_2">
19+
<property name="title">
20+
<string>Axies</string>
21+
</property>
22+
<layout class="QGridLayout" name="gridLayout_2">
23+
<item row="0" column="0">
24+
<layout class="QHBoxLayout" name="horizontalLayout_8">
25+
<item>
26+
<widget class="QCheckBox" name="checkBoxAxis">
27+
<property name="text">
28+
<string>Show Axies</string>
29+
</property>
30+
</widget>
31+
</item>
32+
</layout>
33+
</item>
34+
<item row="1" column="0">
35+
<layout class="QHBoxLayout" name="horizontalLayout_4">
36+
<item>
37+
<widget class="QLabel" name="label_10">
38+
<property name="text">
39+
<string>Axis Position</string>
40+
</property>
41+
</widget>
42+
</item>
43+
<item>
44+
<widget class="QComboBox" name="comboBoxAxisPosition">
45+
<item>
46+
<property name="text">
47+
<string>Left</string>
48+
</property>
49+
</item>
50+
<item>
51+
<property name="text">
52+
<string>Right</string>
53+
</property>
54+
</item>
55+
</widget>
56+
</item>
57+
</layout>
58+
</item>
59+
<item row="2" column="0">
60+
<layout class="QHBoxLayout" name="horizontalLayout_7">
61+
<item>
62+
<layout class="QVBoxLayout" name="verticalLayout_3">
63+
<item>
64+
<widget class="QLabel" name="label_6">
65+
<property name="text">
66+
<string>X</string>
67+
</property>
68+
</widget>
69+
</item>
70+
<item>
71+
<widget class="QLabel" name="label_7">
72+
<property name="text">
73+
<string>Y</string>
74+
</property>
75+
</widget>
76+
</item>
77+
<item>
78+
<widget class="QLabel" name="label_8">
79+
<property name="text">
80+
<string>Z</string>
81+
</property>
82+
</widget>
83+
</item>
84+
</layout>
85+
</item>
86+
<item>
87+
<layout class="QVBoxLayout" name="verticalLayout_4">
88+
<item>
89+
<widget class="QComboBox" name="comboBoxX">
90+
<property name="minimumSize">
91+
<size>
92+
<width>80</width>
93+
<height>0</height>
94+
</size>
95+
</property>
96+
<property name="maximumSize">
97+
<size>
98+
<width>80</width>
99+
<height>16777215</height>
100+
</size>
101+
</property>
102+
<item>
103+
<property name="text">
104+
<string>Up</string>
105+
</property>
106+
</item>
107+
<item>
108+
<property name="text">
109+
<string>Aside</string>
110+
</property>
111+
</item>
112+
<item>
113+
<property name="text">
114+
<string>Inside</string>
115+
</property>
116+
</item>
117+
</widget>
118+
</item>
119+
<item>
120+
<widget class="QComboBox" name="comboBoxY">
121+
<property name="minimumSize">
122+
<size>
123+
<width>80</width>
124+
<height>0</height>
125+
</size>
126+
</property>
127+
<property name="maximumSize">
128+
<size>
129+
<width>80</width>
130+
<height>16777215</height>
131+
</size>
132+
</property>
133+
<item>
134+
<property name="text">
135+
<string>Aside</string>
136+
</property>
137+
</item>
138+
<item>
139+
<property name="text">
140+
<string>Inside</string>
141+
</property>
142+
</item>
143+
<item>
144+
<property name="text">
145+
<string>Up</string>
146+
</property>
147+
</item>
148+
</widget>
149+
</item>
150+
<item>
151+
<widget class="QComboBox" name="comboBoxZ">
152+
<property name="minimumSize">
153+
<size>
154+
<width>80</width>
155+
<height>0</height>
156+
</size>
157+
</property>
158+
<property name="maximumSize">
159+
<size>
160+
<width>80</width>
161+
<height>16777215</height>
162+
</size>
163+
</property>
164+
<item>
165+
<property name="text">
166+
<string>Inside</string>
167+
</property>
168+
</item>
169+
<item>
170+
<property name="text">
171+
<string>Up</string>
172+
</property>
173+
</item>
174+
<item>
175+
<property name="text">
176+
<string>Aside</string>
177+
</property>
178+
</item>
179+
</widget>
180+
</item>
181+
</layout>
182+
</item>
183+
</layout>
184+
</item>
185+
</layout>
186+
</widget>
187+
</item>
188+
</layout>
189+
</widget>
190+
<resources/>
191+
<connections/>
192+
</ui>

0 commit comments

Comments
 (0)