PIValueTreeEdit paste now offer input new name if current name exists
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user