00001 #include "ItemModelHelper.h"
00002
00003
00004 #include <QDebug>
00005
00006
00007 QModelIndex findSgNodeInModel(const SgNode * node,
00008 const QAbstractItemModel & model,
00009 const QModelIndex & subTreeInd,
00010 int column)
00011 {
00012 if(node==NULL)
00013 return QModelIndex();
00014
00015 for(int r=0; r < model.rowCount(subTreeInd); r++ )
00016 {
00017 QModelIndex curInd = model.index(r,column,subTreeInd);
00018 SgNode * inModel = qvariant_cast<SgNode*> ( model.data(curInd,SgNodeRole)) ;
00019 if(inModel == node)
00020 return curInd;
00021 else
00022 {
00023 QModelIndex subTreeRes = findSgNodeInModel(node,model,curInd);
00024 if(subTreeRes.isValid())
00025 return subTreeRes;
00026 }
00027 }
00028
00029 return QModelIndex();
00030 }
00031
00032
00033 QModelIndex findVariantInModel(const QVariant & value,
00034 const QAbstractItemModel & model,
00035 int role,
00036 const QModelIndex & subTreeInd,
00037 int column)
00038 {
00039 for(int r=0; r < model.rowCount(subTreeInd); r++ )
00040 {
00041 QModelIndex curInd = model.index(r,column,subTreeInd);
00042 QVariant inModel = model.data(curInd,role) ;
00043 if(inModel == value)
00044 return curInd;
00045 else
00046 {
00047 QModelIndex subTreeRes = findVariantInModel(value,model,role,curInd,column);
00048 if(subTreeRes.isValid())
00049 return subTreeRes;
00050 }
00051 }
00052
00053 return QModelIndex();
00054 }
00055
00056
00057