diff options
-rw-r--r-- | mappingtreemodel.cpp | 16 | ||||
-rw-r--r-- | mappingtreemodel.h | 1 | ||||
-rw-r--r-- | mappingtreewidget.cpp | 10 |
3 files changed, 25 insertions, 2 deletions
diff --git a/mappingtreemodel.cpp b/mappingtreemodel.cpp index 9650e77..25969cb 100644 --- a/mappingtreemodel.cpp +++ b/mappingtreemodel.cpp @@ -232,6 +232,22 @@ bool MappingTreeModel::addChild(const QVariant &name, const QModelIndex &parent) return false; } +bool MappingTreeModel::renameChild(const QModelIndex &idx, const QString newName){ + if(!idx.isValid()){ + return false; + } + int descId = idx.data(DescIdRole).toInt(); + QSqlQuery renameQ(mDb); + renameQ.prepare("UPDATE mapping_description SET tdescription_name = :name WHERE idescription_id = :id"); + renameQ.bindValue(":id", descId); + renameQ.bindValue(":name", newName); + if(renameQ.exec()){ + populate(); + return true; + } + return false; +} + bool MappingTreeModel::deleteChild(const QModelIndex &idx){ if(!idx.isValid()){ return false; diff --git a/mappingtreemodel.h b/mappingtreemodel.h index c28967a..ec30fb3 100644 --- a/mappingtreemodel.h +++ b/mappingtreemodel.h @@ -44,6 +44,7 @@ class MappingTreeModel : public SmTreeModel { bool addMappingType(const QString &type); bool deleteMappingType(int typeId); bool addChild(const QVariant &name, const QModelIndex &parent); + bool renameChild(const QModelIndex &idx, const QString newName); bool deleteChild(const QModelIndex &idx); MappingData mappingDataFromIndex(QModelIndex &idx) const; QStringList paths() const; diff --git a/mappingtreewidget.cpp b/mappingtreewidget.cpp index 1bb093f..873afd2 100644 --- a/mappingtreewidget.cpp +++ b/mappingtreewidget.cpp @@ -226,8 +226,14 @@ void MappingTreeWidget::typeChanged(QString type){ void MappingTreeWidget::editChild(){ QModelIndex sel = selected(); - if(sel.isValid()){ - mTree->edit(sel); + QString question = QString("Rename %1").arg(sel.data(MappingTreeModel::NameRole).toString()); + bool ok = false; + QString newName = QInputDialog::getText(mTree, tr("Rename"), question, QLineEdit::Normal, sel.data(MappingTreeModel::NameRole).toString(), &ok); + if(ok){ + QModelIndex real = mProxy->mapToSource(sel); + if(real.isValid()){ + mModel->renameChild(real, newName); + } } } |