From 5de1bf0d54a56fe1e27e44b9df2c68e72b660b11 Mon Sep 17 00:00:00 2001 From: arntro-4 Date: Sat, 18 Oct 2014 13:29:29 +0200 Subject: [PATCH] Ability to rename custom properties --- src/tiled/images/16x16/rename.png | Bin 0 -> 624 bytes src/tiled/propertiesdock.cpp | 54 ++++++++++++++++++++++++++++++ src/tiled/propertiesdock.h | 3 ++ src/tiled/tiled.qrc | 1 + 4 files changed, 58 insertions(+) create mode 100644 src/tiled/images/16x16/rename.png diff --git a/src/tiled/images/16x16/rename.png b/src/tiled/images/16x16/rename.png new file mode 100644 index 0000000000000000000000000000000000000000..a12fccab4f26664c906ae52e0396ce4f86153186 GIT binary patch literal 624 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D%zBQrxHN+NuH ztdjF{^%7I^lT!66atnZ}7#M6Stboki)RIJnirk#MVyg;UC9n!BAR8pCucQE0Qj%?} z6yY17;GAESs$i;TqGzCF$EBd4U{jQmW)z9|8>y;bpKhp88yV>WRp=I1=9MH?=;jqGLkxkLMfuL^+7WFhI$72aI=A0Z9t+{{zaLoK$}74+Zoz`RicPN?Xl4Z zS&rlwh)=Mbl{qMv!fm{X;V`XM%#uG{kYY%?@YKx7RYhJd(|zc(#I9!Ohr@x#McjRfZswWC@2=X(G%#NzsetEnabled(false); + mActionRenameProperty->setIcon(QIcon(QLatin1String(":/images/16x16/rename.png"))); + connect(mActionRenameProperty, SIGNAL(triggered()), + SLOT(renameProperty())); + Utils::setThemeIcon(mActionAddProperty, "add"); Utils::setThemeIcon(mActionRemoveProperty, "remove"); + Utils::setThemeIcon(mActionRenameProperty, "rename"); QToolBar *toolBar = new QToolBar; toolBar->setFloatable(false); @@ -69,6 +76,7 @@ PropertiesDock::PropertiesDock(QWidget *parent) toolBar->setIconSize(QSize(16, 16)); toolBar->addAction(mActionAddProperty); toolBar->addAction(mActionRemoveProperty); + toolBar->addAction(mActionRenameProperty); QWidget *widget = new QWidget(this); QVBoxLayout *layout = new QVBoxLayout(widget); @@ -150,6 +158,7 @@ void PropertiesDock::currentItemChanged(QtBrowserItem *item) bool isCustomProperty = mPropertyBrowser->isCustomPropertyItem(item); bool external = isExternal(mPropertyBrowser->object()); mActionRemoveProperty->setEnabled(isCustomProperty && !external); + mActionRenameProperty->setEnabled(isCustomProperty && !external); } void PropertiesDock::tilesetFileNameChanged(Tileset *tileset) @@ -219,6 +228,50 @@ void PropertiesDock::removeProperty() // TODO: Would be nice to automatically select the next property } +void PropertiesDock::renameProperty() +{ + QtBrowserItem *item = mPropertyBrowser->currentItem(); + if (!item) + return; + + //Getting back the current value of the property + QString oldname = item->property()->propertyName(); + + QInputDialog *dialog = new QInputDialog(mPropertyBrowser); + dialog->setInputMode(QInputDialog::TextInput); + dialog->setLabelText(tr("Name:")); + dialog->setTextValue(oldname); + dialog->setWindowTitle(tr("Rename Property")); + dialog->open(this, SLOT(renameProperty(QString))); +} + +void PropertiesDock::renameProperty(const QString &name) +{ + //Firt step : getting the property actual value + QtBrowserItem *item = mPropertyBrowser->currentItem(); + if (!item) + return; + QString oldvalue = item->property()->valueText(); + + //Then delete the 'old' property + removeProperty(); + + //Then create a new property with the new name + if (name.isEmpty()) + return; + Object *object = mMapDocument->currentObject(); + if (!object) + return; + + if (!object->hasProperty(name)) { + QUndoStack *undoStack = mMapDocument->undoStack(); + undoStack->push(new SetProperty(mMapDocument, mMapDocument->currentObjects(), name, oldvalue)); + } + + mPropertyBrowser->editCustomProperty(name); +} + + bool PropertiesDock::event(QEvent *event) { switch (event->type()) { @@ -248,6 +301,7 @@ void PropertiesDock::retranslateUi() mActionAddProperty->setText(tr("Add Property")); mActionRemoveProperty->setText(tr("Remove Property")); + mActionRenameProperty->setText(tr("Rename Property")); } } // namespace Internal diff --git a/src/tiled/propertiesdock.h b/src/tiled/propertiesdock.h index 95156a7247..faa0f28a6c 100644 --- a/src/tiled/propertiesdock.h +++ b/src/tiled/propertiesdock.h @@ -57,6 +57,8 @@ private slots: void addProperty(); void addProperty(const QString &name); void removeProperty(); + void renameProperty(); + void renameProperty(const QString &name); private: void retranslateUi(); @@ -65,6 +67,7 @@ private slots: PropertyBrowser *mPropertyBrowser; QAction *mActionAddProperty; QAction *mActionRemoveProperty; + QAction *mActionRenameProperty; }; } // namespace Internal diff --git a/src/tiled/tiled.qrc b/src/tiled/tiled.qrc index 8d721ed674..131a7f66c1 100644 --- a/src/tiled/tiled.qrc +++ b/src/tiled/tiled.qrc @@ -78,5 +78,6 @@ images/24x24/terrain-edit.png images/32x32/tiled.png images/24x24/move-image-layer.png + images/16x16/rename.png