PIValueTreeEdit paste now offer input new name if current name exists
This commit is contained in:
@@ -192,6 +192,14 @@
|
|||||||
<source>Select new name:</source>
|
<source>Select new name:</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Paste</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Name "%1" already exists, get new name:</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>PIValueTreeEditArray</name>
|
<name>PIValueTreeEditArray</name>
|
||||||
|
|||||||
@@ -192,6 +192,14 @@
|
|||||||
<source>Select new name:</source>
|
<source>Select new name:</source>
|
||||||
<translation>Выберите новое имя:</translation>
|
<translation>Выберите новое имя:</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Paste</source>
|
||||||
|
<translation>Вставить</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Name "%1" already exists, get new name:</source>
|
||||||
|
<translation>Имя "%1" уже существует, задайте новое имя:</translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>PIValueTreeEditArray</name>
|
<name>PIValueTreeEditArray</name>
|
||||||
|
|||||||
@@ -442,10 +442,22 @@ void PIValueTreeEdit::actionCopy(QToolButton *, const PIString & vn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIValueTreeEdit::actionPaste(QToolButton * button, const PIString & vn, int offset) {
|
void PIValueTreeEdit::actionPaste(QToolButton *, const PIString & vn, int offset) {
|
||||||
PIString json = Q2PIString(QApplication::clipboard()->text());
|
PIString json = Q2PIString(QApplication::clipboard()->text());
|
||||||
if (json.isEmpty()) return;
|
if (json.isEmpty()) return;
|
||||||
|
while (current.contains(paste_name)) {
|
||||||
|
bool ok = false;
|
||||||
|
QString s = QInputDialog::getText(nullptr,
|
||||||
|
tr("Paste"),
|
||||||
|
tr("Name \"%1\" already exists, get new name:").arg(PI2QString(paste_name)),
|
||||||
|
QLineEdit::Normal,
|
||||||
|
PI2QString(paste_name),
|
||||||
|
&ok);
|
||||||
|
if (!ok) return;
|
||||||
|
paste_name = Q2PIString(s);
|
||||||
|
}
|
||||||
PIValueTree ins_val = PIValueTreeConversions::fromJSON(PIJSON::fromJSON(json));
|
PIValueTree ins_val = PIValueTreeConversions::fromJSON(PIJSON::fromJSON(json));
|
||||||
|
ins_val.setName(paste_name);
|
||||||
// if (ins_val.name.isEmpty()) return;
|
// if (ins_val.name.isEmpty()) return;
|
||||||
PIValueTree cur_val = value();
|
PIValueTree cur_val = value();
|
||||||
cur_val.insertChild(cur_val.childIndex(vn) + offset, ins_val);
|
cur_val.insertChild(cur_val.childIndex(vn) + offset, ins_val);
|
||||||
@@ -492,6 +504,7 @@ void PIValueTreeEdit::actionTriggered(QToolButton * button, const PIString & vn,
|
|||||||
|
|
||||||
|
|
||||||
void PIValueTreeEdit::checkActions() {
|
void PIValueTreeEdit::checkActions() {
|
||||||
|
paste_name.clear();
|
||||||
bool can_paste = true;
|
bool can_paste = true;
|
||||||
PIString str = Q2PIString(QApplication::clipboard()->text());
|
PIString str = Q2PIString(QApplication::clipboard()->text());
|
||||||
if (str.isEmpty() || !str.startsWith("{")) {
|
if (str.isEmpty() || !str.startsWith("{")) {
|
||||||
@@ -501,7 +514,7 @@ void PIValueTreeEdit::checkActions() {
|
|||||||
if (!j.contains("name"))
|
if (!j.contains("name"))
|
||||||
can_paste = false;
|
can_paste = false;
|
||||||
else {
|
else {
|
||||||
if (current.contains(j["name"].value().toString())) can_paste = false;
|
paste_name = j["name"].value().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
widget_params->actionPasteBefore->setEnabled(can_paste);
|
widget_params->actionPasteBefore->setEnabled(can_paste);
|
||||||
|
|||||||
@@ -174,6 +174,7 @@ private:
|
|||||||
PIValueTreeEditParameters * widget_params;
|
PIValueTreeEditParameters * widget_params;
|
||||||
PIValueTreeEditReorder * widget_reorder;
|
PIValueTreeEditReorder * widget_reorder;
|
||||||
PIStringList root_path;
|
PIStringList root_path;
|
||||||
|
PIString paste_name;
|
||||||
PIVector<PIVariantEdit *> array_edits;
|
PIVector<PIVariantEdit *> array_edits;
|
||||||
PIMap<PIString, PIVariantEdit *> value_edits;
|
PIMap<PIString, PIVariantEdit *> value_edits;
|
||||||
PIMap<PIString, PIValueTreeEdit *> tree_edits;
|
PIMap<PIString, PIValueTreeEdit *> tree_edits;
|
||||||
|
|||||||
@@ -89,12 +89,21 @@
|
|||||||
<property name="bottomMargin">
|
<property name="bottomMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="PIValueTreeEdit" name="valueTreeEdit"/>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>PIValueTreeEdit</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>pivaluetree_edit.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
<slots/>
|
|
||||||
</ui>
|
</ui>
|
||||||
|
|||||||
Reference in New Issue
Block a user