1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
|
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/DFBrowser_SearchLineModel.hxx>
#include <inspector/DFBrowser_Module.hxx>
#include <inspector/DFBrowser_Tools.hxx>
#include <inspector/DFBrowserPane_AttributePane.hxx>
#include <inspector/DFBrowserPane_ItemRole.hxx>
#include <inspector/DFBrowserPane_Tools.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QDir>
#include <QIcon>
#include <Standard_WarningsRestore.hxx>
// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
DFBrowser_SearchLineModel::DFBrowser_SearchLineModel(QObject* theParent,
DFBrowser_Module* theModule)
: QAbstractTableModel(theParent),
myModule(theModule),
myRowCount(0)
{
}
// =======================================================================
// function : SetValues
// purpose :
// =======================================================================
void DFBrowser_SearchLineModel::SetValues(
const QMap<int, QMap<QString, DFBrowser_SearchItemInfo>>& theDocumentValues,
const QMap<int, QStringList>& theDocumentInfoValues)
{
myAdditionalValues = theDocumentValues;
myDocumentInfoValues = theDocumentInfoValues;
myRowCount = 0;
for (QMap<int, QStringList>::const_iterator aValuesIt = myDocumentInfoValues.begin();
aValuesIt != myDocumentInfoValues.end();
aValuesIt++)
myRowCount += aValuesIt.value().size();
}
// =======================================================================
// function : ClearValues
// purpose :
// =======================================================================
void DFBrowser_SearchLineModel::ClearValues()
{
myAdditionalValues.clear();
myDocumentInfoValues.clear();
myRowCount = 0;
}
// =======================================================================
// function : GetPath
// purpose :
// =======================================================================
QStringList DFBrowser_SearchLineModel::GetPath(const QModelIndex& theIndex) const
{
int aRowInDocument;
int aDocumentId = getDocumentId(theIndex.row(), aRowInDocument);
if (aDocumentId < 0)
return QStringList();
const QMap<QString, DFBrowser_SearchItemInfo>& anAdditionalValues =
myAdditionalValues[aDocumentId];
const QStringList& anInfoValues = myDocumentInfoValues[aDocumentId];
return anAdditionalValues[anInfoValues[aRowInDocument]].Path();
}
// =======================================================================
// function : GetValue
// purpose :
// =======================================================================
QString DFBrowser_SearchLineModel::GetValue(const QModelIndex& theIndex) const
{
int aRowInDocument;
int aDocumentId = getDocumentId(theIndex.row(), aRowInDocument);
if (aDocumentId < 0)
return QString();
QString aValue = myDocumentInfoValues[aDocumentId][aRowInDocument];
return aValue.mid(0, aValue.indexOf(SplitSeparator()));
}
// =======================================================================
// function : index
// purpose :
// =======================================================================
QModelIndex DFBrowser_SearchLineModel::index(int theRow,
int theColumn,
const QModelIndex& theParent) const
{
if (!hasIndex(theRow, theColumn, theParent))
return QModelIndex();
return createIndex(theRow, theColumn);
}
// =======================================================================
// function : data
// purpose :
// =======================================================================
QVariant DFBrowser_SearchLineModel::data(const QModelIndex& theIndex, int theRole) const
{
switch (theIndex.column())
{
case 0: {
if (theRole == Qt::DisplayRole || theRole == Qt::EditRole || theRole == Qt::ToolTipRole)
{
int aRowInDocument;
int aDocumentId = getDocumentId(theIndex.row(), aRowInDocument);
if (aDocumentId < 0)
return QVariant();
return myDocumentInfoValues[aDocumentId][aRowInDocument];
}
break;
}
case 1: {
if (theRole == Qt::DecorationRole)
{
int aRowInDocument;
int aDocumentId = getDocumentId(theIndex.row(), aRowInDocument);
if (aDocumentId < 0)
return QVariant();
QString anInfoValue = myDocumentInfoValues[aDocumentId][aRowInDocument];
QVariant anIcon = myAdditionalValues[aDocumentId][anInfoValue].Icon();
if (anIcon.isNull())
{
QString anAttributeName = anInfoValue.mid(0, anInfoValue.indexOf(SplitSeparator()));
anIcon = DFBrowser_Module::GetAttributeInfo(anAttributeName.toUtf8().data(),
myModule,
DFBrowserPane_ItemRole_Decoration_40x40,
0);
}
else
anIcon = DFBrowser_Tools::GetLabelIcon(TDF_Label(), false);
return anIcon;
}
if (theRole == Qt::SizeHintRole)
return QSize(80, 80);
break;
}
case 2: {
if (theRole == Qt::DisplayRole || theRole == Qt::EditRole)
{
int aRowInDocument;
int aDocumentId = getDocumentId(theIndex.row(), aRowInDocument);
if (aDocumentId < 0)
return QVariant();
QString anInfoValue = myDocumentInfoValues[aDocumentId][aRowInDocument];
return myAdditionalValues[aDocumentId][anInfoValue].PathUnited();
}
break;
}
default:
break;
}
return QVariant();
}
// =======================================================================
// function : emitLayoutChanged
// purpose :
// =======================================================================
void DFBrowser_SearchLineModel::EmitLayoutChanged()
{
emit layoutChanged();
}
// =======================================================================
// function : getDocumentId
// purpose :
// =======================================================================
int DFBrowser_SearchLineModel::getDocumentId(const int theRow, int& theRowInDocument) const
{
theRowInDocument = 0;
int aDocumentId = -1;
int aCurrentRow = theRow;
for (int aValueId = 0, aSize = myDocumentInfoValues.size(); aValueId < aSize; aValueId++)
{
int aValueIndex = aValueId + 1;
if (!myDocumentInfoValues.contains(aValueIndex))
continue;
QStringList aValues = myDocumentInfoValues[aValueIndex];
int aValuesSize = aValues.size();
if (aCurrentRow < aValuesSize)
{
aDocumentId = aValueIndex;
theRowInDocument = aCurrentRow;
}
else
aCurrentRow = aCurrentRow - aValuesSize;
}
return aDocumentId;
}
|