diff options
| author | Arno <am@disconnect.de> | 2012-02-26 14:15:45 +0100 | 
|---|---|---|
| committer | Arno <am@disconnect.de> | 2012-02-26 14:15:45 +0100 | 
| commit | 11bf52b6cf1c27a75715a8379e7893b8d1e16bf0 (patch) | |
| tree | d0d5366c585fb482716f44db3f9e22ea8acd914c /mappingtreemodel.cpp | |
| parent | ff4a70f50e42152c5c391fd7801b916e64b181a4 (diff) | |
| download | SheMov-11bf52b6cf1c27a75715a8379e7893b8d1e16bf0.tar.gz SheMov-11bf52b6cf1c27a75715a8379e7893b8d1e16bf0.tar.bz2 SheMov-11bf52b6cf1c27a75715a8379e7893b8d1e16bf0.zip  | |
Mark active Mappings
When selecting pictures, mark the active mappings with a different
color.
Diffstat (limited to 'mappingtreemodel.cpp')
| -rw-r--r-- | mappingtreemodel.cpp | 56 | 
1 files changed, 56 insertions, 0 deletions
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<int> &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<MappingData> MappingTreeModel::mappingData(SmTreeItem *item){ +    QList<MappingData> 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 {  | 
