Skip to content

Commit 2f08135

Browse files
添加zk文件
1 parent 1f2c15d commit 2f08135

Some content is hidden

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

54 files changed

+5061
-1373
lines changed

qt_zk/CreateChildNodeDialog.cpp

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#include "CreateChildNodeDialog.h"
2+
#include <QMessageBox>
3+
4+
CreateChildNodeDialog::CreateChildNodeDialog(QWidget* parent, ZKConnectionWorker* pWorker)
5+
: QDialog(parent), m_pWorker(pWorker)
6+
{
7+
ui.setupUi(this);
8+
9+
// icon
10+
this->setWindowIcon(style()->standardIcon(QStyle::SP_FileDialogNewFolder));
11+
12+
connect(pWorker, &ZKConnectionWorker::AfterCreateNode, this, &CreateChildNodeDialog::OnZKReturnCreateNodeResult);
13+
14+
connect(ui.createButton, &QPushButton::clicked, this, &CreateChildNodeDialog::OnCreateButtonClicked);
15+
16+
connect(ui.nullDataCheckBox, &QCheckBox::stateChanged, [ & ](int nState)
17+
{
18+
ui.dataTextEdit->setEnabled(nState == Qt::Unchecked);
19+
});
20+
21+
connect(ui.cancelButton, &QPushButton::clicked, [&](bool)
22+
{
23+
this->hide();
24+
});
25+
26+
void (QComboBox::*signalIndexChanged)(int) = &QComboBox::currentIndexChanged;
27+
28+
connect(ui.createModeComboBox, signalIndexChanged, [&](int nCurrentIndex)
29+
{
30+
ui.sequenceCheckBox->setVisible(nCurrentIndex != 2);
31+
});
32+
}
33+
34+
CreateChildNodeDialog::~CreateChildNodeDialog()
35+
{
36+
}
37+
38+
void CreateChildNodeDialog::SetParentPath(const std::string& strParentPath)
39+
{
40+
m_nTransactionID++;
41+
42+
m_strParentPath = strParentPath;
43+
44+
this->setWindowTitle(tr("Create Child For Node: ") + QString::fromStdString(m_strParentPath));
45+
ui.dataTextEdit->setPlainText(QString());
46+
ui.childNameLineEdit->setText(QString());
47+
ui.createButton->setEnabled(true);
48+
}
49+
50+
void CreateChildNodeDialog::OnCreateButtonClicked(bool)
51+
{
52+
const auto strNodeName = ui.childNameLineEdit->text().toStdString();
53+
if (strNodeName.empty())
54+
{
55+
QMessageBox::critical(this, tr("Error"), tr("Please enter the node name."));
56+
return;
57+
}
58+
59+
if (strNodeName.find('/') != std::string::npos)
60+
{
61+
QMessageBox::critical(this, tr("Error"), tr("Node name must not contain '/'."));
62+
return;
63+
}
64+
65+
std::string strPath;
66+
if (m_strParentPath == "/")
67+
{
68+
strPath = m_strParentPath + strNodeName;
69+
}
70+
else
71+
{
72+
strPath = m_strParentPath + "/" + strNodeName;
73+
}
74+
75+
QVariant strValue;
76+
if (!ui.nullDataCheckBox->isChecked())
77+
{
78+
strValue = ui.dataTextEdit->toPlainText();
79+
}
80+
81+
const auto nCreateModeIndex = ui.createModeComboBox->currentIndex();
82+
int nCreateMode;
83+
if (nCreateModeIndex == 0)
84+
{
85+
if (ui.sequenceCheckBox->isChecked())
86+
{
87+
nCreateMode = ZOO_PERSISTENT_SEQUENTIAL;
88+
}
89+
else
90+
{
91+
nCreateMode = ZOO_PERSISTENT;
92+
}
93+
}
94+
else if (nCreateModeIndex == 1)
95+
{
96+
if (ui.sequenceCheckBox->isChecked())
97+
{
98+
nCreateMode = ZOO_EPHEMERAL_SEQUENTIAL;
99+
}
100+
else
101+
{
102+
nCreateMode = ZOO_EPHEMERAL;
103+
}
104+
}
105+
else
106+
{
107+
nCreateMode = ZOO_CONTAINER;
108+
}
109+
110+
emit m_pWorker->CreateNode(strPath, strValue, nCreateMode, m_nTransactionID, ui.goCheckBox->isChecked());
111+
ui.createButton->setEnabled(false);
112+
}
113+
114+
void CreateChildNodeDialog::OnZKReturnCreateNodeResult(const std::string& strRealPath, const QVariant& strValue, const QString& strResult, const Stat& xStat,
115+
const int64_t nTransactionID, const bool bGoAfterCreated)
116+
{
117+
if (nTransactionID != m_nTransactionID)
118+
{
119+
return;
120+
}
121+
122+
if (this->isHidden())
123+
{
124+
return;
125+
}
126+
127+
ui.createButton->setEnabled(true);
128+
129+
// 成功
130+
if (strResult.isEmpty())
131+
{
132+
if (ui.closeCheckBox->isChecked())
133+
{
134+
this->hide();
135+
}
136+
}
137+
}

qt_zk/CreateChildNodeDialog.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
3+
#include <QDialog>
4+
#include "ui_CreateChildNodeDialog.h"
5+
#include "ZKConnectionWorker.h"
6+
7+
class CreateChildNodeDialog : public QDialog
8+
{
9+
Q_OBJECT
10+
11+
public:
12+
CreateChildNodeDialog(QWidget* parent, ZKConnectionWorker* pWorker);
13+
~CreateChildNodeDialog();
14+
15+
void SetParentPath(const std::string& strParentPath);
16+
17+
private slots:
18+
19+
void OnCreateButtonClicked(bool);
20+
21+
void OnZKReturnCreateNodeResult(const std::string& strRealPath, const QVariant& strValue, const QString& strResult, const Stat& xStat,
22+
const int64_t nTransactionID, const bool bGoAfterCreated);
23+
24+
private:
25+
Ui::CreateChildNodeDialog ui;
26+
27+
ZKConnectionWorker* const m_pWorker;
28+
29+
std::string m_strParentPath;
30+
int64_t m_nTransactionID = 0;
31+
};

qt_zk/CreateChildNodeDialog.ui

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>CreateChildNodeDialog</class>
4+
<widget class="QDialog" name="CreateChildNodeDialog">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>770</width>
10+
<height>477</height>
11+
</rect>
12+
</property>
13+
<layout class="QVBoxLayout" name="verticalLayout">
14+
<item>
15+
<widget class="QLabel" name="label_2">
16+
<property name="font">
17+
<font>
18+
<weight>75</weight>
19+
<bold>true</bold>
20+
</font>
21+
</property>
22+
<property name="text">
23+
<string>Child Name:</string>
24+
</property>
25+
</widget>
26+
</item>
27+
<item>
28+
<widget class="QLineEdit" name="childNameLineEdit"/>
29+
</item>
30+
<item>
31+
<widget class="QLabel" name="label_4">
32+
<property name="font">
33+
<font>
34+
<weight>75</weight>
35+
<bold>true</bold>
36+
</font>
37+
</property>
38+
<property name="text">
39+
<string>Create Mode:</string>
40+
</property>
41+
</widget>
42+
</item>
43+
<item>
44+
<layout class="QHBoxLayout" name="horizontalLayout">
45+
<item>
46+
<widget class="QComboBox" name="createModeComboBox">
47+
<item>
48+
<property name="text">
49+
<string>PERSISTENT</string>
50+
</property>
51+
</item>
52+
<item>
53+
<property name="text">
54+
<string>EPHEMERAL</string>
55+
</property>
56+
</item>
57+
<item>
58+
<property name="text">
59+
<string>CONTAINER</string>
60+
</property>
61+
</item>
62+
</widget>
63+
</item>
64+
<item>
65+
<widget class="QCheckBox" name="sequenceCheckBox">
66+
<property name="text">
67+
<string>sequence</string>
68+
</property>
69+
</widget>
70+
</item>
71+
<item>
72+
<spacer name="horizontalSpacer">
73+
<property name="orientation">
74+
<enum>Qt::Horizontal</enum>
75+
</property>
76+
<property name="sizeHint" stdset="0">
77+
<size>
78+
<width>40</width>
79+
<height>20</height>
80+
</size>
81+
</property>
82+
</spacer>
83+
</item>
84+
<item>
85+
<widget class="QCheckBox" name="goCheckBox">
86+
<property name="text">
87+
<string>Go after created</string>
88+
</property>
89+
<property name="checked">
90+
<bool>true</bool>
91+
</property>
92+
</widget>
93+
</item>
94+
<item>
95+
<widget class="QCheckBox" name="closeCheckBox">
96+
<property name="text">
97+
<string>Close after created</string>
98+
</property>
99+
<property name="checked">
100+
<bool>true</bool>
101+
</property>
102+
</widget>
103+
</item>
104+
</layout>
105+
</item>
106+
<item>
107+
<widget class="QLabel" name="label_3">
108+
<property name="font">
109+
<font>
110+
<weight>75</weight>
111+
<bold>true</bold>
112+
</font>
113+
</property>
114+
<property name="text">
115+
<string>Data:</string>
116+
</property>
117+
</widget>
118+
</item>
119+
<item>
120+
<widget class="QCheckBox" name="nullDataCheckBox">
121+
<property name="text">
122+
<string>has no data</string>
123+
</property>
124+
<property name="checked">
125+
<bool>true</bool>
126+
</property>
127+
</widget>
128+
</item>
129+
<item>
130+
<widget class="QPlainTextEdit" name="dataTextEdit">
131+
<property name="enabled">
132+
<bool>false</bool>
133+
</property>
134+
</widget>
135+
</item>
136+
<item>
137+
<layout class="QHBoxLayout" name="horizontalLayout_2">
138+
<item>
139+
<spacer name="horizontalSpacer_2">
140+
<property name="orientation">
141+
<enum>Qt::Horizontal</enum>
142+
</property>
143+
<property name="sizeHint" stdset="0">
144+
<size>
145+
<width>40</width>
146+
<height>20</height>
147+
</size>
148+
</property>
149+
</spacer>
150+
</item>
151+
<item>
152+
<widget class="QPushButton" name="cancelButton">
153+
<property name="text">
154+
<string>Cancel</string>
155+
</property>
156+
</widget>
157+
</item>
158+
<item>
159+
<widget class="QPushButton" name="createButton">
160+
<property name="text">
161+
<string>Create</string>
162+
</property>
163+
</widget>
164+
</item>
165+
</layout>
166+
</item>
167+
</layout>
168+
</widget>
169+
<layoutdefault spacing="6" margin="11"/>
170+
<resources/>
171+
<connections/>
172+
</ui>

0 commit comments

Comments
 (0)