玉兔远程控制
0.1.0-bate11
Toggle main menu visibility
载入中...
搜索中...
未找到
Src
ParameterCompone
ParameterFilterUI.cpp
1
#include <QInputDialog>
2
#include <QItemSelectionModel>
3
#include <QMenu>
4
#include "ParameterFilterUI.h"
5
#include "ui_ParameterFilterUI.h"
6
7
CParameterFilterUI::CParameterFilterUI(QWidget *parent)
8
:
CParameterUI
(parent)
9
, ui(new
Ui
::
CParameterFilterUI
)
10
, m_pPara(nullptr)
11
{
12
ui->setupUi(
this
);
13
ui->lsFilter->setModel(&m_Model);
14
15
m_szFilteListPrompt = tr(
"The IP address and the netmask must be separated by a slash (/)."
) +
"\n\n"
16
+ tr(
"ag:"
) +
"\n"
17
+
"- 123.123.123.123/n "
+ tr(
"where n is any value between 0 and 32"
) +
"\n"
18
+
"- 123.123.123.123/255.255.255.255"
+
"\n"
19
+
"- <ipv6-address>/n "
+ tr(
"where n is any value between 0 and 128"
) +
"\n\n"
20
+ tr(
"For IP version 4, accepts as well missing trailing components"
) +
"\n"
21
+ tr(
"(i.e., less than 4 octets, like \"192.168.1\"), followed or not by a dot. "
) +
"\n"
22
+ tr(
"If the netmask is also missing in that case,"
) +
"\n"
23
+ tr(
"it is set to the number of octets actually passed"
) +
"\n"
24
+ tr(
"(in the example above, it would be 24, for 3 octets)."
) +
"\n\n"
25
+ tr(
"Add IP address and the netmask:"
);
26
27
bool
check = connect(ui->lsFilter, SIGNAL(customContextMenuRequested(
const
QPoint&)),
28
this
, SLOT(slotContextMenuRequested(
const
QPoint&)));
29
Q_ASSERT(check);
30
}
31
32
CParameterFilterUI::~CParameterFilterUI()
33
{
34
delete
ui;
35
}
36
37
int
CParameterFilterUI::SetParameter
(
CParameter
*pParameter)
38
{
39
int
nRet = 0;
40
m_pPara = qobject_cast<CParameterFilter*>(pParameter);
41
if
(!m_pPara)
return
-1;
42
m_pPara->OnProcess([&](
const
QString & key)->
int
{
43
m_Model.appendRow(
new
QStandardItem(key));
44
return
0;
45
});
46
return
nRet;
47
}
48
49
int
CParameterFilterUI::Accept
()
50
{
51
int
nRet = 0;
52
if
(!m_pPara)
return
-1;
53
54
m_pPara->Clear();
55
QStringList lstBlack;
56
for
(
int
i = 0; i < m_Model.rowCount(); ++i) {
57
m_pPara->AddKey(m_Model.item(i)->text());
58
}
59
60
return
nRet;
61
}
62
63
void
CParameterFilterUI::slotContextMenuRequested(
const
QPoint &pos)
64
{
65
QMenu m;
66
QItemSelectionModel* pSelect = ui->lsFilter->selectionModel();
67
QModelIndexList lstIndex = pSelect->selectedRows();
68
m.addAction(tr(
"Add"
),
this
, SLOT(on_pbAdd_clicked()));
69
if
(!lstIndex.isEmpty()) {
70
m.addAction(tr(
"Delete"
),
this
, SLOT(on_pbDelete_clicked()));
71
}
72
73
QPoint p = ui->lsFilter->mapToGlobal(pos);
74
m.exec(p);
75
}
76
77
void
CParameterFilterUI::on_pbAdd_clicked()
78
{
79
QString szIp = QInputDialog::getText(
this
, tr(
"Add"
), m_szFilteListPrompt);
80
QStandardItem* item =
new
QStandardItem(szIp);
81
m_Model.appendRow(item);
82
}
83
84
void
CParameterFilterUI::on_pbDelete_clicked()
85
{
86
QItemSelectionModel* pSelect = ui->lsFilter->selectionModel();
87
if
(!pSelect)
return
;
88
QModelIndexList lstIndex = pSelect->selectedRows();
89
foreach
(
auto
idx, lstIndex) {
90
m_Model.removeRow(idx.row());
91
}
92
}
CParameterFilterUI
定义
ParameterFilterUI.h:14
CParameterFilterUI::SetParameter
virtual int SetParameter(CParameter *pParameter) override
[override functions]
定义
ParameterFilterUI.cpp:37
CParameterFilterUI::Accept
virtual int Accept() override
接受参数。如果需要,可先调用 CheckValidity
定义
ParameterFilterUI.cpp:49
CParameterUI
参数界面接口
定义
ParameterUI.h:15
CParameter
参数接口
定义
Parameter.h:220
Ui
定义
FrmFullScreenToolBar.h:14
作者:康林 (kl222@126.com)
版权所有(c) 康林工作室 保留所有权力