-// Copyright (C) 2013-2015 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2013-2023 CEA, EDF, OPEN CASCADE
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include "CurveCreator_TreeView.h"
#include "CurveCreator_ICurve.hxx"
+#include "CurveCreator_Curve.hxx"
+#include "CurveCreator_Utils.hxx"
#include <SUIT_Session.h>
#include <SUIT_ResourceMgr.h>
#define ID_SECTION -1
-CurveCreator_TreeViewModel::CurveCreator_TreeViewModel( CurveCreator_ICurve* theCurve, QObject* parent ) :
- QAbstractItemModel(parent), myCurve(theCurve)
+CurveCreator_TreeViewModel::CurveCreator_TreeViewModel( CurveCreator_ICurve* theCurve, QObject* parent, bool toDrawColorIcon ) :
+ QAbstractItemModel(parent), myCurve(theCurve), myDrawColorIcon(toDrawColorIcon)
{
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
QPixmap aSplineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE")));
int CurveCreator_TreeViewModel::columnCount(const QModelIndex & parent ) const
{
- if( parent.internalId() == ID_SECTION )
- return 2;
+ if( myDrawColorIcon )
+ return 3;
else
return 2;
}
int aRow = index.row();
int aColumn = index.column();
if( myCurve ){
- if( index.internalId() == ID_SECTION ){
+ if( index.internalId() == (quintptr)ID_SECTION ){
if( role == Qt::DisplayRole ){
if( aColumn == 0 )
return QString::fromStdString(myCurve->getSectionName(aRow));
}
}
}
+ else if (myDrawColorIcon && aColumn == 2)
+ {
+ Quantity_Color color = ((CurveCreator_Curve*)myCurve)->getColorSection(aRow);
+ QPixmap pixmap(16,16);
+ pixmap.fill( CurveCreator_Utils::colorConv(color));
+ return pixmap;
+ }
}
}
/* else{
if( !theIndex.isValid() )
return QModelIndex();
- if( theIndex.internalId() == ID_SECTION ){
+ if( theIndex.internalId() == (quintptr)ID_SECTION ){
return QModelIndex();
}
return createIndex( theIndex.internalId(), 0, ID_SECTION );
aRowCnt = myCurve->getNbSections();
}
else{
- if( parent.internalId() == ID_SECTION ){
+ if( parent.internalId() == (quintptr)ID_SECTION ){
//Points level
aRowCnt = myCurve->getNbPoints(parent.row());
}
bool CurveCreator_TreeViewModel::isSection( const QModelIndex& theIndx ) const
{
- if( theIndx.internalId() == ID_SECTION )
+ if( theIndx.internalId() == (quintptr)ID_SECTION )
return true;
return false;
}
int CurveCreator_TreeViewModel::getSection( const QModelIndex& theIndx ) const
{
- if( theIndx.internalId() == ID_SECTION )
+ if( theIndx.internalId() == (quintptr)ID_SECTION )
return theIndx.row();
return theIndx.internalId();
}
int CurveCreator_TreeViewModel::getPoint( const QModelIndex& theIndx ) const
{
- if( theIndx.internalId() == ID_SECTION )
+ if( theIndx.internalId() == (quintptr)ID_SECTION )
return -1;
return theIndx.row();
}
void CurveCreator_TreeViewModel::setCurve( CurveCreator_ICurve* theCurve )
{
+ beginResetModel();
myCurve = theCurve;
-#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
- reset();
-#endif
+ endResetModel();
}
/*****************************************************************************************/
-CurveCreator_TreeView::CurveCreator_TreeView( CurveCreator_ICurve* theCurve, QWidget *parent) :
+CurveCreator_TreeView::CurveCreator_TreeView( CurveCreator_ICurve* theCurve, QWidget *parent, bool toDrawColorIcon) :
QTreeView(parent)
{
header()->hide();
-#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
- header()->setResizeMode(QHeaderView::ResizeToContents);
-#else
header()->setSectionResizeMode(QHeaderView::ResizeToContents);
-#endif
setUniformRowHeights(true);
setContextMenuPolicy( Qt::CustomContextMenu );
- CurveCreator_TreeViewModel* aModel = new CurveCreator_TreeViewModel(theCurve, this);
+ CurveCreator_TreeViewModel* aModel = new CurveCreator_TreeViewModel(theCurve, this, toDrawColorIcon);
setModel(aModel);
setSelectionBehavior(SelectRows);
setSelectionMode(SingleSelection);
}
}
-void CurveCreator_TreeView::setIndexState( const QModelIndex& theIndx, bool& isExpanded, bool& isSelected, bool& isCurrent )
+void CurveCreator_TreeView::setIndexState( const QModelIndex& theIndx, bool& isExpanded, bool& isSelected, bool& /*isCurrent*/ ) // todo: isCurrent is not set!
{
setExpanded( theIndx, isExpanded );
QItemSelectionModel::SelectionFlags aFlag = QItemSelectionModel::Select;