Rabbit Remote Control 0.1.0-bate10
Loading...
Searching...
No Matches
ParameterFilterUI.cpp
1#include <QInputDialog>
2#include <QItemSelectionModel>
3#include <QMenu>
4#include "ParameterFilterUI.h"
5#include "ui_ParameterFilterUI.h"
6
7CParameterFilterUI::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
32CParameterFilterUI::~CParameterFilterUI()
33{
34 delete ui;
35}
36
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
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
63void 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
77void 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
84void 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}
virtual int SetParameter(CParameter *pParameter) override
[override functions]
virtual int Accept() override
Accept parameters.
The parameter UI interface.
Definition ParameterUI.h:15
Parameter interface.
Definition Parameter.h:220