From ee29bb41dc9c4d4dd6fc9bfd3fb9ad5cc3bd1569 Mon Sep 17 00:00:00 2001 From: Arno Date: Fri, 2 Mar 2012 20:08:40 +0100 Subject: Make it possible to move mappings Move mappings by context menu. Select new parent by QComboBox with available paths, items separated by "/". Note that hell will break loose if a mapping name contains "/". Will be fixed later. Since mapping views don't have setSortingEnabled(), make SmTreeModel::addRow() sort items. This fixes a long standing bug in SmTreeModel::reparent(): Since it alters the model, newParent has to be a QPersistentModelIndex to stay consistent. --- mappingtreemodel.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'mappingtreemodel.h') diff --git a/mappingtreemodel.h b/mappingtreemodel.h index 60c7bd4..c8ee8ee 100644 --- a/mappingtreemodel.h +++ b/mappingtreemodel.h @@ -34,7 +34,9 @@ class MappingTreeModel : public SmTreeModel { //data QVariant data(const QModelIndex &index, int role) const; + QModelIndex indexFromPath(QString &path, int column = 0) const; bool setData(const QModelIndex &index, const QVariant &value, int role); + void move(const QModelIndex &source, const QModelIndex &dest); bool addMappingType(const QString &type); bool deleteMappingType(int typeId); bool addChild(const QVariant &name, const QModelIndex &parent); @@ -42,6 +44,7 @@ class MappingTreeModel : public SmTreeModel { int childCount(const QModelIndex &idx) const; MappingData mappingDataFromId(int mappingId) const; void setSelectedMappings(const QList &mappingData); + QStringList paths() const; public slots: void populate(); @@ -58,6 +61,8 @@ class MappingTreeModel : public SmTreeModel { }; void getMappingTypes(); void getChildrenRecursive(SmTreeItem *item); + QStringList getPathsRecursive(SmTreeItem *parent) const; + QString basePath(SmTreeItem *item) const; int lowerBound(SmTreeItem *item, const QVariant &value, int column = 0) const; QList mappingData(SmTreeItem *item); QSqlDatabase mDb; @@ -71,6 +76,8 @@ class MappingTreeModel : public SmTreeModel { QSqlQuery *mSelectChildQ; QSqlQuery *mAddParentQ; QSqlQuery *mDeleteChildQ; + QSqlQuery *mUpdateParentQ; + QSqlQuery *mDeleteMappingParentQ; QList mMappingTypes; QList mValidMappings; QList mSelectedMappings; -- cgit v1.2.3-70-g09d2