PIValueTreeEdit paste now offer input new name if current name exists

This commit is contained in:
2023-04-29 20:44:28 +03:00
parent d38d624b51
commit 1f0c71ec0c
5 changed files with 42 additions and 3 deletions

View File

@@ -192,6 +192,14 @@
<source>Select new name:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Paste</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Name &quot;%1&quot; already exists, get new name:</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PIValueTreeEditArray</name>

View File

@@ -192,6 +192,14 @@
<source>Select new name:</source>
<translation>Выберите новое имя:</translation>
</message>
<message>
<source>Paste</source>
<translation>Вставить</translation>
</message>
<message>
<source>Name &quot;%1&quot; already exists, get new name:</source>
<translation>Имя &quot;%1&quot; уже существует, задайте новое имя:</translation>
</message>
</context>
<context>
<name>PIValueTreeEditArray</name>

View File

@@ -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());
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));
ins_val.setName(paste_name);
// if (ins_val.name.isEmpty()) return;
PIValueTree cur_val = value();
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() {
paste_name.clear();
bool can_paste = true;
PIString str = Q2PIString(QApplication::clipboard()->text());
if (str.isEmpty() || !str.startsWith("{")) {
@@ -501,7 +514,7 @@ void PIValueTreeEdit::checkActions() {
if (!j.contains("name"))
can_paste = false;
else {
if (current.contains(j["name"].value().toString())) can_paste = false;
paste_name = j["name"].value().toString();
}
}
widget_params->actionPasteBefore->setEnabled(can_paste);

View File

@@ -174,6 +174,7 @@ private:
PIValueTreeEditParameters * widget_params;
PIValueTreeEditReorder * widget_reorder;
PIStringList root_path;
PIString paste_name;
PIVector<PIVariantEdit *> array_edits;
PIMap<PIString, PIVariantEdit *> value_edits;
PIMap<PIString, PIValueTreeEdit *> tree_edits;

View File

@@ -89,12 +89,21 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="PIValueTreeEdit" name="valueTreeEdit"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>PIValueTreeEdit</class>
<extends>QWidget</extends>
<header>pivaluetree_edit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
<slots/>
</ui>