Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to rename custom properties #803

Merged
merged 1 commit into from
Oct 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added src/tiled/images/16x16/rename.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions src/tiled/propertiesdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,23 @@ PropertiesDock::PropertiesDock(QWidget *parent)
connect(mActionRemoveProperty, SIGNAL(triggered()),
SLOT(removeProperty()));

mActionRenameProperty = new QAction(this);
mActionRenameProperty->setEnabled(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);
toolBar->setMovable(false);
toolBar->setIconSize(QSize(16, 16));
toolBar->addAction(mActionAddProperty);
toolBar->addAction(mActionRemoveProperty);
toolBar->addAction(mActionRenameProperty);

QWidget *widget = new QWidget(this);
QVBoxLayout *layout = new QVBoxLayout(widget);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -248,6 +301,7 @@ void PropertiesDock::retranslateUi()

mActionAddProperty->setText(tr("Add Property"));
mActionRemoveProperty->setText(tr("Remove Property"));
mActionRenameProperty->setText(tr("Rename Property"));
}

} // namespace Internal
Expand Down
3 changes: 3 additions & 0 deletions src/tiled/propertiesdock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -65,6 +67,7 @@ private slots:
PropertyBrowser *mPropertyBrowser;
QAction *mActionAddProperty;
QAction *mActionRemoveProperty;
QAction *mActionRenameProperty;
};

} // namespace Internal
Expand Down
1 change: 1 addition & 0 deletions src/tiled/tiled.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@
<file>images/24x24/terrain-edit.png</file>
<file>images/32x32/tiled.png</file>
<file>images/24x24/move-image-layer.png</file>
<file>images/16x16/rename.png</file>
</qresource>
</RCC>