Use QInputDialog in Classes widget

This commit is contained in:
itayc0hen 2020-06-14 11:51:43 +03:00 committed by Itay Cohen
parent 3b2abf4984
commit 9c0d5d72d1

View File

@ -4,11 +4,11 @@
#include "common/Helpers.h" #include "common/Helpers.h"
#include "common/SvgIconEngine.h" #include "common/SvgIconEngine.h"
#include "dialogs/EditMethodDialog.h" #include "dialogs/EditMethodDialog.h"
#include "dialogs/RenameDialog.h"
#include <QList> #include <QList>
#include <QMenu> #include <QMenu>
#include <QMouseEvent> #include <QMouseEvent>
#include <QInputDialog>
QVariant ClassesModel::headerData(int section, Qt::Orientation, int role) const QVariant ClassesModel::headerData(int section, Qt::Orientation, int role) const
{ {
@ -740,14 +740,14 @@ void ClassesWidget::on_editMethodAction_triggered()
EditMethodDialog::editMethod(className, methName, this); EditMethodDialog::editMethod(className, methName, this);
} }
void ClassesWidget::on_newClassAction_triggered() void ClassesWidget::on_newClassAction_triggered()
{ {
QString name; bool ok;
if (!RenameDialog::showDialog(tr("Create new Class"), &name, tr("Class Name"), this) || name.isEmpty()) { QString name = QInputDialog::getText(this, tr("Create new Class"),
return; tr("Class Name:"), QLineEdit::Normal, QString(), &ok);
} if (ok && !name.isEmpty()) {
Core()->createNewClass(name); Core()->createNewClass(name);
}
} }
void ClassesWidget::on_deleteClassAction_triggered() void ClassesWidget::on_deleteClassAction_triggered()
@ -770,9 +770,10 @@ void ClassesWidget::on_renameClassAction_triggered()
return; return;
} }
QString oldName = index.data(ClassesModel::NameRole).toString(); QString oldName = index.data(ClassesModel::NameRole).toString();
QString newName = oldName; bool ok;
if (!RenameDialog::showDialog(tr("Rename Class %1").arg(oldName), &newName, tr("Class Name"), this) || newName.isEmpty()) { QString newName = QInputDialog::getText(this, tr("Rename Class %1").arg(oldName),
return; tr("Class name:"), QLineEdit::Normal, oldName, &ok);
} if (ok && !newName.isEmpty()) {
Core()->renameClass(oldName, newName); Core()->renameClass(oldName, newName);
}
} }