From 11bf52b6cf1c27a75715a8379e7893b8d1e16bf0 Mon Sep 17 00:00:00 2001 From: Arno Date: Sun, 26 Feb 2012 14:15:45 +0100 Subject: Mark active Mappings When selecting pictures, mark the active mappings with a different color. --- mappingtreemodel.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'mappingtreemodel.cpp') diff --git a/mappingtreemodel.cpp b/mappingtreemodel.cpp index 4cd3f29..8872d45 100644 --- a/mappingtreemodel.cpp +++ b/mappingtreemodel.cpp @@ -94,6 +94,12 @@ QVariant MappingTreeModel::data(const QModelIndex &index, int role) const{ if(role == AddedRole){ return item->data(Added); } + if(role == Qt::ForegroundRole){ + int id = item->data(Id).toInt(); + if(mSelectedMappings.contains(id)){ + return QColor(Qt::blue); + } + } return SmTreeModel::data(index, role); } @@ -180,6 +186,8 @@ bool MappingTreeModel::addChild(const QVariant &name, const QModelIndex &parent) mAddParentQ->bindValue(":parentid", pItem->data(Id)); mAddParentQ->exec(); } + mValidMappings.clear(); + mValidMappings = mappingData(root()); return true; } } @@ -197,6 +205,8 @@ bool MappingTreeModel::deleteChild(const QModelIndex &idx){ mDeleteChildQ->bindValue(":id", item->data(Id)); if(mDeleteChildQ->exec()){ removeRows(idx.row(), 1, idx.parent()); + mValidMappings.clear(); + mValidMappings = mappingData(root()); return true; } return false; @@ -210,6 +220,30 @@ int MappingTreeModel::childCount(const QModelIndex &idx) const{ return item->childCount(); } +MappingData MappingTreeModel::mappingDataFromId(int mappingId) const{ + MappingData retval = { -1, QString(), QStringList() }; + foreach(MappingData d, mValidMappings){ + if(d.id == mappingId){ + retval = d; + break; + } + } + return retval; +} + +void MappingTreeModel::setSelectedMappings(const QList &mappingIds){ + mSelectedMappings = mappingIds; + /*foreach(int id, mappingIds){ + QModelIndex idx = findRecursive(id, Id); + if(idx.isValid()){ + emit dataChanged(idx, idx); + } + }*/ + beginResetModel(); + endResetModel(); + emit needExpansion(); +} + void MappingTreeModel::populate(){ if(mType == -1){ return; @@ -231,6 +265,8 @@ void MappingTreeModel::populate(){ getChildrenRecursive(childItem); } setRoot(rootItem); + mValidMappings.clear(); + mValidMappings = mappingData(root()); emit needExpansion(); } } @@ -274,6 +310,26 @@ int MappingTreeModel::lowerBound(SmTreeItem *item, const QVariant &value, int co return item->childCount(); } +QList MappingTreeModel::mappingData(SmTreeItem *item){ + QList retval; + if(item->childCount() > 0){ + for(int i = 0; i < item->childCount(); ++i){ + retval << mappingData(item->child(i)); + } + } + MappingData mapItem = { item->data(Id).toInt(), item->data(Name).toString(), QStringList() }; + QStringList path; + SmTreeItem *p = item; + while(p->parent()){ + path << p->data(Name).toString(); + p = p->parent(); + } + std::reverse(path.begin(), path.end()); + mapItem.path = path; + retval << mapItem; + return retval; +} + MappingTreeResultModel::MappingTreeResultModel(const QStringList &headers, QObject *parent) : SmTreeModel(headers, parent) { } Qt::ItemFlags MappingTreeResultModel::flags(const QModelIndex &index) const { -- cgit v1.2.3-70-g09d2