mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-19 13:40:49 +03:00
0027398: Integrate Qt Browser Widget to Open CASCADE Technology
The following implementation has been made: - CMake procedure is extended to compile Qt tools. This is optional and is handled by USE_QT_TOOLS option(OFF by default) - It is possible to build Qt tools using Qt5 or Qt4, it is settled with USE_QT4 option. - Sample of DFBrowser tool is available in samples/tools/TInspectorEXE. It is build with tools, executable is placed in binaries. To start the sample, use dfbrowser.bat command. - DFBrowser tool may be started from DRAW
This commit is contained in:
148
tools/DFBrowserPane/DFBrowserPane_AttributePaneModel.cxx
Normal file
148
tools/DFBrowserPane/DFBrowserPane_AttributePaneModel.cxx
Normal file
@@ -0,0 +1,148 @@
|
||||
// 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 <DFBrowserPane_AttributePaneModel.hxx>
|
||||
|
||||
// =======================================================================
|
||||
// function : Constructor
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
DFBrowserPane_AttributePaneModel::DFBrowserPane_AttributePaneModel (QObject* theParent)
|
||||
: QAbstractTableModel (theParent), myOrientation (Qt::Vertical), myColumnCount (1)
|
||||
{
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Init
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void DFBrowserPane_AttributePaneModel::Init (const QList<QVariant>& theValues)
|
||||
{
|
||||
myValuesMap.clear();
|
||||
|
||||
if (myOrientation == Qt::Vertical)
|
||||
{
|
||||
int aRows = theValues.size() / myColumnCount;
|
||||
QList<QVariant> aRowValues;
|
||||
int aValuesIndex = 0;
|
||||
for (int aRowId = 0; aRowId < aRows; aRowId++)
|
||||
{
|
||||
aRowValues.clear();
|
||||
for (int aColumnId = 0; aColumnId < myColumnCount; aColumnId++)
|
||||
{
|
||||
aRowValues.append (theValues[aValuesIndex]);
|
||||
aValuesIndex++;
|
||||
}
|
||||
myValuesMap[aRowId] = aRowValues;
|
||||
}
|
||||
}
|
||||
else {
|
||||
int aCols = theValues.size() / myColumnCount;
|
||||
QList<QVariant> aColValues;
|
||||
int aValuesIndex = 0;
|
||||
for (int aColumnId = 0; aColumnId < aCols; aColumnId++)
|
||||
{
|
||||
aColValues.clear();
|
||||
for (int aRowId = 0; aRowId < myColumnCount; aRowId++)
|
||||
{
|
||||
aColValues.append (theValues[aValuesIndex]);
|
||||
aValuesIndex++;
|
||||
}
|
||||
myValuesMap[aColumnId] = aColValues;
|
||||
}
|
||||
}
|
||||
emit layoutChanged();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : SetHeaderValues
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void DFBrowserPane_AttributePaneModel::SetHeaderValues (const QList<QVariant>& theValues,
|
||||
Qt::Orientation theOrientation)
|
||||
{
|
||||
if (theOrientation == Qt::Horizontal)
|
||||
myHorizontalHeaderValues = theValues;
|
||||
else
|
||||
myVerticalHeaderValues = theValues;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : columnCount
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
int DFBrowserPane_AttributePaneModel::columnCount (const QModelIndex&/* theParent*/) const
|
||||
{
|
||||
return myOrientation == Qt::Vertical ? myColumnCount : myValuesMap.size();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : rowCount
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
int DFBrowserPane_AttributePaneModel::rowCount (const QModelIndex&/* theParent*/) const
|
||||
{
|
||||
return myOrientation == Qt::Vertical ? myValuesMap.size() : myColumnCount;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : data
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
QVariant DFBrowserPane_AttributePaneModel::data (const QModelIndex& theIndex, int theRole) const
|
||||
{
|
||||
QVariant aValue;
|
||||
|
||||
if (theRole == Qt::DisplayRole)
|
||||
{
|
||||
if (myOrientation == Qt::Vertical)
|
||||
{
|
||||
int aRowId = theIndex.row();
|
||||
QList<QVariant> aRowValues = myValuesMap[aRowId];
|
||||
aValue = aRowValues.at (theIndex.column());
|
||||
}
|
||||
else
|
||||
{
|
||||
int aColId = theIndex.column();
|
||||
QList<QVariant> aColValues = myValuesMap[aColId];
|
||||
aValue = aColValues.at (theIndex.row());
|
||||
}
|
||||
}
|
||||
return aValue;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : headerData
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
QVariant DFBrowserPane_AttributePaneModel::headerData (int theSection, Qt::Orientation theOrientation,
|
||||
int theRole) const
|
||||
{
|
||||
QVariant aValue = QAbstractTableModel::headerData (theSection, theOrientation, theRole);
|
||||
if (theRole == Qt::DisplayRole)
|
||||
{
|
||||
if (theOrientation == Qt::Horizontal)
|
||||
{
|
||||
if (!myHorizontalHeaderValues.empty() && theSection < myHorizontalHeaderValues.size())
|
||||
aValue = myHorizontalHeaderValues[theSection];
|
||||
}
|
||||
else
|
||||
{ // vertical
|
||||
if (!myVerticalHeaderValues.empty() && theSection < myVerticalHeaderValues.size())
|
||||
aValue = myVerticalHeaderValues[theSection];
|
||||
}
|
||||
}
|
||||
return aValue;
|
||||
}
|
Reference in New Issue
Block a user