Skip to content

Commit b823d4b

Browse files
committed
[NEW] 添加项目文件及说明
Signed-off-by: albert <[email protected]>
1 parent 4990710 commit b823d4b

File tree

282 files changed

+21390
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

282 files changed

+21390
-2
lines changed

Qt画面绘图demo/fadian.gif

1.09 MB
Loading

Qt画面绘图demo/shuibeng.gif

132 KB
Loading
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>Dialog</class>
4+
<widget class="QDialog" name="Dialog">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>559</width>
10+
<height>412</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Dialog</string>
15+
</property>
16+
<widget class="QPushButton" name="btnDelController">
17+
<property name="geometry">
18+
<rect>
19+
<x>40</x>
20+
<y>160</y>
21+
<width>93</width>
22+
<height>28</height>
23+
</rect>
24+
</property>
25+
<property name="text">
26+
<string>删除控制器</string>
27+
</property>
28+
</widget>
29+
<widget class="QComboBox" name="comboBox_controllers">
30+
<property name="geometry">
31+
<rect>
32+
<x>40</x>
33+
<y>70</y>
34+
<width>87</width>
35+
<height>22</height>
36+
</rect>
37+
</property>
38+
</widget>
39+
<widget class="QDialogButtonBox" name="buttonBox">
40+
<property name="geometry">
41+
<rect>
42+
<x>130</x>
43+
<y>340</y>
44+
<width>341</width>
45+
<height>32</height>
46+
</rect>
47+
</property>
48+
<property name="orientation">
49+
<enum>Qt::Horizontal</enum>
50+
</property>
51+
<property name="standardButtons">
52+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
53+
</property>
54+
</widget>
55+
<widget class="QPushButton" name="btnAddController">
56+
<property name="geometry">
57+
<rect>
58+
<x>40</x>
59+
<y>130</y>
60+
<width>93</width>
61+
<height>28</height>
62+
</rect>
63+
</property>
64+
<property name="text">
65+
<string>增加控制器</string>
66+
</property>
67+
</widget>
68+
<widget class="QPushButton" name="btnPrint">
69+
<property name="geometry">
70+
<rect>
71+
<x>130</x>
72+
<y>270</y>
73+
<width>161</width>
74+
<height>28</height>
75+
</rect>
76+
</property>
77+
<property name="text">
78+
<string>print controllers</string>
79+
</property>
80+
</widget>
81+
<widget class="QWidget" name="widget_addController" native="true">
82+
<property name="geometry">
83+
<rect>
84+
<x>230</x>
85+
<y>40</y>
86+
<width>291</width>
87+
<height>201</height>
88+
</rect>
89+
</property>
90+
<widget class="QLineEdit" name="lineEdit_IP">
91+
<property name="geometry">
92+
<rect>
93+
<x>110</x>
94+
<y>60</y>
95+
<width>113</width>
96+
<height>21</height>
97+
</rect>
98+
</property>
99+
</widget>
100+
<widget class="QLineEdit" name="lineEdit_Port">
101+
<property name="geometry">
102+
<rect>
103+
<x>110</x>
104+
<y>90</y>
105+
<width>113</width>
106+
<height>21</height>
107+
</rect>
108+
</property>
109+
</widget>
110+
<widget class="QLabel" name="label_9">
111+
<property name="geometry">
112+
<rect>
113+
<x>50</x>
114+
<y>60</y>
115+
<width>41</width>
116+
<height>16</height>
117+
</rect>
118+
</property>
119+
<property name="text">
120+
<string>IP:</string>
121+
</property>
122+
</widget>
123+
<widget class="QLabel" name="label_10">
124+
<property name="geometry">
125+
<rect>
126+
<x>50</x>
127+
<y>90</y>
128+
<width>41</width>
129+
<height>16</height>
130+
</rect>
131+
</property>
132+
<property name="text">
133+
<string>Port:</string>
134+
</property>
135+
</widget>
136+
<widget class="QDialogButtonBox" name="buttonBox_2">
137+
<property name="geometry">
138+
<rect>
139+
<x>70</x>
140+
<y>150</y>
141+
<width>193</width>
142+
<height>28</height>
143+
</rect>
144+
</property>
145+
<property name="standardButtons">
146+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
147+
</property>
148+
</widget>
149+
<widget class="QLabel" name="label_11">
150+
<property name="geometry">
151+
<rect>
152+
<x>50</x>
153+
<y>30</y>
154+
<width>41</width>
155+
<height>16</height>
156+
</rect>
157+
</property>
158+
<property name="text">
159+
<string>Name:</string>
160+
</property>
161+
</widget>
162+
<widget class="QLineEdit" name="lineEdit_Name">
163+
<property name="geometry">
164+
<rect>
165+
<x>110</x>
166+
<y>30</y>
167+
<width>113</width>
168+
<height>21</height>
169+
</rect>
170+
</property>
171+
</widget>
172+
<widget class="QCheckBox" name="checkBox_M1">
173+
<property name="geometry">
174+
<rect>
175+
<x>120</x>
176+
<y>120</y>
177+
<width>41</width>
178+
<height>19</height>
179+
</rect>
180+
</property>
181+
<property name="text">
182+
<string>M1</string>
183+
</property>
184+
</widget>
185+
<widget class="QCheckBox" name="checkBox_M2">
186+
<property name="geometry">
187+
<rect>
188+
<x>170</x>
189+
<y>120</y>
190+
<width>41</width>
191+
<height>19</height>
192+
</rect>
193+
</property>
194+
<property name="text">
195+
<string>M2</string>
196+
</property>
197+
</widget>
198+
<widget class="QCheckBox" name="checkBox_M3">
199+
<property name="geometry">
200+
<rect>
201+
<x>220</x>
202+
<y>120</y>
203+
<width>51</width>
204+
<height>19</height>
205+
</rect>
206+
</property>
207+
<property name="text">
208+
<string>M3</string>
209+
</property>
210+
</widget>
211+
<widget class="QLabel" name="label_12">
212+
<property name="geometry">
213+
<rect>
214+
<x>50</x>
215+
<y>120</y>
216+
<width>61</width>
217+
<height>16</height>
218+
</rect>
219+
</property>
220+
<property name="text">
221+
<string>选择M点:</string>
222+
</property>
223+
</widget>
224+
</widget>
225+
</widget>
226+
<resources/>
227+
<connections/>
228+
</ui>
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#include "addcontrollersdialog.h"
2+
#include "ui_addcontrollersdialog.h"
3+
#include <QDebug>
4+
#include <QRegExp>
5+
#include <QMessageBox>
6+
#include <stdio.h>
7+
8+
AddControllersDialog::AddControllersDialog(QWidget *parent, QMap<QString, QVector<QString>> c) :
9+
QDialog(parent), controllers(c), ui(new Ui::Dialog)
10+
{
11+
ui->setupUi(this);
12+
ui->widget_addController->hide();
13+
updateItemForComobox();
14+
15+
this->setWindowTitle("Add Controllers");
16+
17+
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(slotButtonBox_OK()));
18+
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(slotButtonBox_Cancel()));
19+
20+
connect(ui->buttonBox_2, SIGNAL(accepted()), this, SLOT(slotButtonBox2_OK()));
21+
connect(ui->buttonBox_2, SIGNAL(rejected()), this, SLOT(slotButtonBox2_Cancel()));
22+
23+
}
24+
25+
AddControllersDialog::~AddControllersDialog()
26+
{
27+
delete ui;
28+
}
29+
30+
void AddControllersDialog::setCurrentController(const QString controller)
31+
{
32+
currentController = controller;
33+
}
34+
35+
void AddControllersDialog::on_btnAddController_clicked()
36+
{
37+
ui->widget_addController->show();
38+
}
39+
40+
void AddControllersDialog::on_btnDelController_clicked()
41+
{
42+
QString text = ui->comboBox_controllers->currentText();
43+
44+
int ret_water= QMessageBox::question(this, "deleteController", QString("are you sure to delete %1?").arg(text));
45+
switch (ret_water) {
46+
case QMessageBox::Yes:
47+
{
48+
controllers.remove(text);
49+
updateItemForComobox();
50+
}
51+
break;
52+
case QMessageBox::No:
53+
break;
54+
default:
55+
break;
56+
}
57+
}
58+
59+
void AddControllersDialog::slotButtonBox_OK()
60+
{
61+
emit saveControllerSettings(controllers);
62+
}
63+
64+
void AddControllersDialog::slotButtonBox_Cancel()
65+
{
66+
emit cancelControllerSettings();
67+
}
68+
69+
void AddControllersDialog::slotButtonBox2_OK()
70+
{
71+
72+
73+
bool ok=false;
74+
int port = ui->lineEdit_Port->text().toInt(&ok, 10);
75+
QString ip = ui->lineEdit_IP->text();
76+
QString name = ui->lineEdit_Name->text();
77+
bool ok2 = isIPaddress( ip );
78+
79+
if( name==NULL || !ok || !ok2 || port<0 || port>65535 ){
80+
QMessageBox::information(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("输入不合法"));
81+
ui->lineEdit_IP->clear();
82+
ui->lineEdit_Port->clear();
83+
ui->lineEdit_Name->clear();
84+
return;
85+
}
86+
87+
QString M;
88+
if( ui->checkBox_M1->isChecked() )
89+
M.append("0 ");
90+
if( ui->checkBox_M2->isChecked() )
91+
M.append("1 ");
92+
if( ui->checkBox_M3->isChecked() )
93+
M.append("2 ");
94+
95+
controllers[name] = QVector<QString>({ip, QString::number(port), M});
96+
updateItemForComobox();
97+
ui->widget_addController->hide();
98+
ui->lineEdit_IP->clear();
99+
ui->lineEdit_Port->clear();
100+
ui->lineEdit_Name->clear();
101+
ui->checkBox_M1->setChecked(false);
102+
ui->checkBox_M2->setChecked(false);
103+
ui->checkBox_M3->setChecked(false);
104+
return;
105+
}
106+
107+
void AddControllersDialog::slotButtonBox2_Cancel()
108+
{
109+
ui->widget_addController->hide();
110+
ui->lineEdit_IP->clear();
111+
ui->lineEdit_Port->clear();
112+
ui->lineEdit_Name->clear();
113+
ui->checkBox_M1->setChecked(false);
114+
ui->checkBox_M2->setChecked(false);
115+
ui->checkBox_M3->setChecked(false);
116+
}
117+
118+
bool AddControllersDialog::isIPaddress(QString ip)
119+
{
120+
QRegExp rx("((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)");
121+
122+
if( !rx.exactMatch(ip) )
123+
124+
{
125+
return false;
126+
}
127+
128+
return true;
129+
}
130+
131+
void AddControllersDialog::on_btnPrint_clicked()
132+
{
133+
QMap<QString, QVector<QString>>::iterator i;
134+
for (i = controllers.begin(); i != controllers.end(); ++i) { //i,j全使用const_iterator使用时会发生错误
135+
printf("%s: ", i.key().toStdString().data());
136+
QVector<QString>::iterator j;
137+
for(j = controllers[i.key()].begin(); j != controllers[i.key()].end(); ++j)
138+
printf("%s ", j->toStdString().data());
139+
printf("\n");
140+
}
141+
fflush(stdout);
142+
}
143+
144+
void AddControllersDialog::updateItemForComobox()
145+
{
146+
ui->comboBox_controllers->clear();
147+
QMap<QString, QVector<QString>>::const_iterator i;
148+
for (i = controllers.constBegin(); i != controllers.constEnd(); ++i) {
149+
ui->comboBox_controllers->addItem(i.key());
150+
}
151+
}
152+

0 commit comments

Comments
 (0)