mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +03:00
Coding - Apply .clang-format formatting #286
Update empty method guards to new style with regex (see PR). Used clang-format 18.1.8. New actions to validate code formatting is added. Update .clang-format with disabling of include sorting. It is temporary changes, then include will be sorted. Apply formatting for /src and /tools folder. The files with .hxx,.cxx,.lxx,.h,.pxx,.hpp,*.cpp extensions.
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
// 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.
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef TreeModel_ColumnType_H
|
||||
#define TreeModel_ColumnType_H
|
||||
@@ -23,9 +23,9 @@
|
||||
//! Sets custom item role of Tree view wmodel
|
||||
enum TreeModel_ColumnType
|
||||
{
|
||||
TreeModel_ColumnType_Name = 0, //! name column
|
||||
TreeModel_ColumnType_Name = 0, //! name column
|
||||
TreeModel_ColumnType_Visibility, //! visibility state column
|
||||
TreeModel_ColumnType_Row //! row of the item column
|
||||
TreeModel_ColumnType_Row //! row of the item column
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -11,7 +11,7 @@
|
||||
// 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.
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <inspector/TreeModel_ContextMenu.hxx>
|
||||
#include <inspector/TreeModel_ModelBase.hxx>
|
||||
@@ -29,45 +29,51 @@
|
||||
// function : Constructor
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
TreeModel_ContextMenu::TreeModel_ContextMenu (QTreeView* theTreeView)
|
||||
: QObject (theTreeView), myTreeView (theTreeView)
|
||||
TreeModel_ContextMenu::TreeModel_ContextMenu(QTreeView* theTreeView)
|
||||
: QObject(theTreeView),
|
||||
myTreeView(theTreeView)
|
||||
{
|
||||
myTreeView->header()->setContextMenuPolicy (Qt::CustomContextMenu);
|
||||
myTreeView->header()->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
#if QT_VERSION >= 0x050000
|
||||
myTreeView->header()->setSectionsClickable (true);
|
||||
myTreeView->header()->setSectionsClickable(true);
|
||||
#endif
|
||||
myTreeView->header()->setHighlightSections (true);
|
||||
connect (myTreeView->header(), SIGNAL (customContextMenuRequested (const QPoint&)),
|
||||
this, SLOT (onTreeViewHeaderContextMenuRequested (const QPoint&)));
|
||||
myTreeView->header()->setHighlightSections(true);
|
||||
connect(myTreeView->header(),
|
||||
SIGNAL(customContextMenuRequested(const QPoint&)),
|
||||
this,
|
||||
SLOT(onTreeViewHeaderContextMenuRequested(const QPoint&)));
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : onTreeViewHeaderContextMenuRequested
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void TreeModel_ContextMenu::onTreeViewHeaderContextMenuRequested (const QPoint& thePosition)
|
||||
void TreeModel_ContextMenu::onTreeViewHeaderContextMenuRequested(const QPoint& thePosition)
|
||||
{
|
||||
TreeModel_ModelBase* aModel = dynamic_cast<TreeModel_ModelBase*> (myTreeView->model());
|
||||
TreeModel_ModelBase* aModel = dynamic_cast<TreeModel_ModelBase*>(myTreeView->model());
|
||||
if (!aModel)
|
||||
return;
|
||||
|
||||
QMenu* aMenu = new QMenu (myTreeView);
|
||||
int aNbSections = aModel->columnCount();
|
||||
QMenu* aMenu = new QMenu(myTreeView);
|
||||
int aNbSections = aModel->columnCount();
|
||||
for (int aColumnId = 0; aColumnId < aNbSections; aColumnId++)
|
||||
{
|
||||
QAction* anAction = ViewControl_Tools::CreateAction (aModel->ChangeHeaderItem (aColumnId)->GetName(),
|
||||
SLOT (onColumnVisibilityChanged()), myTreeView, this);
|
||||
anAction->setCheckable (true);
|
||||
anAction->setChecked (!myTreeView->isColumnHidden (aColumnId));
|
||||
anAction->setData (aColumnId);
|
||||
aMenu->addAction (anAction);
|
||||
QAction* anAction =
|
||||
ViewControl_Tools::CreateAction(aModel->ChangeHeaderItem(aColumnId)->GetName(),
|
||||
SLOT(onColumnVisibilityChanged()),
|
||||
myTreeView,
|
||||
this);
|
||||
anAction->setCheckable(true);
|
||||
anAction->setChecked(!myTreeView->isColumnHidden(aColumnId));
|
||||
anAction->setData(aColumnId);
|
||||
aMenu->addAction(anAction);
|
||||
}
|
||||
|
||||
if (aMenu->actions().isEmpty())
|
||||
return;
|
||||
|
||||
QPoint aPoint = myTreeView->mapToGlobal (thePosition);
|
||||
aMenu->exec (aPoint);
|
||||
QPoint aPoint = myTreeView->mapToGlobal(thePosition);
|
||||
aMenu->exec(aPoint);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
|
@@ -11,7 +11,7 @@
|
||||
// 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.
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef TreeModel_ContextMenu_H
|
||||
#define TreeModel_ContextMenu_H
|
||||
@@ -33,7 +33,7 @@ class TreeModel_ContextMenu : public QObject
|
||||
Q_OBJECT
|
||||
public:
|
||||
//! Constructor
|
||||
Standard_EXPORT TreeModel_ContextMenu (QTreeView* theTreeView);
|
||||
Standard_EXPORT TreeModel_ContextMenu(QTreeView* theTreeView);
|
||||
|
||||
//! Destructor
|
||||
~TreeModel_ContextMenu() {}
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
protected slots:
|
||||
//! Shows context menu for tree view header. It contains actions to change columns visibility.
|
||||
//! \param thePosition a clicked point
|
||||
void onTreeViewHeaderContextMenuRequested (const QPoint& thePosition);
|
||||
void onTreeViewHeaderContextMenuRequested(const QPoint& thePosition);
|
||||
|
||||
//! Changes clicked column visibility
|
||||
void onColumnVisibilityChanged();
|
||||
|
@@ -11,7 +11,7 @@
|
||||
// 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.
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef TreeModel_HeaderSection_H
|
||||
#define TreeModel_HeaderSection_H
|
||||
@@ -31,12 +31,25 @@ class TreeModel_HeaderSection
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
TreeModel_HeaderSection() : myName(), myWidth (-1), myIsHidden (false), myIsItalic (false) {}
|
||||
TreeModel_HeaderSection()
|
||||
: myName(),
|
||||
myWidth(-1),
|
||||
myIsHidden(false),
|
||||
myIsItalic(false)
|
||||
{
|
||||
}
|
||||
|
||||
//! Constructor
|
||||
TreeModel_HeaderSection (const QString& theName, const int theWidth = -1, const bool theIsHidden = false,
|
||||
const bool theIsItalic = false)
|
||||
: myName (theName), myWidth (theWidth), myIsHidden (theIsHidden), myIsItalic (theIsItalic) {}
|
||||
TreeModel_HeaderSection(const QString& theName,
|
||||
const int theWidth = -1,
|
||||
const bool theIsHidden = false,
|
||||
const bool theIsItalic = false)
|
||||
: myName(theName),
|
||||
myWidth(theWidth),
|
||||
myIsHidden(theIsHidden),
|
||||
myIsItalic(theIsItalic)
|
||||
{
|
||||
}
|
||||
|
||||
//! Destructor
|
||||
~TreeModel_HeaderSection() {}
|
||||
@@ -48,36 +61,39 @@ public:
|
||||
|
||||
//! Sets text value
|
||||
//! \theName text value
|
||||
void SetName (const QString& theName) { myName = theName; }
|
||||
void SetName(const QString& theName) { myName = theName; }
|
||||
|
||||
//! Returns text value
|
||||
QString GetName() const { return myName; }
|
||||
|
||||
//! Sets section width
|
||||
//! \param theValue width value
|
||||
void SetWidth (const int theWidth) { myWidth = theWidth; }
|
||||
void SetWidth(const int theWidth) { myWidth = theWidth; }
|
||||
|
||||
//! Returns section width
|
||||
int GetWidth (const bool isComputeDefault = true) const
|
||||
{ return (myWidth ==-1 && isComputeDefault) ? TreeModel_Tools::GetTextWidth (GetName(), 0) : myWidth; }
|
||||
int GetWidth(const bool isComputeDefault = true) const
|
||||
{
|
||||
return (myWidth == -1 && isComputeDefault) ? TreeModel_Tools::GetTextWidth(GetName(), 0)
|
||||
: myWidth;
|
||||
}
|
||||
|
||||
//! Sets section width
|
||||
void SetIsHidden (bool isHidden) { myIsHidden = isHidden; }
|
||||
void SetIsHidden(bool isHidden) { myIsHidden = isHidden; }
|
||||
|
||||
//! Returns if the section is visiblt
|
||||
bool IsHidden() const { return myIsHidden; }
|
||||
|
||||
//! Sets section width
|
||||
void SetIsItalic (bool isItalic) { myIsItalic = isItalic; }
|
||||
void SetIsItalic(bool isItalic) { myIsItalic = isItalic; }
|
||||
|
||||
//! Returns if the section is visiblt
|
||||
bool IsItalic() const { return myIsItalic; }
|
||||
|
||||
private:
|
||||
QString myName; //!< text value
|
||||
int myWidth; //!< section width
|
||||
bool myIsHidden; //!< visibility
|
||||
bool myIsItalic; //!< italic
|
||||
QString myName; //!< text value
|
||||
int myWidth; //!< section width
|
||||
bool myIsHidden; //!< visibility
|
||||
bool myIsItalic; //!< italic
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -11,7 +11,7 @@
|
||||
// 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.
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <inspector/TreeModel_ColumnType.hxx>
|
||||
#include <inspector/TreeModel_ItemBase.hxx>
|
||||
@@ -28,11 +28,14 @@
|
||||
// function : Constructor
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
TreeModel_ItemBase::TreeModel_ItemBase (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
|
||||
: m_iStreamChildren (0), m_bInitialized (false)
|
||||
TreeModel_ItemBase::TreeModel_ItemBase(TreeModel_ItemBasePtr theParent,
|
||||
const int theRow,
|
||||
const int theColumn)
|
||||
: m_iStreamChildren(0),
|
||||
m_bInitialized(false)
|
||||
{
|
||||
m_pParent = theParent;
|
||||
m_iRow = theRow;
|
||||
m_iRow = theRow;
|
||||
m_iColumn = theColumn;
|
||||
}
|
||||
|
||||
@@ -42,7 +45,9 @@ TreeModel_ItemBase::TreeModel_ItemBase (TreeModel_ItemBasePtr theParent, const i
|
||||
// =======================================================================
|
||||
void TreeModel_ItemBase::Reset()
|
||||
{
|
||||
for (PositionToItemHash::const_iterator aChildrenIt = m_ChildItems.begin(); aChildrenIt != m_ChildItems.end(); aChildrenIt++)
|
||||
for (PositionToItemHash::const_iterator aChildrenIt = m_ChildItems.begin();
|
||||
aChildrenIt != m_ChildItems.end();
|
||||
aChildrenIt++)
|
||||
{
|
||||
TreeModel_ItemBasePtr anItem = aChildrenIt.value();
|
||||
if (anItem)
|
||||
@@ -54,38 +59,39 @@ void TreeModel_ItemBase::Reset()
|
||||
myProperties->Reset();
|
||||
}
|
||||
myCachedValues.clear();
|
||||
myStream.str ("");
|
||||
myStream.str("");
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Reset
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void TreeModel_ItemBase::Reset (int theRole)
|
||||
void TreeModel_ItemBase::Reset(int theRole)
|
||||
{
|
||||
if (!myCachedValues.contains (theRole))
|
||||
if (!myCachedValues.contains(theRole))
|
||||
return;
|
||||
|
||||
myCachedValues.remove (theRole);
|
||||
myCachedValues.remove(theRole);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : child
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
TreeModel_ItemBasePtr TreeModel_ItemBase::Child (int theRow, int theColumn, const bool isToCreate)
|
||||
TreeModel_ItemBasePtr TreeModel_ItemBase::Child(int theRow, int theColumn, const bool isToCreate)
|
||||
{
|
||||
QPair<int, int> aPos = qMakePair (theRow, theColumn);
|
||||
QPair<int, int> aPos = qMakePair(theRow, theColumn);
|
||||
|
||||
if (m_ChildItems.contains (aPos))
|
||||
if (m_ChildItems.contains(aPos))
|
||||
return m_ChildItems[aPos];
|
||||
|
||||
TreeModel_ItemBasePtr anItem;
|
||||
if (isToCreate) {
|
||||
if (isToCreate)
|
||||
{
|
||||
if (theRow < m_iStreamChildren)
|
||||
anItem = TreeModel_ItemStream::CreateItem (currentItem(), theRow, theColumn);
|
||||
anItem = TreeModel_ItemStream::CreateItem(currentItem(), theRow, theColumn);
|
||||
else
|
||||
anItem = createChild (theRow - m_iStreamChildren, theColumn);
|
||||
anItem = createChild(theRow - m_iStreamChildren, theColumn);
|
||||
|
||||
if (anItem)
|
||||
m_ChildItems[aPos] = anItem;
|
||||
@@ -97,7 +103,8 @@ TreeModel_ItemBasePtr TreeModel_ItemBase::Child (int theRow, int theColumn, cons
|
||||
// function : Presentations
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void TreeModel_ItemBase::Presentations (NCollection_List<Handle(Standard_Transient)>& thePresentations)
|
||||
void TreeModel_ItemBase::Presentations(
|
||||
NCollection_List<Handle(Standard_Transient)>& thePresentations)
|
||||
{
|
||||
if (Column() != 0)
|
||||
return;
|
||||
@@ -105,7 +112,7 @@ void TreeModel_ItemBase::Presentations (NCollection_List<Handle(Standard_Transie
|
||||
const Handle(TreeModel_ItemProperties)& anItemProperties = Properties();
|
||||
if (anItemProperties)
|
||||
{
|
||||
anItemProperties->Presentations (thePresentations);
|
||||
anItemProperties->Presentations(thePresentations);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,26 +122,26 @@ void TreeModel_ItemBase::Presentations (NCollection_List<Handle(Standard_Transie
|
||||
// =======================================================================
|
||||
const TreeModel_ItemBasePtr TreeModel_ItemBase::currentItem()
|
||||
{
|
||||
return TreeModel_ItemBasePtr (this);
|
||||
return TreeModel_ItemBasePtr(this);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : cachedValue
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
QVariant TreeModel_ItemBase::cachedValue (const int theItemRole) const
|
||||
QVariant TreeModel_ItemBase::cachedValue(const int theItemRole) const
|
||||
{
|
||||
if (myCachedValues.contains (theItemRole))
|
||||
if (myCachedValues.contains(theItemRole))
|
||||
return myCachedValues[theItemRole];
|
||||
|
||||
QVariant aValueToCache;
|
||||
if (theItemRole == TreeModel_ItemRole_RowCountRole)
|
||||
aValueToCache = initRowCount() + const_cast<TreeModel_ItemBase*>(this)->initStreamRowCount();
|
||||
else
|
||||
aValueToCache = initValue (theItemRole);
|
||||
aValueToCache = initValue(theItemRole);
|
||||
|
||||
myCachedValues.insert (theItemRole, aValueToCache);
|
||||
return myCachedValues.contains (theItemRole) ? myCachedValues[theItemRole] : QVariant();
|
||||
myCachedValues.insert(theItemRole, aValueToCache);
|
||||
return myCachedValues.contains(theItemRole) ? myCachedValues[theItemRole] : QVariant();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
@@ -169,13 +176,13 @@ int TreeModel_ItemBase::initStreamRowCount()
|
||||
if (Column() == 0)
|
||||
{
|
||||
Standard_SStream aStream;
|
||||
initStream (aStream);
|
||||
if (!Standard_Dump::Text (aStream).IsEmpty())
|
||||
initStream(aStream);
|
||||
if (!Standard_Dump::Text(aStream).IsEmpty())
|
||||
{
|
||||
if (!myProperties)
|
||||
{
|
||||
myProperties = new TreeModel_ItemProperties();
|
||||
myProperties->SetItem (currentItem());
|
||||
myProperties->SetItem(currentItem());
|
||||
}
|
||||
myProperties->Init();
|
||||
aStreamChildrenCount = myProperties->Children().Extent();
|
||||
@@ -189,14 +196,16 @@ int TreeModel_ItemBase::initStreamRowCount()
|
||||
// function : initValue
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
QVariant TreeModel_ItemBase::initValue (const int theItemRole) const
|
||||
QVariant TreeModel_ItemBase::initValue(const int theItemRole) const
|
||||
{
|
||||
if (theItemRole != Qt::DisplayRole && theItemRole != Qt::ToolTipRole)
|
||||
return QVariant();
|
||||
|
||||
switch (Column())
|
||||
{
|
||||
case TreeModel_ColumnType_Row: { return Row(); }
|
||||
case TreeModel_ColumnType_Row: {
|
||||
return Row();
|
||||
}
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
|
@@ -11,7 +11,7 @@
|
||||
// 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.
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef TreeModel_ItemBase_H
|
||||
#define TreeModel_ItemBase_H
|
||||
@@ -76,7 +76,6 @@ typedef QExplicitlySharedDataPointer<TreeModel_ItemBase> TreeModel_ItemBasePtr;
|
||||
class TreeModel_ItemBase : public QSharedData
|
||||
{
|
||||
public:
|
||||
|
||||
//! Destructor
|
||||
virtual ~TreeModel_ItemBase() {}
|
||||
|
||||
@@ -107,9 +106,15 @@ public:
|
||||
|
||||
//! Returns stream value of the item to fulfill property panel.
|
||||
//! \return stream value or dummy
|
||||
virtual bool SetStream (const Standard_SStream& theSStream, Standard_Integer& theStartPos,
|
||||
Standard_Integer& theLastPos) const
|
||||
{ (void)theSStream; (void)theStartPos; (void)theLastPos; return false; }
|
||||
virtual bool SetStream(const Standard_SStream& theSStream,
|
||||
Standard_Integer& theStartPos,
|
||||
Standard_Integer& theLastPos) const
|
||||
{
|
||||
(void)theSStream;
|
||||
(void)theStartPos;
|
||||
(void)theLastPos;
|
||||
return false;
|
||||
}
|
||||
|
||||
//! Gets the parent of the item, or TreeModel_ItemBasePtr() if it has no parent.
|
||||
//! \return pointer to the item
|
||||
@@ -130,18 +135,26 @@ public:
|
||||
//! \param theColumn the column of the child item
|
||||
//! \param isToCreate the flag whether the item should be created if it is not created yet
|
||||
//! \return the child item or TreeModel_ItemBasePtr() if it does not exist
|
||||
Standard_EXPORT TreeModel_ItemBasePtr Child (int theRow, int theColumn, const bool isToCreate = true);
|
||||
Standard_EXPORT TreeModel_ItemBasePtr Child(int theRow,
|
||||
int theColumn,
|
||||
const bool isToCreate = true);
|
||||
|
||||
//! Sets a custom value for the role in an internal cache
|
||||
//! \param theValue a value
|
||||
//! \param theRole a value role
|
||||
void SetCustomData(const QVariant& theValue, int theRole) { myCachedValues.insert (theRole, theValue); }
|
||||
void SetCustomData(const QVariant& theValue, int theRole)
|
||||
{
|
||||
myCachedValues.insert(theRole, theValue);
|
||||
}
|
||||
|
||||
//! Returns the data stored under the given role for the current item
|
||||
//! \param theIndex the item model index
|
||||
//! \param theRole the item model role
|
||||
virtual QVariant data (const QModelIndex& theIndex, int theRole = Qt::DisplayRole) const
|
||||
{ (void)theIndex; return cachedValue(theRole); }
|
||||
virtual QVariant data(const QModelIndex& theIndex, int theRole = Qt::DisplayRole) const
|
||||
{
|
||||
(void)theIndex;
|
||||
return cachedValue(theRole);
|
||||
}
|
||||
|
||||
//! Returns number of rows where the children are
|
||||
//! \return the row count
|
||||
@@ -151,18 +164,24 @@ public:
|
||||
const Handle(TreeModel_ItemProperties)& Properties() const { return myProperties; }
|
||||
|
||||
//! Updates item by the item properties value
|
||||
virtual void StoreItemProperties (const int theRow, const int theColumn, const QVariant& theValue)
|
||||
{ (void)theRow, (void)theColumn; (void)theValue; }
|
||||
virtual void StoreItemProperties(const int theRow, const int theColumn, const QVariant& theValue)
|
||||
{
|
||||
(void)theRow, (void)theColumn;
|
||||
(void)theValue;
|
||||
}
|
||||
|
||||
//! Returns presentation of the item to be visualized in the view
|
||||
//! \thePresentations[out] container of presentation handles
|
||||
Standard_EXPORT virtual void Presentations (NCollection_List<Handle(Standard_Transient)>& thePresentations);
|
||||
protected:
|
||||
Standard_EXPORT virtual void Presentations(
|
||||
NCollection_List<Handle(Standard_Transient)>& thePresentations);
|
||||
|
||||
protected:
|
||||
//! \param theParent the parent item
|
||||
//! \param theRow the item row position in the parent item
|
||||
//! \param theColumn the item column position in the parent item
|
||||
Standard_EXPORT TreeModel_ItemBase (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn);
|
||||
Standard_EXPORT TreeModel_ItemBase(TreeModel_ItemBasePtr theParent,
|
||||
const int theRow,
|
||||
const int theColumn);
|
||||
|
||||
//! Initializes the current item. It creates a backup of the specific item information
|
||||
virtual void initItem() const {}
|
||||
@@ -171,18 +190,21 @@ protected:
|
||||
//! \param theRow the child row position
|
||||
//! \param theColumn the child column position
|
||||
//! \return the created item
|
||||
virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn)
|
||||
{ (void)theRow; (void)theColumn; return TreeModel_ItemBasePtr(); }
|
||||
virtual TreeModel_ItemBasePtr createChild(int theRow, int theColumn)
|
||||
{
|
||||
(void)theRow;
|
||||
(void)theColumn;
|
||||
return TreeModel_ItemBasePtr();
|
||||
}
|
||||
|
||||
//! Wraps the current item by shared pointer
|
||||
//! \return the shared pointer to the current item
|
||||
Standard_EXPORT const TreeModel_ItemBasePtr currentItem();
|
||||
|
||||
//! Returns the cached value for the role. Init the value if it is requested the first time
|
||||
//! By default, it calls initRowCount(TreeModel_ItemRole_RowCountRole) or initValue for the item role
|
||||
//! \param theItemRole a value role
|
||||
//! \return the value
|
||||
Standard_EXPORT QVariant cachedValue (const int theItemRole) const;
|
||||
//! By default, it calls initRowCount(TreeModel_ItemRole_RowCountRole) or initValue for the item
|
||||
//! role \param theItemRole a value role \return the value
|
||||
Standard_EXPORT QVariant cachedValue(const int theItemRole) const;
|
||||
|
||||
//! \return number of children. It should be reimplemented in child
|
||||
virtual int initRowCount() const = 0;
|
||||
@@ -193,40 +215,40 @@ protected:
|
||||
//! Returns data value for the role. It should be reimplemented in child
|
||||
//! \param theItemRole a value role
|
||||
//! \return the value
|
||||
Standard_EXPORT virtual QVariant initValue (const int theItemRole) const;
|
||||
Standard_EXPORT virtual QVariant initValue(const int theItemRole) const;
|
||||
|
||||
//! Returns stream value of the item to fulfill property panel.
|
||||
//! \return stream value or dummy
|
||||
virtual void initStream (Standard_OStream& theOStream) const { (void)theOStream; }
|
||||
virtual void initStream(Standard_OStream& theOStream) const { (void)theOStream; }
|
||||
|
||||
protected:
|
||||
Handle(TreeModel_ItemProperties) myProperties; //!< the properties
|
||||
int m_iStreamChildren; //!< the count of stream items
|
||||
Standard_SStream myStream; //!< stream value
|
||||
Handle(TreeModel_ItemProperties) myProperties; //!< the properties
|
||||
int m_iStreamChildren; //!< the count of stream items
|
||||
Standard_SStream myStream; //!< stream value
|
||||
|
||||
private:
|
||||
|
||||
typedef QHash< QPair<int, int>, TreeModel_ItemBasePtr > PositionToItemHash;
|
||||
PositionToItemHash m_ChildItems; //!< the hash of item children
|
||||
typedef QHash<QPair<int, int>, TreeModel_ItemBasePtr> PositionToItemHash;
|
||||
PositionToItemHash m_ChildItems; //!< the hash of item children
|
||||
|
||||
mutable QMap<int, QVariant> myCachedValues; //!< cached values, should be cleared by reset
|
||||
TreeModel_ItemBasePtr m_pParent; //!< the parent item
|
||||
int m_iRow; //!< the item row position in the parent item
|
||||
int m_iColumn; //!< the item column position in the parent item
|
||||
TreeModel_ItemBasePtr m_pParent; //!< the parent item
|
||||
int m_iRow; //!< the item row position in the parent item
|
||||
int m_iColumn; //!< the item column position in the parent item
|
||||
bool m_bInitialized; //!< the state whether the item content is already initialized
|
||||
};
|
||||
|
||||
//! Returns an explicitly shared pointer to the pointer held by other, using a
|
||||
//! dynamic cast to type X to obtain an internal pointer of the appropriate type.
|
||||
//! If the dynamic_cast fails, the object returned will be null.
|
||||
//! Example of using:
|
||||
//! Example of using:
|
||||
//! TreeModel_ItemBase* aParent;
|
||||
//! TreeModel_CustomItemPtr aParentItem = itemDynamicCast<TreeModel_CustomItem>(aParent);
|
||||
//! \param theItem a source item
|
||||
//! \return a converted item
|
||||
template <class X, class T> QExplicitlySharedDataPointer<X> itemDynamicCast (const QExplicitlySharedDataPointer<T>& theItem)
|
||||
template <class X, class T>
|
||||
QExplicitlySharedDataPointer<X> itemDynamicCast(const QExplicitlySharedDataPointer<T>& theItem)
|
||||
{
|
||||
X* ptr = dynamic_cast<X*> (theItem.data());
|
||||
X* ptr = dynamic_cast<X*>(theItem.data());
|
||||
|
||||
QExplicitlySharedDataPointer<X> result;
|
||||
result = ptr;
|
||||
|
@@ -11,7 +11,7 @@
|
||||
// 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.
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <inspector/TreeModel_ItemProperties.hxx>
|
||||
#include <inspector/TreeModel_ItemStream.hxx>
|
||||
@@ -34,26 +34,26 @@ IMPLEMENT_STANDARD_RTTIEXT(TreeModel_ItemProperties, Standard_Transient)
|
||||
// function : Init
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void TreeModel_ItemProperties::Init ()
|
||||
void TreeModel_ItemProperties::Init()
|
||||
{
|
||||
myRowValues.Clear();
|
||||
|
||||
InitByStream (Item()->Stream());
|
||||
InitByStream(Item()->Stream());
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : InitByStream
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void TreeModel_ItemProperties::InitByStream (const Standard_SStream& aStream)
|
||||
void TreeModel_ItemProperties::InitByStream(const Standard_SStream& aStream)
|
||||
{
|
||||
NCollection_IndexedDataMap<TCollection_AsciiString, Standard_DumpValue> aValues;
|
||||
TCollection_AsciiString aStreamText = Standard_Dump::Text (aStream);
|
||||
Standard_Dump::SplitJson (aStreamText, aValues);
|
||||
TCollection_AsciiString aStreamText = Standard_Dump::Text(aStream);
|
||||
Standard_Dump::SplitJson(aStreamText, aValues);
|
||||
|
||||
TreeModel_ItemStreamPtr aStreamParent = itemDynamicCast<TreeModel_ItemStream>(Item());
|
||||
TCollection_AsciiString aKey;
|
||||
Standard_DumpValue aKeyValue;
|
||||
Standard_DumpValue aKeyValue;
|
||||
if (!aStreamParent)
|
||||
{
|
||||
if (!Item() || Item()->Object().IsNull())
|
||||
@@ -65,9 +65,9 @@ void TreeModel_ItemProperties::InitByStream (const Standard_SStream& aStream)
|
||||
const Handle(Standard_Transient)& anItemObject = Item()->Object();
|
||||
aKey = anItemObject.IsNull() ? "Dump" : anItemObject->DynamicType()->Name();
|
||||
}
|
||||
aKeyValue = Standard_DumpValue (aStreamText, 1);
|
||||
aKeyValue = Standard_DumpValue(aStreamText, 1);
|
||||
|
||||
myKey = aKey;
|
||||
myKey = aKey;
|
||||
myStreamValue = aKeyValue;
|
||||
}
|
||||
else
|
||||
@@ -77,43 +77,46 @@ void TreeModel_ItemProperties::InitByStream (const Standard_SStream& aStream)
|
||||
{
|
||||
const Handle(TreeModel_ItemProperties)& aParentProperties = Item()->Parent()->Properties();
|
||||
if (aParentProperties)
|
||||
aParentProperties->ChildStream (Item()->Row(), aKey, aKeyValue);
|
||||
aParentProperties->ChildStream(Item()->Row(), aKey, aKeyValue);
|
||||
}
|
||||
myKey = aKey;
|
||||
myKey = aKey;
|
||||
myStreamValue = aKeyValue;
|
||||
|
||||
aValues.Clear();
|
||||
Standard_Dump::SplitJson (myStreamValue.myValue, aValues);
|
||||
Standard_Dump::SplitJson(myStreamValue.myValue, aValues);
|
||||
}
|
||||
|
||||
for (Standard_Integer anIndex = 1; anIndex <= aValues.Size(); anIndex++)
|
||||
{
|
||||
Standard_DumpValue aValue = aValues.FindFromIndex (anIndex);
|
||||
if (Standard_Dump::HasChildKey (aValue.myValue))
|
||||
myChildren.Add (aValues.FindKey (anIndex), aValue);
|
||||
Standard_DumpValue aValue = aValues.FindFromIndex(anIndex);
|
||||
if (Standard_Dump::HasChildKey(aValue.myValue))
|
||||
myChildren.Add(aValues.FindKey(anIndex), aValue);
|
||||
else
|
||||
{
|
||||
TreeModel_RowValue aRowValue (aValue.myStartPosition, aValues.FindKey (anIndex).ToCString(), aValue.myValue.ToCString());
|
||||
myRowValues.Add (myRowValues.Size() + 1, aRowValue);
|
||||
TreeModel_RowValue aRowValue(aValue.myStartPosition,
|
||||
aValues.FindKey(anIndex).ToCString(),
|
||||
aValue.myValue.ToCString());
|
||||
myRowValues.Add(myRowValues.Size() + 1, aRowValue);
|
||||
}
|
||||
}
|
||||
if (myRowValues.Size() == 1)
|
||||
{
|
||||
Quantity_Color aColor;
|
||||
if (Convert_Tools::ConvertStreamToColor (aStream, aColor))
|
||||
if (Convert_Tools::ConvertStreamToColor(aStream, aColor))
|
||||
{
|
||||
Standard_Real aRed, aGreen, aBlue;
|
||||
aColor.Values (aRed, aGreen, aBlue, Quantity_TOC_sRGB);
|
||||
aColor.Values(aRed, aGreen, aBlue, Quantity_TOC_sRGB);
|
||||
|
||||
int aDelta = 255;
|
||||
myRowValues.ChangeFromIndex (1).CustomValues.insert ((int)Qt::BackgroundRole, QColor((int)(aRed * aDelta),
|
||||
(int)(aGreen * aDelta), (int)(aBlue * aDelta)));
|
||||
myRowValues.ChangeFromIndex(1).CustomValues.insert(
|
||||
(int)Qt::BackgroundRole,
|
||||
QColor((int)(aRed * aDelta), (int)(aGreen * aDelta), (int)(aBlue * aDelta)));
|
||||
}
|
||||
}
|
||||
// in case if the stream alert has empty key avalue, use as the key the first row value
|
||||
if ((myKey.IsEmpty() || myKey.IsEqual ("Dump")) && myRowValues.Size() > 0)
|
||||
if ((myKey.IsEmpty() || myKey.IsEqual("Dump")) && myRowValues.Size() > 0)
|
||||
{
|
||||
myKey = myRowValues.FindFromIndex (1).Value.toString().toStdString().c_str();
|
||||
myKey = myRowValues.FindFromIndex(1).Value.toString().toStdString().c_str();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +126,7 @@ void TreeModel_ItemProperties::InitByStream (const Standard_SStream& aStream)
|
||||
// =======================================================================
|
||||
void TreeModel_ItemProperties::Reset()
|
||||
{
|
||||
myKey = "";
|
||||
myKey = "";
|
||||
myStreamValue = Standard_DumpValue();
|
||||
|
||||
myChildren.Clear();
|
||||
@@ -143,12 +146,12 @@ int TreeModel_ItemProperties::RowCount() const
|
||||
// function : Data
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
QVariant TreeModel_ItemProperties::Data (const int theRow, const int theColumn, int theRole) const
|
||||
QVariant TreeModel_ItemProperties::Data(const int theRow, const int theColumn, int theRole) const
|
||||
{
|
||||
if (theColumn == 1 && theRole == Qt::BackgroundRole)
|
||||
{
|
||||
const QMap<int, QVariant>& aCachedValues = RowValues().FindFromIndex (theRow + 1).CustomValues;
|
||||
if (aCachedValues.contains ((int)theRole))
|
||||
const QMap<int, QVariant>& aCachedValues = RowValues().FindFromIndex(theRow + 1).CustomValues;
|
||||
if (aCachedValues.contains((int)theRole))
|
||||
return aCachedValues[(int)theRole];
|
||||
}
|
||||
|
||||
@@ -157,20 +160,22 @@ QVariant TreeModel_ItemProperties::Data (const int theRow, const int theColumn,
|
||||
if (Data(theRow, 0, Qt::DisplayRole).toString().contains("className"))
|
||||
{
|
||||
QFont aFont = qApp->font();
|
||||
aFont.setItalic (true);
|
||||
aFont.setItalic(true);
|
||||
return aFont;
|
||||
}
|
||||
}
|
||||
if (theRole == Qt::ForegroundRole)
|
||||
{
|
||||
if (Data(theRow, 0, Qt::DisplayRole).toString().contains("className"))
|
||||
return QColor (Qt::darkGray).darker(150);
|
||||
return QColor(Qt::darkGray).darker(150);
|
||||
}
|
||||
|
||||
if (theRole == Qt::DisplayRole || theRole == Qt::ToolTipRole)
|
||||
{
|
||||
if (theColumn == 0) return RowValues().FindFromIndex (theRow + 1).Key;
|
||||
else if (theColumn == 1) return RowValues().FindFromIndex (theRow + 1).Value;
|
||||
if (theColumn == 0)
|
||||
return RowValues().FindFromIndex(theRow + 1).Key;
|
||||
else if (theColumn == 1)
|
||||
return RowValues().FindFromIndex(theRow + 1).Value;
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
@@ -180,13 +185,13 @@ QVariant TreeModel_ItemProperties::Data (const int theRow, const int theColumn,
|
||||
// function : EditType
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
ViewControl_EditType TreeModel_ItemProperties::EditType (const int, const int theColumn) const
|
||||
ViewControl_EditType TreeModel_ItemProperties::EditType(const int, const int theColumn) const
|
||||
{
|
||||
if (theColumn == 0)
|
||||
return ViewControl_EditType_None;
|
||||
|
||||
Quantity_Color aColor;
|
||||
if (Convert_Tools::ConvertStreamToColor (Item()->Stream(), aColor))
|
||||
if (Convert_Tools::ConvertStreamToColor(Item()->Stream(), aColor))
|
||||
{
|
||||
return ViewControl_EditType_Color;
|
||||
}
|
||||
@@ -197,21 +202,22 @@ ViewControl_EditType TreeModel_ItemProperties::EditType (const int, const int th
|
||||
// function : ReplaceValue
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Boolean ReplaceValue (const TCollection_AsciiString& theFromValue,
|
||||
const TCollection_AsciiString& theToValue,
|
||||
Standard_DumpValue& theStreamValue)
|
||||
Standard_Boolean ReplaceValue(const TCollection_AsciiString& theFromValue,
|
||||
const TCollection_AsciiString& theToValue,
|
||||
Standard_DumpValue& theStreamValue)
|
||||
{
|
||||
TCollection_AsciiString aStreamValue = theStreamValue.myValue;
|
||||
|
||||
int aPosition = aStreamValue.FirstLocationInSet (theFromValue, 1, aStreamValue.Length());
|
||||
int aPosition = aStreamValue.FirstLocationInSet(theFromValue, 1, aStreamValue.Length());
|
||||
if (aPosition < 1)
|
||||
return Standard_False;
|
||||
|
||||
aPosition += 2; // due to 'FirstLocationInSet' returns position taking into account '"\' as 1 position
|
||||
aPosition +=
|
||||
2; // due to 'FirstLocationInSet' returns position taking into account '"\' as 1 position
|
||||
|
||||
TCollection_AsciiString aPartStart = aStreamValue.SubString(1, aPosition - 1);
|
||||
TCollection_AsciiString aPartFinal = aStreamValue.SubString(aPosition + theFromValue.Length(),
|
||||
aStreamValue.Length());
|
||||
TCollection_AsciiString aPartFinal =
|
||||
aStreamValue.SubString(aPosition + theFromValue.Length(), aStreamValue.Length());
|
||||
theStreamValue.myValue = aPartStart + theToValue + aPartFinal;
|
||||
|
||||
return Standard_True;
|
||||
@@ -221,7 +227,10 @@ Standard_Boolean ReplaceValue (const TCollection_AsciiString& theFromValue,
|
||||
// function : SetData
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool TreeModel_ItemProperties::SetData (const int theRow, const int theColumn, const QVariant& theValue, int theRole)
|
||||
bool TreeModel_ItemProperties::SetData(const int theRow,
|
||||
const int theColumn,
|
||||
const QVariant& theValue,
|
||||
int theRole)
|
||||
{
|
||||
if (theColumn == 0)
|
||||
return false;
|
||||
@@ -231,47 +240,49 @@ bool TreeModel_ItemProperties::SetData (const int theRow, const int theColumn, c
|
||||
|
||||
if (myRowValues.Size() == 1 && theColumn == 1)
|
||||
{
|
||||
TCollection_AsciiString aStreamValue (theValue.toString().toStdString().c_str());
|
||||
TCollection_AsciiString aStreamValue(theValue.toString().toStdString().c_str());
|
||||
NCollection_IndexedDataMap<TCollection_AsciiString, Standard_DumpValue> aKeyToValues;
|
||||
if (Standard_Dump::SplitJson (aStreamValue, aKeyToValues))
|
||||
if (Standard_Dump::SplitJson(aStreamValue, aKeyToValues))
|
||||
{
|
||||
Standard_SStream aStream;
|
||||
aStream << aStreamValue.ToCString();
|
||||
|
||||
int aStartPos = 1;
|
||||
int aStartPos = 1;
|
||||
Quantity_ColorRGBA aColor;
|
||||
if (aColor.InitFromJson (aStream, aStartPos))
|
||||
if (aColor.InitFromJson(aStream, aStartPos))
|
||||
{
|
||||
Standard_Real aRed, aGreen, aBlue;
|
||||
aColor.GetRGB().Values (aRed, aGreen, aBlue, Quantity_TOC_sRGB);
|
||||
aColor.GetRGB().Values(aRed, aGreen, aBlue, Quantity_TOC_sRGB);
|
||||
int aDelta = 255;
|
||||
myRowValues.ChangeFromIndex (1).CustomValues.insert ((int)Qt::BackgroundRole, QColor((int)(aRed * aDelta),
|
||||
(int)(aGreen * aDelta), (int)(aBlue * aDelta)));
|
||||
myRowValues.ChangeFromIndex(1).CustomValues.insert(
|
||||
(int)Qt::BackgroundRole,
|
||||
QColor((int)(aRed * aDelta), (int)(aGreen * aDelta), (int)(aBlue * aDelta)));
|
||||
}
|
||||
Standard_DumpValue aValue = aKeyToValues.FindFromIndex (1);
|
||||
myStreamValue.myValue = aValue.myValue.ToCString();
|
||||
myRowValues.ChangeFromIndex (1).Value = aValue.myValue.ToCString();
|
||||
Standard_DumpValue aValue = aKeyToValues.FindFromIndex(1);
|
||||
myStreamValue.myValue = aValue.myValue.ToCString();
|
||||
myRowValues.ChangeFromIndex(1).Value = aValue.myValue.ToCString();
|
||||
|
||||
Item()->StoreItemProperties (theRow, theColumn, theValue);
|
||||
Item()->StoreItemProperties(theRow, theColumn, theValue);
|
||||
return true;
|
||||
}
|
||||
TCollection_AsciiString aFromValue = myRowValues.ChangeFromIndex (1).Value.toString().toStdString().c_str();
|
||||
TCollection_AsciiString aFromValue =
|
||||
myRowValues.ChangeFromIndex(1).Value.toString().toStdString().c_str();
|
||||
if (ReplaceValue(aFromValue, aStreamValue, myStreamValue))
|
||||
{
|
||||
aStreamValue = myStreamValue.myValue;
|
||||
if (Standard_Dump::SplitJson (aStreamValue, aKeyToValues))
|
||||
if (Standard_Dump::SplitJson(aStreamValue, aKeyToValues))
|
||||
{
|
||||
Standard_DumpValue aValue = aKeyToValues.FindFromIndex (1);
|
||||
myRowValues.ChangeFromIndex (1).Value = aValue.myValue.ToCString();
|
||||
Standard_DumpValue aValue = aKeyToValues.FindFromIndex(1);
|
||||
myRowValues.ChangeFromIndex(1).Value = aValue.myValue.ToCString();
|
||||
|
||||
Item()->StoreItemProperties (theRow, theColumn, aStreamValue.ToCString());
|
||||
Item()->StoreItemProperties(theRow, theColumn, aStreamValue.ToCString());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
myRowValues.ChangeFromIndex (theRow + 1).Value = theValue;
|
||||
Item()->StoreItemProperties (theRow, theColumn, theValue);
|
||||
myRowValues.ChangeFromIndex(theRow + 1).Value = theValue;
|
||||
Item()->StoreItemProperties(theRow, theColumn, theValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -279,21 +290,22 @@ bool TreeModel_ItemProperties::SetData (const int theRow, const int theColumn, c
|
||||
// function : Presentations
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void TreeModel_ItemProperties::Presentations (NCollection_List<Handle(Standard_Transient)>& thePresentations)
|
||||
void TreeModel_ItemProperties::Presentations(
|
||||
NCollection_List<Handle(Standard_Transient)>& thePresentations)
|
||||
{
|
||||
if (!Item())
|
||||
{
|
||||
return;
|
||||
}
|
||||
const Standard_SStream& aStream = Item()->Stream();
|
||||
Convert_Tools::ConvertStreamToPresentations (aStream, 1, -1, thePresentations);
|
||||
Convert_Tools::ConvertStreamToPresentations(aStream, 1, -1, thePresentations);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : TableFlags
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Qt::ItemFlags TreeModel_ItemProperties::TableFlags (const int, const int theColumn) const
|
||||
Qt::ItemFlags TreeModel_ItemProperties::TableFlags(const int, const int theColumn) const
|
||||
{
|
||||
Qt::ItemFlags aFlags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
|
||||
@@ -307,15 +319,15 @@ Qt::ItemFlags TreeModel_ItemProperties::TableFlags (const int, const int theColu
|
||||
// function : ChildStream
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void TreeModel_ItemProperties::ChildStream (const int theRowId,
|
||||
TCollection_AsciiString& theKey,
|
||||
Standard_DumpValue& theValue) const
|
||||
void TreeModel_ItemProperties::ChildStream(const int theRowId,
|
||||
TCollection_AsciiString& theKey,
|
||||
Standard_DumpValue& theValue) const
|
||||
{
|
||||
if (myChildren.Size() <= theRowId)
|
||||
return;
|
||||
|
||||
theKey = myChildren.FindKey (theRowId + 1);
|
||||
theValue = myChildren.FindFromIndex (theRowId + 1);
|
||||
theKey = myChildren.FindKey(theRowId + 1);
|
||||
theValue = myChildren.FindFromIndex(theRowId + 1);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
|
@@ -11,7 +11,7 @@
|
||||
// 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.
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef TreeModel_ItemProperties_H
|
||||
#define TreeModel_ItemProperties_H
|
||||
@@ -54,13 +54,20 @@ class TreeModel_ItemProperties : public Standard_Transient
|
||||
//! container of values in a row of property table
|
||||
struct TreeModel_RowValue
|
||||
{
|
||||
TreeModel_RowValue (const Standard_Integer theValueStartPosition, const QVariant& theKey, QVariant theValue)
|
||||
: ValueStartPosition (theValueStartPosition), Key (theKey), Value (theValue) {}
|
||||
TreeModel_RowValue(const Standard_Integer theValueStartPosition,
|
||||
const QVariant& theKey,
|
||||
QVariant theValue)
|
||||
: ValueStartPosition(theValueStartPosition),
|
||||
Key(theKey),
|
||||
Value(theValue)
|
||||
{
|
||||
}
|
||||
|
||||
Standard_Integer ValueStartPosition; //!< start position of the key
|
||||
QVariant Key; //!< value in the first column
|
||||
QVariant Value; //!< value in the second column
|
||||
QMap<int, QVariant> CustomValues; //!< custom values, e.g. key is Background, value is a defined color
|
||||
QVariant Key; //!< value in the first column
|
||||
QVariant Value; //!< value in the second column
|
||||
QMap<int, QVariant>
|
||||
CustomValues; //!< custom values, e.g. key is Background, value is a defined color
|
||||
};
|
||||
|
||||
public:
|
||||
@@ -71,10 +78,10 @@ public:
|
||||
~TreeModel_ItemProperties() {}
|
||||
|
||||
//! Sets the current item
|
||||
void SetItem (const TreeModel_ItemBasePtr& theItem) { myItem = theItem; }
|
||||
void SetItem(const TreeModel_ItemBasePtr& theItem) { myItem = theItem; }
|
||||
|
||||
//! Fills properties with the stream value
|
||||
Standard_EXPORT void InitByStream (const Standard_SStream& theStream);
|
||||
Standard_EXPORT void InitByStream(const Standard_SStream& theStream);
|
||||
|
||||
//! Returns the current item
|
||||
TreeModel_ItemBasePtr Item() const { return myItem; }
|
||||
@@ -93,42 +100,43 @@ public:
|
||||
//! \return an integer value
|
||||
int ColumnCount() const { return 2; }
|
||||
|
||||
//! Returns content of the model index for the given role, it is obtained from internal container of values
|
||||
//! \param theRow a model index row
|
||||
//! \param theColumn a model index column
|
||||
//! \param theRole a view role
|
||||
//! \return value interpreted depending on the given role
|
||||
Standard_EXPORT QVariant Data (const int theRow, const int theColumn, int theRole = Qt::DisplayRole) const;
|
||||
//! Returns content of the model index for the given role, it is obtained from internal container
|
||||
//! of values \param theRow a model index row \param theColumn a model index column \param theRole
|
||||
//! a view role \return value interpreted depending on the given role
|
||||
Standard_EXPORT QVariant Data(const int theRow,
|
||||
const int theColumn,
|
||||
int theRole = Qt::DisplayRole) const;
|
||||
|
||||
//! Returns type of edit control for the model index. By default, it is an empty control
|
||||
//! \param theRow a model index row
|
||||
//! \param theColumn a model index column
|
||||
//! \return edit type
|
||||
Standard_EXPORT ViewControl_EditType EditType (const int theRow, const int theColumn) const;
|
||||
Standard_EXPORT ViewControl_EditType EditType(const int theRow, const int theColumn) const;
|
||||
|
||||
//! Sets content of the model index for the given role, it is applied to internal container of values
|
||||
//! \param theRow a model index row
|
||||
//! \param theColumn a model index column
|
||||
//! \param theRole a view role
|
||||
//! \return true if the value is changed
|
||||
Standard_EXPORT bool SetData (const int theRow, const int theColumn, const QVariant& theValue,
|
||||
int theRole = Qt::DisplayRole);
|
||||
//! Sets content of the model index for the given role, it is applied to internal container of
|
||||
//! values \param theRow a model index row \param theColumn a model index column \param theRole a
|
||||
//! view role \return true if the value is changed
|
||||
Standard_EXPORT bool SetData(const int theRow,
|
||||
const int theColumn,
|
||||
const QVariant& theValue,
|
||||
int theRole = Qt::DisplayRole);
|
||||
|
||||
//! Returns presentation of the attribute to be visualized in the view
|
||||
//! \thePresentations[out] container of presentation handles to be visualized
|
||||
Standard_EXPORT void Presentations (NCollection_List<Handle(Standard_Transient)>& thePresentations);
|
||||
Standard_EXPORT void Presentations(
|
||||
NCollection_List<Handle(Standard_Transient)>& thePresentations);
|
||||
|
||||
//! Returns flags for the item: ItemIsEnabled | Qt::ItemIsSelectable.
|
||||
//! Additional flag for the column 1 is Qt::ItemIsEditable.
|
||||
//! \param theIndex a model index
|
||||
//! \return flags
|
||||
Standard_EXPORT Qt::ItemFlags TableFlags (const int theRow, const int theColumn) const;
|
||||
Standard_EXPORT Qt::ItemFlags TableFlags(const int theRow, const int theColumn) const;
|
||||
|
||||
//! Returns stream value of the item to fulfill property panel.
|
||||
//! \return stream value or dummy
|
||||
Standard_EXPORT void ChildStream (const int theRowId,
|
||||
TCollection_AsciiString& theKey,
|
||||
Standard_DumpValue& theValue) const;
|
||||
Standard_EXPORT void ChildStream(const int theRowId,
|
||||
TCollection_AsciiString& theKey,
|
||||
Standard_DumpValue& theValue) const;
|
||||
|
||||
//! Returns data object of the item.
|
||||
//! \return object key
|
||||
@@ -139,15 +147,24 @@ public:
|
||||
const TCollection_AsciiString& StreamValue() const { return myStreamValue.myValue; }
|
||||
|
||||
//! Returns children stream values
|
||||
//const NCollection_IndexedDataMap<TCollection_AsciiString, Standard_DumpValue>& Values() const { initItem(); return myValues; }
|
||||
// const NCollection_IndexedDataMap<TCollection_AsciiString, Standard_DumpValue>& Values() const {
|
||||
// initItem(); return myValues; }
|
||||
|
||||
//! Returns children stream values
|
||||
const NCollection_IndexedDataMap<Standard_Integer, TreeModel_RowValue>& RowValues() const { initItem(); return myRowValues; }
|
||||
const NCollection_IndexedDataMap<Standard_Integer, TreeModel_RowValue>& RowValues() const
|
||||
{
|
||||
initItem();
|
||||
return myRowValues;
|
||||
}
|
||||
|
||||
//! Returns children stream values
|
||||
const NCollection_IndexedDataMap<TCollection_AsciiString, Standard_DumpValue>& Children() const { initItem(); return myChildren; }
|
||||
const NCollection_IndexedDataMap<TCollection_AsciiString, Standard_DumpValue>& Children() const
|
||||
{
|
||||
initItem();
|
||||
return myChildren;
|
||||
}
|
||||
|
||||
DEFINE_STANDARD_RTTIEXT (TreeModel_ItemProperties, Standard_Transient)
|
||||
DEFINE_STANDARD_RTTIEXT(TreeModel_ItemProperties, Standard_Transient)
|
||||
|
||||
protected:
|
||||
//! Initializes the current item. It creates a backup of the specific item information
|
||||
@@ -156,9 +173,10 @@ protected:
|
||||
private:
|
||||
TreeModel_ItemBasePtr myItem; //!< current item
|
||||
|
||||
TCollection_AsciiString myKey; //!< the item key
|
||||
Standard_DumpValue myStreamValue; //!< the stream value
|
||||
NCollection_IndexedDataMap<TCollection_AsciiString, Standard_DumpValue> myChildren; //!< the children
|
||||
TCollection_AsciiString myKey; //!< the item key
|
||||
Standard_DumpValue myStreamValue; //!< the stream value
|
||||
NCollection_IndexedDataMap<TCollection_AsciiString, Standard_DumpValue>
|
||||
myChildren; //!< the children
|
||||
NCollection_IndexedDataMap<Standard_Integer, TreeModel_RowValue> myRowValues; //!< the values
|
||||
};
|
||||
|
||||
|
@@ -11,7 +11,7 @@
|
||||
// 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.
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef TreeModel_ItemRole_H
|
||||
#define TreeModel_ItemRole_H
|
||||
@@ -23,7 +23,8 @@
|
||||
//! Sets custom item role of Tree view wmodel
|
||||
enum TreeModel_ItemRole
|
||||
{
|
||||
TreeModel_ItemRole_RowCountRole = Qt::UserRole + 1, //! additional column with row count for item (cached value)
|
||||
TreeModel_ItemRole_RowCountRole =
|
||||
Qt::UserRole + 1, //! additional column with row count for item (cached value)
|
||||
TreeModel_ItemRole_LastTreeRole //! last enumeration value to use outside incremented
|
||||
};
|
||||
|
||||
|
@@ -11,7 +11,7 @@
|
||||
// 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.
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <inspector/TreeModel_ItemStream.hxx>
|
||||
|
||||
@@ -23,8 +23,10 @@
|
||||
// function : Constructor
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
TreeModel_ItemStream::TreeModel_ItemStream (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
|
||||
: TreeModel_ItemBase (theParent, theRow, theColumn)
|
||||
TreeModel_ItemStream::TreeModel_ItemStream(TreeModel_ItemBasePtr theParent,
|
||||
const int theRow,
|
||||
const int theColumn)
|
||||
: TreeModel_ItemBase(theParent, theRow, theColumn)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -42,13 +44,13 @@ void TreeModel_ItemStream::Init()
|
||||
if (!myProperties)
|
||||
{
|
||||
myProperties = new TreeModel_ItemProperties();
|
||||
myProperties->SetItem (currentItem());
|
||||
myProperties->SetItem(currentItem());
|
||||
}
|
||||
myProperties->Init();
|
||||
aStreamChildrenCount = myProperties->Children().Extent();
|
||||
}
|
||||
m_iStreamChildren = aStreamChildrenCount;
|
||||
initStream (myStream);
|
||||
initStream(myStream);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
@@ -57,7 +59,7 @@ void TreeModel_ItemStream::Init()
|
||||
// =======================================================================
|
||||
void TreeModel_ItemStream::Reset()
|
||||
{
|
||||
myStream.str ("");
|
||||
myStream.str("");
|
||||
TreeModel_ItemBase::Reset();
|
||||
}
|
||||
|
||||
@@ -65,9 +67,9 @@ void TreeModel_ItemStream::Reset()
|
||||
// function : initValue
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
QVariant TreeModel_ItemStream::initValue (const int theItemRole) const
|
||||
QVariant TreeModel_ItemStream::initValue(const int theItemRole) const
|
||||
{
|
||||
QVariant aParentValue = TreeModel_ItemBase::initValue (theItemRole);
|
||||
QVariant aParentValue = TreeModel_ItemBase::initValue(theItemRole);
|
||||
if (aParentValue.isValid())
|
||||
return aParentValue;
|
||||
|
||||
@@ -75,14 +77,16 @@ QVariant TreeModel_ItemStream::initValue (const int theItemRole) const
|
||||
return QVariant();
|
||||
|
||||
if (theItemRole == Qt::ForegroundRole)
|
||||
return QColor (Qt::darkBlue);
|
||||
return QColor(Qt::darkBlue);
|
||||
|
||||
if (theItemRole != Qt::DisplayRole && theItemRole != Qt::EditRole && theItemRole != Qt::ToolTipRole)
|
||||
if (theItemRole != Qt::DisplayRole && theItemRole != Qt::EditRole
|
||||
&& theItemRole != Qt::ToolTipRole)
|
||||
return QVariant();
|
||||
|
||||
switch (Column())
|
||||
{
|
||||
case 0: return Properties() ? Properties()->Key().ToCString() : "";
|
||||
case 0:
|
||||
return Properties() ? Properties()->Key().ToCString() : "";
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
@@ -91,16 +95,16 @@ QVariant TreeModel_ItemStream::initValue (const int theItemRole) const
|
||||
// function : StoreItemProperties
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void TreeModel_ItemStream::StoreItemProperties (const int, const int, const QVariant& theValue)
|
||||
void TreeModel_ItemStream::StoreItemProperties(const int, const int, const QVariant& theValue)
|
||||
{
|
||||
Parent()->StoreItemProperties (-1, -1, theValue);
|
||||
Parent()->StoreItemProperties(-1, -1, theValue);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : initStream
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void TreeModel_ItemStream::initStream (Standard_OStream& theOStream) const
|
||||
void TreeModel_ItemStream::initStream(Standard_OStream& theOStream) const
|
||||
{
|
||||
if (!Properties())
|
||||
return;
|
||||
@@ -123,7 +127,7 @@ void TreeModel_ItemStream::initItem() const
|
||||
// function : createChild
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
TreeModel_ItemBasePtr TreeModel_ItemStream::createChild (int theRow, int theColumn)
|
||||
TreeModel_ItemBasePtr TreeModel_ItemStream::createChild(int theRow, int theColumn)
|
||||
{
|
||||
return TreeModel_ItemStream::CreateItem (currentItem(), theRow, theColumn);
|
||||
return TreeModel_ItemStream::CreateItem(currentItem(), theRow, theColumn);
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@
|
||||
// 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.
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef TreeModel_ItemStream_H
|
||||
#define TreeModel_ItemStream_H
|
||||
@@ -35,10 +35,13 @@ typedef QExplicitlySharedDataPointer<TreeModel_ItemStream> TreeModel_ItemStreamP
|
||||
class TreeModel_ItemStream : public TreeModel_ItemBase
|
||||
{
|
||||
public:
|
||||
|
||||
//! Creates an item wrapped by a shared pointer
|
||||
static TreeModel_ItemStreamPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
|
||||
{ return TreeModel_ItemStreamPtr (new TreeModel_ItemStream (theParent, theRow, theColumn)); }
|
||||
static TreeModel_ItemStreamPtr CreateItem(TreeModel_ItemBasePtr theParent,
|
||||
const int theRow,
|
||||
const int theColumn)
|
||||
{
|
||||
return TreeModel_ItemStreamPtr(new TreeModel_ItemStream(theParent, theRow, theColumn));
|
||||
}
|
||||
|
||||
//! Destructor
|
||||
virtual ~TreeModel_ItemStream() {}
|
||||
@@ -53,43 +56,50 @@ public:
|
||||
|
||||
//! Returns number of displayed presentations
|
||||
//! \return rows count
|
||||
virtual int initRowCount() const Standard_OVERRIDE { initItem(); return 0; }
|
||||
virtual int initRowCount() const Standard_OVERRIDE
|
||||
{
|
||||
initItem();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//! Returns item information for the given role. Fills internal container if it was not filled yet
|
||||
//! \param theItemRole a value role
|
||||
//! \return the value
|
||||
Standard_EXPORT virtual QVariant initValue (const int theItemRole) const Standard_OVERRIDE;
|
||||
Standard_EXPORT virtual QVariant initValue(const int theItemRole) const Standard_OVERRIDE;
|
||||
|
||||
//! Stores values of the item properties into the item object
|
||||
//! \param theRow the child row position
|
||||
//! \param theColumn the child column position
|
||||
//! \param theValue the cell value
|
||||
Standard_EXPORT virtual void StoreItemProperties (const int theRow, const int theColumn, const QVariant& theValue) Standard_OVERRIDE;
|
||||
Standard_EXPORT virtual void StoreItemProperties(const int theRow,
|
||||
const int theColumn,
|
||||
const QVariant& theValue) Standard_OVERRIDE;
|
||||
|
||||
protected:
|
||||
//! Returns stream value of the item to fulfill property panel.
|
||||
//! \return stream value or dummy
|
||||
Standard_EXPORT virtual void initStream (Standard_OStream& theOStream) const Standard_OVERRIDE;
|
||||
Standard_EXPORT virtual void initStream(Standard_OStream& theOStream) const Standard_OVERRIDE;
|
||||
|
||||
//! Initializes the current item. It creates a backup of the specific item information
|
||||
//! Does nothing as context has been already set into item
|
||||
Standard_EXPORT virtual void initItem() const Standard_OVERRIDE;
|
||||
|
||||
protected:
|
||||
|
||||
//! Creates a child item in the given position.
|
||||
//! \param theRow the child row position
|
||||
//! \param theColumn the child column position
|
||||
//! \return the created item
|
||||
Standard_EXPORT virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE;
|
||||
Standard_EXPORT virtual TreeModel_ItemBasePtr createChild(int theRow,
|
||||
int theColumn) Standard_OVERRIDE;
|
||||
|
||||
private:
|
||||
|
||||
//! Constructor
|
||||
//! \param theParent a parent item
|
||||
//! \param theRow the item row position in the parent item
|
||||
//! \param theColumn the item column position in the parent item
|
||||
Standard_EXPORT TreeModel_ItemStream(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn);
|
||||
Standard_EXPORT TreeModel_ItemStream(TreeModel_ItemBasePtr theParent,
|
||||
const int theRow,
|
||||
const int theColumn);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -11,7 +11,7 @@
|
||||
// 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.
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <inspector/TreeModel_ModelBase.hxx>
|
||||
|
||||
@@ -33,12 +33,13 @@ const int COLUMN_SIZE_WIDTH = 30;
|
||||
// function : Constructor
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
TreeModel_ModelBase::TreeModel_ModelBase (QObject* theParent)
|
||||
: QAbstractItemModel (theParent), m_pUseVisibilityColumn (false),
|
||||
myVisibilityState (0)
|
||||
TreeModel_ModelBase::TreeModel_ModelBase(QObject* theParent)
|
||||
: QAbstractItemModel(theParent),
|
||||
m_pUseVisibilityColumn(false),
|
||||
myVisibilityState(0)
|
||||
{
|
||||
myVisibleIcon = QIcon (":/icons/item_visible.png");
|
||||
myInvisibleIcon = QIcon (":/icons/item_invisible.png");
|
||||
myVisibleIcon = QIcon(":/icons/item_visible.png");
|
||||
myInvisibleIcon = QIcon(":/icons/item_invisible.png");
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
@@ -47,19 +48,21 @@ TreeModel_ModelBase::TreeModel_ModelBase (QObject* theParent)
|
||||
// =======================================================================
|
||||
void TreeModel_ModelBase::InitColumns()
|
||||
{
|
||||
setHeaderItem (TreeModel_ColumnType_Name, TreeModel_HeaderSection ("Name", COLUMN_NAME_WIDTH));
|
||||
setHeaderItem (TreeModel_ColumnType_Visibility, TreeModel_HeaderSection ("Visibility", TreeModel_ModelBase::ColumnVisibilityWidth()));
|
||||
setHeaderItem (TreeModel_ColumnType_Row, TreeModel_HeaderSection ("Row", COLUMN_SIZE_WIDTH));
|
||||
setHeaderItem(TreeModel_ColumnType_Name, TreeModel_HeaderSection("Name", COLUMN_NAME_WIDTH));
|
||||
setHeaderItem(
|
||||
TreeModel_ColumnType_Visibility,
|
||||
TreeModel_HeaderSection("Visibility", TreeModel_ModelBase::ColumnVisibilityWidth()));
|
||||
setHeaderItem(TreeModel_ColumnType_Row, TreeModel_HeaderSection("Row", COLUMN_SIZE_WIDTH));
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : GetItemByIndex
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
TreeModel_ItemBasePtr TreeModel_ModelBase::GetItemByIndex (const QModelIndex& theIndex)
|
||||
TreeModel_ItemBasePtr TreeModel_ModelBase::GetItemByIndex(const QModelIndex& theIndex)
|
||||
{
|
||||
TreeModel_ItemBase* anItem = (TreeModel_ItemBase*)theIndex.internalPointer();
|
||||
return TreeModel_ItemBasePtr (anItem);
|
||||
return TreeModel_ItemBasePtr(anItem);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
@@ -70,7 +73,7 @@ void TreeModel_ModelBase::Reset()
|
||||
{
|
||||
for (int aColId = 0, aNbColumns = columnCount(); aColId < aNbColumns; aColId++)
|
||||
{
|
||||
TreeModel_ItemBasePtr aRootItem = RootItem (aColId);
|
||||
TreeModel_ItemBasePtr aRootItem = RootItem(aColId);
|
||||
if (aRootItem)
|
||||
aRootItem->Reset();
|
||||
}
|
||||
@@ -80,58 +83,61 @@ void TreeModel_ModelBase::Reset()
|
||||
// function : index
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
QModelIndex TreeModel_ModelBase::index (int theRow, int theColumn, const QModelIndex& theParent) const
|
||||
QModelIndex TreeModel_ModelBase::index(int theRow,
|
||||
int theColumn,
|
||||
const QModelIndex& theParent) const
|
||||
{
|
||||
if (!hasIndex (theRow, theColumn, theParent))
|
||||
if (!hasIndex(theRow, theColumn, theParent))
|
||||
return QModelIndex();
|
||||
|
||||
// to create index on the root item
|
||||
if (!theParent.isValid())
|
||||
return createIndex (theRow, theColumn, getIndexValue (RootItem (theColumn)));
|
||||
return createIndex(theRow, theColumn, getIndexValue(RootItem(theColumn)));
|
||||
|
||||
TreeModel_ItemBasePtr aParentItem;
|
||||
if (!theParent.isValid())
|
||||
aParentItem = RootItem (theColumn);
|
||||
aParentItem = RootItem(theColumn);
|
||||
else
|
||||
aParentItem = GetItemByIndex (theParent);
|
||||
aParentItem = GetItemByIndex(theParent);
|
||||
|
||||
TreeModel_ItemBasePtr aChildItem = aParentItem->Child (theRow, theColumn);
|
||||
return aChildItem ? createIndex (theRow, theColumn, getIndexValue (aChildItem)) : QModelIndex();
|
||||
TreeModel_ItemBasePtr aChildItem = aParentItem->Child(theRow, theColumn);
|
||||
return aChildItem ? createIndex(theRow, theColumn, getIndexValue(aChildItem)) : QModelIndex();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : data
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
QVariant TreeModel_ModelBase::data (const QModelIndex& theIndex, int theRole) const
|
||||
QVariant TreeModel_ModelBase::data(const QModelIndex& theIndex, int theRole) const
|
||||
{
|
||||
if (!theIndex.isValid())
|
||||
return QVariant ("undefined");
|
||||
return QVariant("undefined");
|
||||
|
||||
if (IsUseVisibilityColumn() && theIndex.column() == TreeModel_ColumnType_Visibility)
|
||||
{
|
||||
if (theRole != Qt::DecorationRole)
|
||||
return QVariant();
|
||||
|
||||
TreeModel_ItemBasePtr anItem = GetItemByIndex (theIndex);
|
||||
if (!anItem->data (theIndex, theRole).isNull()) // value is already in cache
|
||||
return anItem->data (theIndex, theRole);
|
||||
TreeModel_ItemBasePtr anItem = GetItemByIndex(theIndex);
|
||||
if (!anItem->data(theIndex, theRole).isNull()) // value is already in cache
|
||||
return anItem->data(theIndex, theRole);
|
||||
|
||||
if (!anItem->IsInitialized())
|
||||
anItem->Init();
|
||||
|
||||
if (!myVisibilityState || !myVisibilityState->CanBeVisible (theIndex))
|
||||
if (!myVisibilityState || !myVisibilityState->CanBeVisible(theIndex))
|
||||
return QVariant();
|
||||
|
||||
QVariant aValue = myVisibilityState->IsVisible (theIndex) ? myVisibleIcon : myInvisibleIcon;
|
||||
anItem->SetCustomData (aValue, theRole);
|
||||
QVariant aValue = myVisibilityState->IsVisible(theIndex) ? myVisibleIcon : myInvisibleIcon;
|
||||
anItem->SetCustomData(aValue, theRole);
|
||||
return aValue;
|
||||
}
|
||||
|
||||
TreeModel_ItemBasePtr anItem = GetItemByIndex (theIndex);
|
||||
QVariant anItemData = anItem->data (theIndex, theRole);
|
||||
TreeModel_ItemBasePtr anItem = GetItemByIndex(theIndex);
|
||||
QVariant anItemData = anItem->data(theIndex, theRole);
|
||||
|
||||
if (anItemData.isNull() && theRole == Qt::BackgroundRole && myHighlightedIndices.contains (theIndex))
|
||||
if (anItemData.isNull() && theRole == Qt::BackgroundRole
|
||||
&& myHighlightedIndices.contains(theIndex))
|
||||
anItemData = TreeModel_Tools::LightHighlightColor();
|
||||
|
||||
return anItemData;
|
||||
@@ -141,25 +147,25 @@ QVariant TreeModel_ModelBase::data (const QModelIndex& theIndex, int theRole) co
|
||||
// function : parent
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
QModelIndex TreeModel_ModelBase::parent (const QModelIndex& theIndex) const
|
||||
QModelIndex TreeModel_ModelBase::parent(const QModelIndex& theIndex) const
|
||||
{
|
||||
if (!theIndex.isValid())
|
||||
return QModelIndex();
|
||||
|
||||
TreeModel_ItemBasePtr aChildItem = GetItemByIndex (theIndex);
|
||||
TreeModel_ItemBasePtr aChildItem = GetItemByIndex(theIndex);
|
||||
TreeModel_ItemBasePtr aParentItem = aChildItem ? aChildItem->Parent() : TreeModel_ItemBasePtr();
|
||||
|
||||
if (!aParentItem)
|
||||
return QModelIndex();
|
||||
|
||||
return createIndex (aParentItem->Row(), aParentItem->Column(), getIndexValue (aParentItem));
|
||||
return createIndex(aParentItem->Row(), aParentItem->Column(), getIndexValue(aParentItem));
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : flags
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Qt::ItemFlags TreeModel_ModelBase::flags (const QModelIndex& theIndex) const
|
||||
Qt::ItemFlags TreeModel_ModelBase::flags(const QModelIndex& theIndex) const
|
||||
{
|
||||
if (!theIndex.isValid())
|
||||
{
|
||||
@@ -172,7 +178,9 @@ Qt::ItemFlags TreeModel_ModelBase::flags (const QModelIndex& theIndex) const
|
||||
// function : headerData
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
QVariant TreeModel_ModelBase::headerData (int theSection, Qt::Orientation theOrientation, int theRole) const
|
||||
QVariant TreeModel_ModelBase::headerData(int theSection,
|
||||
Qt::Orientation theOrientation,
|
||||
int theRole) const
|
||||
{
|
||||
if (theOrientation != Qt::Horizontal || theRole != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
@@ -187,7 +195,7 @@ QVariant TreeModel_ModelBase::headerData (int theSection, Qt::Orientation theOri
|
||||
// function : rowCount
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
int TreeModel_ModelBase::rowCount (const QModelIndex& theParent) const
|
||||
int TreeModel_ModelBase::rowCount(const QModelIndex& theParent) const
|
||||
{
|
||||
// to create index on the root item
|
||||
if (!theParent.isValid())
|
||||
@@ -195,9 +203,9 @@ int TreeModel_ModelBase::rowCount (const QModelIndex& theParent) const
|
||||
|
||||
TreeModel_ItemBasePtr aParentItem;
|
||||
if (!theParent.isValid())
|
||||
aParentItem = RootItem (0);
|
||||
aParentItem = RootItem(0);
|
||||
else
|
||||
aParentItem = GetItemByIndex (theParent);
|
||||
aParentItem = GetItemByIndex(theParent);
|
||||
|
||||
if (!aParentItem)
|
||||
return 0;
|
||||
@@ -218,19 +226,20 @@ void TreeModel_ModelBase::EmitLayoutChanged()
|
||||
// function : EmitLayoutChanged
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void TreeModel_ModelBase::EmitDataChanged (const QModelIndex& theTopLeft, const QModelIndex& theBottomRight,
|
||||
const QVector<int>& theRoles,
|
||||
const bool isResetItem)
|
||||
void TreeModel_ModelBase::EmitDataChanged(const QModelIndex& theTopLeft,
|
||||
const QModelIndex& theBottomRight,
|
||||
const QVector<int>& theRoles,
|
||||
const bool isResetItem)
|
||||
{
|
||||
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (theTopLeft);
|
||||
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex(theTopLeft);
|
||||
if (anItemBase && isResetItem)
|
||||
anItemBase->Reset();
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
(void)theRoles;
|
||||
emit dataChanged (theTopLeft, theBottomRight);
|
||||
emit dataChanged(theTopLeft, theBottomRight);
|
||||
#else
|
||||
emit dataChanged (theTopLeft, theBottomRight, theRoles);
|
||||
emit dataChanged(theTopLeft, theBottomRight, theRoles);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -238,16 +247,19 @@ void TreeModel_ModelBase::EmitDataChanged (const QModelIndex& theTopLeft, const
|
||||
// function : Selected
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
QModelIndexList TreeModel_ModelBase::Selected (const QModelIndexList& theIndices, const int theCellId,
|
||||
const Qt::Orientation theOrientation)
|
||||
QModelIndexList TreeModel_ModelBase::Selected(const QModelIndexList& theIndices,
|
||||
const int theCellId,
|
||||
const Qt::Orientation theOrientation)
|
||||
{
|
||||
QModelIndexList aSelected;
|
||||
for (QModelIndexList::const_iterator anIndicesIt = theIndices.begin(); anIndicesIt != theIndices.end(); anIndicesIt++)
|
||||
for (QModelIndexList::const_iterator anIndicesIt = theIndices.begin();
|
||||
anIndicesIt != theIndices.end();
|
||||
anIndicesIt++)
|
||||
{
|
||||
QModelIndex anIndex = *anIndicesIt;
|
||||
if ((theOrientation == Qt::Horizontal && anIndex.column() == theCellId) ||
|
||||
(theOrientation == Qt::Vertical && anIndex.row() == theCellId))
|
||||
aSelected.append (anIndex);
|
||||
if ((theOrientation == Qt::Horizontal && anIndex.column() == theCellId)
|
||||
|| (theOrientation == Qt::Vertical && anIndex.row() == theCellId))
|
||||
aSelected.append(anIndex);
|
||||
}
|
||||
return aSelected;
|
||||
}
|
||||
@@ -256,10 +268,11 @@ QModelIndexList TreeModel_ModelBase::Selected (const QModelIndexList& theIndices
|
||||
// function : SingleSelected
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
QModelIndex TreeModel_ModelBase::SingleSelected (const QModelIndexList& theIndices, const int theCellId,
|
||||
const Qt::Orientation theOrientation)
|
||||
QModelIndex TreeModel_ModelBase::SingleSelected(const QModelIndexList& theIndices,
|
||||
const int theCellId,
|
||||
const Qt::Orientation theOrientation)
|
||||
{
|
||||
QModelIndexList aSelected = Selected (theIndices, theCellId, theOrientation);
|
||||
QModelIndexList aSelected = Selected(theIndices, theCellId, theOrientation);
|
||||
return aSelected.size() == 1 ? aSelected.first() : QModelIndex();
|
||||
}
|
||||
|
||||
@@ -267,16 +280,18 @@ QModelIndex TreeModel_ModelBase::SingleSelected (const QModelIndexList& theIndic
|
||||
// function : SelectedItems
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
QList<TreeModel_ItemBasePtr> TreeModel_ModelBase::SelectedItems (const QModelIndexList& theIndices)
|
||||
QList<TreeModel_ItemBasePtr> TreeModel_ModelBase::SelectedItems(const QModelIndexList& theIndices)
|
||||
{
|
||||
QList<TreeModel_ItemBasePtr> anItems;
|
||||
|
||||
for (QModelIndexList::const_iterator anIndicesIt = theIndices.begin(); anIndicesIt != theIndices.end(); anIndicesIt++)
|
||||
for (QModelIndexList::const_iterator anIndicesIt = theIndices.begin();
|
||||
anIndicesIt != theIndices.end();
|
||||
anIndicesIt++)
|
||||
{
|
||||
TreeModel_ItemBasePtr anItem = TreeModel_ModelBase::GetItemByIndex (*anIndicesIt);
|
||||
if (!anItem || anItems.contains (anItem))
|
||||
TreeModel_ItemBasePtr anItem = TreeModel_ModelBase::GetItemByIndex(*anIndicesIt);
|
||||
if (!anItem || anItems.contains(anItem))
|
||||
continue;
|
||||
anItems.append (anItem);
|
||||
anItems.append(anItem);
|
||||
}
|
||||
return anItems;
|
||||
}
|
||||
@@ -285,17 +300,20 @@ QList<TreeModel_ItemBasePtr> TreeModel_ModelBase::SelectedItems (const QModelInd
|
||||
// function : SubItemsPresentations
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void TreeModel_ModelBase::SubItemsPresentations (const QModelIndexList& theIndices,
|
||||
NCollection_List<Handle(Standard_Transient)>& thePresentations)
|
||||
void TreeModel_ModelBase::SubItemsPresentations(
|
||||
const QModelIndexList& theIndices,
|
||||
NCollection_List<Handle(Standard_Transient)>& thePresentations)
|
||||
{
|
||||
QList<TreeModel_ItemBasePtr> anItems;
|
||||
|
||||
for (QModelIndexList::const_iterator anIndicesIt = theIndices.begin(); anIndicesIt != theIndices.end(); anIndicesIt++)
|
||||
for (QModelIndexList::const_iterator anIndicesIt = theIndices.begin();
|
||||
anIndicesIt != theIndices.end();
|
||||
anIndicesIt++)
|
||||
{
|
||||
TreeModel_ItemBasePtr anItem = TreeModel_ModelBase::GetItemByIndex (*anIndicesIt);
|
||||
if (!anItem || anItems.contains (anItem))
|
||||
TreeModel_ItemBasePtr anItem = TreeModel_ModelBase::GetItemByIndex(*anIndicesIt);
|
||||
if (!anItem || anItems.contains(anItem))
|
||||
continue;
|
||||
subItemsPresentations (anItem, thePresentations);
|
||||
subItemsPresentations(anItem, thePresentations);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,15 +321,16 @@ void TreeModel_ModelBase::SubItemsPresentations (const QModelIndexList& theIndic
|
||||
// function : subItemPresentations
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void TreeModel_ModelBase::subItemsPresentations (const TreeModel_ItemBasePtr& theItem,
|
||||
NCollection_List<Handle(Standard_Transient)>& thePresentations)
|
||||
void TreeModel_ModelBase::subItemsPresentations(
|
||||
const TreeModel_ItemBasePtr& theItem,
|
||||
NCollection_List<Handle(Standard_Transient)>& thePresentations)
|
||||
{
|
||||
theItem->Presentations (thePresentations);
|
||||
theItem->Presentations(thePresentations);
|
||||
|
||||
QList<TreeModel_ItemBasePtr> anItems;
|
||||
for (int aRowId = 0; aRowId < theItem->rowCount(); aRowId++)
|
||||
{
|
||||
subItemsPresentations (theItem->Child (aRowId, theItem->Column()), thePresentations);
|
||||
subItemsPresentations(theItem->Child(aRowId, theItem->Column()), thePresentations);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,33 +338,34 @@ void TreeModel_ModelBase::subItemsPresentations (const TreeModel_ItemBasePtr& th
|
||||
// function : createRoot
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void TreeModel_ModelBase::createRoot (const int theColumnId)
|
||||
void TreeModel_ModelBase::createRoot(const int theColumnId)
|
||||
{
|
||||
myRootItems.insert (theColumnId, createRootItem (theColumnId));
|
||||
myRootItems.insert(theColumnId, createRootItem(theColumnId));
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : setHeaderItem
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void TreeModel_ModelBase::setHeaderItem (const int theColumnId, const TreeModel_HeaderSection& theSection)
|
||||
void TreeModel_ModelBase::setHeaderItem(const int theColumnId,
|
||||
const TreeModel_HeaderSection& theSection)
|
||||
{
|
||||
if (theSection.IsEmpty())
|
||||
{
|
||||
// remove section
|
||||
myHeaderValues.remove (theColumnId);
|
||||
myRootItems.remove (theColumnId);
|
||||
myHeaderValues.remove(theColumnId);
|
||||
myRootItems.remove(theColumnId);
|
||||
}
|
||||
|
||||
myHeaderValues[theColumnId] = theSection;
|
||||
createRoot (theColumnId);
|
||||
createRoot(theColumnId);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : getIndexValue
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void* TreeModel_ModelBase::getIndexValue (const TreeModel_ItemBasePtr& theItem)
|
||||
void* TreeModel_ModelBase::getIndexValue(const TreeModel_ItemBasePtr& theItem)
|
||||
{
|
||||
return theItem.data();
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@
|
||||
// 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.
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef TreeModel_ModelBase_H
|
||||
#define TreeModel_ModelBase_H
|
||||
@@ -35,17 +35,16 @@ class TreeModel_VisibilityState;
|
||||
|
||||
//! \class TreeModel_ModelBase
|
||||
//! \brief Implementation of the tree item based model of QAbstractItemModel.
|
||||
//! The TreeModel_ModelBase class defines the abstract model realization through the base item architecture.
|
||||
//! By the model index creation, a base item is created and attached to the index.
|
||||
//! The TreeModel_ModelBase class defines the abstract model realization through the base item
|
||||
//! architecture. By the model index creation, a base item is created and attached to the index.
|
||||
//! Each item contains an iformation about the item parent, position in the parent and
|
||||
//! the item's children. So, it is possible to get the model index relation from the item.
|
||||
class TreeModel_ModelBase : public QAbstractItemModel
|
||||
{
|
||||
public:
|
||||
|
||||
//! Constructor
|
||||
//! \param theParent the parent object
|
||||
Standard_EXPORT TreeModel_ModelBase (QObject* theParent = 0);
|
||||
Standard_EXPORT TreeModel_ModelBase(QObject* theParent = 0);
|
||||
|
||||
//! Destructor
|
||||
virtual ~TreeModel_ModelBase() {}
|
||||
@@ -57,7 +56,7 @@ public:
|
||||
//! Returns the item shared pointer by the model index
|
||||
//! if it is in the index internal pointer
|
||||
//! @param theIndex a model index
|
||||
Standard_EXPORT static TreeModel_ItemBasePtr GetItemByIndex (const QModelIndex& theIndex);
|
||||
Standard_EXPORT static TreeModel_ItemBasePtr GetItemByIndex(const QModelIndex& theIndex);
|
||||
|
||||
//! Resets the model items content. Calls the same method of the root item.
|
||||
//! It leads to reset of all child/sub child items.
|
||||
@@ -65,18 +64,20 @@ public:
|
||||
|
||||
//! Returns the model root item.
|
||||
//! It is realized for OCAFBrowser
|
||||
TreeModel_ItemBasePtr RootItem (const int theColumn) const { return myRootItems[theColumn]; }
|
||||
TreeModel_ItemBasePtr RootItem(const int theColumn) const { return myRootItems[theColumn]; }
|
||||
|
||||
//! Emits the layoutChanged signal from outside of this class
|
||||
Standard_EXPORT void EmitLayoutChanged();
|
||||
|
||||
//! Emits the dataChanged signal from outside of this class
|
||||
Standard_EXPORT void EmitDataChanged (const QModelIndex& theTopLeft, const QModelIndex& theBottomRight,
|
||||
const QVector<int>& theRoles = QVector<int>(), const bool isResetItem = true);
|
||||
Standard_EXPORT void EmitDataChanged(const QModelIndex& theTopLeft,
|
||||
const QModelIndex& theBottomRight,
|
||||
const QVector<int>& theRoles = QVector<int>(),
|
||||
const bool isResetItem = true);
|
||||
|
||||
//! Sets state whether visibility column (0) is used in the model
|
||||
//! \param theState state
|
||||
void SetUseVisibilityColumn (const bool theState) { m_pUseVisibilityColumn = theState; }
|
||||
void SetUseVisibilityColumn(const bool theState) { m_pUseVisibilityColumn = theState; }
|
||||
|
||||
//! Returns state whether visibility column (0) is used in the model
|
||||
//! \param theState state
|
||||
@@ -84,70 +85,84 @@ public:
|
||||
|
||||
//! Fills visibility state checker
|
||||
//! \param theController the checker interface
|
||||
void SetVisibilityState (TreeModel_VisibilityState* theController) { myVisibilityState = theController; }
|
||||
void SetVisibilityState(TreeModel_VisibilityState* theController)
|
||||
{
|
||||
myVisibilityState = theController;
|
||||
}
|
||||
|
||||
//! Returns visibility state checker
|
||||
//! \return the checker interface
|
||||
TreeModel_VisibilityState* GetVisibilityState () const { return myVisibilityState; }
|
||||
TreeModel_VisibilityState* GetVisibilityState() const { return myVisibilityState; }
|
||||
|
||||
//! Returns true if the tree view model contains highlighted items. This highlight is set manually.
|
||||
//! Returns true if the tree view model contains highlighted items. This highlight is set
|
||||
//! manually.
|
||||
bool HasHighlighted() { return !myHighlightedIndices.isEmpty(); }
|
||||
|
||||
//! Sets items of the indices highlighted in the model.
|
||||
//! \param theIndices a list of tree model indices
|
||||
void SetHighlighted (const QModelIndexList& theIndices = QModelIndexList()) { myHighlightedIndices = theIndices; }
|
||||
void SetHighlighted(const QModelIndexList& theIndices = QModelIndexList())
|
||||
{
|
||||
myHighlightedIndices = theIndices;
|
||||
}
|
||||
|
||||
//! Returns the index of the item in the model specified by the given row, column and parent index.
|
||||
//! Saves an internal pointer at the createIndex. This pointer is a shared pointer to the class,
|
||||
//! that realizes a base item interface. If the parent is invalid, a root item is used, otherwise a new item
|
||||
//! is created by the pointer item saved the parent model index
|
||||
//! \param theRow the index row position
|
||||
//! \param theColummn the index column position
|
||||
//! \param theParent the parent index
|
||||
//! \return the model index
|
||||
Standard_EXPORT virtual QModelIndex index (int theRow, int theColumn,
|
||||
const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE;
|
||||
//! Returns the index of the item in the model specified by the given row, column and parent
|
||||
//! index. Saves an internal pointer at the createIndex. This pointer is a shared pointer to the
|
||||
//! class, that realizes a base item interface. If the parent is invalid, a root item is used,
|
||||
//! otherwise a new item is created by the pointer item saved the parent model index \param theRow
|
||||
//! the index row position \param theColummn the index column position \param theParent the parent
|
||||
//! index \return the model index
|
||||
Standard_EXPORT virtual QModelIndex index(int theRow,
|
||||
int theColumn,
|
||||
const QModelIndex& theParent = QModelIndex()) const
|
||||
Standard_OVERRIDE;
|
||||
|
||||
//! Returns the data stored under the given role for the item referred to by the index.
|
||||
//! \param theIndex a model index
|
||||
//! \param theRole an enumeration value of role for data obtaining
|
||||
Standard_EXPORT virtual QVariant data (const QModelIndex& theIndex, int theRole = Qt::DisplayRole) const Standard_OVERRIDE;
|
||||
Standard_EXPORT virtual QVariant data(const QModelIndex& theIndex,
|
||||
int theRole = Qt::DisplayRole) const Standard_OVERRIDE;
|
||||
|
||||
//! Returns the parent index by the child index. Founds the item, saved in the index;
|
||||
//! obtains the parent item by the item. Create a new index by the item and containing it.
|
||||
//! \param theIndex a model index
|
||||
Standard_EXPORT virtual QModelIndex parent (const QModelIndex& theIndex) const Standard_OVERRIDE;
|
||||
Standard_EXPORT virtual QModelIndex parent(const QModelIndex& theIndex) const Standard_OVERRIDE;
|
||||
|
||||
//! Returns the item flags for the given index. The base class implementation returns a combination of flags that
|
||||
//! enables the item (ItemIsEnabled) and allows it to be selected (ItemIsSelectable)
|
||||
//! \param theIndex the model index
|
||||
//! \return Qt flag combination
|
||||
Standard_EXPORT virtual Qt::ItemFlags flags (const QModelIndex& theIndex) const Standard_OVERRIDE;
|
||||
//! Returns the item flags for the given index. The base class implementation returns a
|
||||
//! combination of flags that enables the item (ItemIsEnabled) and allows it to be selected
|
||||
//! (ItemIsSelectable) \param theIndex the model index \return Qt flag combination
|
||||
Standard_EXPORT virtual Qt::ItemFlags flags(const QModelIndex& theIndex) const Standard_OVERRIDE;
|
||||
|
||||
//! Returns the header data for the given role and section in the header with the specified orientation.
|
||||
//! \param theSection the header section. For horizontal headers - column number, for vertical headers - row number.
|
||||
//! \param theOrientation a header orientation
|
||||
//! \param theRole a data role
|
||||
//! \return the header data
|
||||
Standard_EXPORT virtual QVariant headerData (int theSection, Qt::Orientation theOrientation,
|
||||
int theRole = Qt::DisplayRole) const Standard_OVERRIDE;
|
||||
//! Returns the header data for the given role and section in the header with the specified
|
||||
//! orientation. \param theSection the header section. For horizontal headers - column number, for
|
||||
//! vertical headers - row number. \param theOrientation a header orientation \param theRole a
|
||||
//! data role \return the header data
|
||||
Standard_EXPORT virtual QVariant headerData(int theSection,
|
||||
Qt::Orientation theOrientation,
|
||||
int theRole = Qt::DisplayRole) const
|
||||
Standard_OVERRIDE;
|
||||
|
||||
//! Returns the number of rows under the given parent. When the parent is valid it means that rowCount is returning
|
||||
//! the number of children of parent.
|
||||
//! \param theParent a parent model index
|
||||
//! Returns the number of rows under the given parent. When the parent is valid it means that
|
||||
//! rowCount is returning the number of children of parent. \param theParent a parent model index
|
||||
//! \return the number of rows
|
||||
Standard_EXPORT virtual int rowCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE;
|
||||
Standard_EXPORT virtual int rowCount(const QModelIndex& theParent = QModelIndex()) const
|
||||
Standard_OVERRIDE;
|
||||
|
||||
//! Returns header item, that can be modified
|
||||
//! \param theColumnId a column index
|
||||
//! \return header section value
|
||||
TreeModel_HeaderSection* ChangeHeaderItem (const int theColumnId) { return &myHeaderValues[theColumnId]; }
|
||||
TreeModel_HeaderSection* ChangeHeaderItem(const int theColumnId)
|
||||
{
|
||||
return &myHeaderValues[theColumnId];
|
||||
}
|
||||
|
||||
//! Returns count of columns in the model
|
||||
//! \param theParent an index of the parent item
|
||||
//! \return integer value
|
||||
virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
|
||||
{ (void)theParent; return myHeaderValues.size(); }
|
||||
virtual int columnCount(const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
|
||||
{
|
||||
(void)theParent;
|
||||
return myHeaderValues.size();
|
||||
}
|
||||
|
||||
//! Returns default value of the visibility column
|
||||
//! \return integer value
|
||||
@@ -158,67 +173,74 @@ public:
|
||||
//! \param theCellId column index if orientation is horizontal, row index otherwise
|
||||
//! \param theOrientation an orientation to apply the cell index
|
||||
//! \return model indices from the list
|
||||
Standard_EXPORT static QModelIndexList Selected (const QModelIndexList& theIndices, const int theCellId,
|
||||
const Qt::Orientation theOrientation = Qt::Horizontal);
|
||||
Standard_EXPORT static QModelIndexList Selected(
|
||||
const QModelIndexList& theIndices,
|
||||
const int theCellId,
|
||||
const Qt::Orientation theOrientation = Qt::Horizontal);
|
||||
|
||||
//! Returns single selected item in the cell of given orientation. If the orientation is Horizontal,
|
||||
//! in the cell id column, one row should be selected.
|
||||
//! \param theIndices a container of selected indices
|
||||
//! \param theCellId column index if orientation is horizontal, row index otherwise
|
||||
//! \param theOrientation an orientation to apply the cell index
|
||||
//! \return model index from the list
|
||||
Standard_EXPORT static QModelIndex SingleSelected (const QModelIndexList& theIndices, const int theCellId,
|
||||
const Qt::Orientation theOrientation = Qt::Horizontal);
|
||||
//! Returns single selected item in the cell of given orientation. If the orientation is
|
||||
//! Horizontal, in the cell id column, one row should be selected. \param theIndices a container
|
||||
//! of selected indices \param theCellId column index if orientation is horizontal, row index
|
||||
//! otherwise \param theOrientation an orientation to apply the cell index \return model index
|
||||
//! from the list
|
||||
Standard_EXPORT static QModelIndex SingleSelected(
|
||||
const QModelIndexList& theIndices,
|
||||
const int theCellId,
|
||||
const Qt::Orientation theOrientation = Qt::Horizontal);
|
||||
|
||||
//! Returns selected tree model items for indices.
|
||||
//! \param theIndices a container of selected indices
|
||||
//! \return model items from the list
|
||||
Standard_EXPORT static QList<TreeModel_ItemBasePtr> SelectedItems (const QModelIndexList& theIndices);
|
||||
Standard_EXPORT static QList<TreeModel_ItemBasePtr> SelectedItems(
|
||||
const QModelIndexList& theIndices);
|
||||
|
||||
//! Returns presentations of sub items
|
||||
//! \param theIndices a container of selected indices
|
||||
//! \thePresentations[out] container of presentations
|
||||
Standard_EXPORT static void SubItemsPresentations (const QModelIndexList& theIndices,
|
||||
NCollection_List<Handle(Standard_Transient)>& thePresentations);
|
||||
Standard_EXPORT static void SubItemsPresentations(
|
||||
const QModelIndexList& theIndices,
|
||||
NCollection_List<Handle(Standard_Transient)>& thePresentations);
|
||||
|
||||
protected:
|
||||
//! Creates root item
|
||||
//! \param theColumnId index of a column
|
||||
virtual TreeModel_ItemBasePtr createRootItem (const int theColumnId) = 0;
|
||||
virtual TreeModel_ItemBasePtr createRootItem(const int theColumnId) = 0;
|
||||
|
||||
//! Sets header properties item.
|
||||
//! \param theColumnId a column index
|
||||
//! \param theSection a section value
|
||||
Standard_EXPORT void setHeaderItem (const int theColumnId, const TreeModel_HeaderSection& theSection);
|
||||
Standard_EXPORT void setHeaderItem(const int theColumnId,
|
||||
const TreeModel_HeaderSection& theSection);
|
||||
|
||||
//! Converts the item shared pointer to void* type
|
||||
//! \param theItem
|
||||
//! \return an item pointer
|
||||
Standard_EXPORT static void* getIndexValue (const TreeModel_ItemBasePtr& theItem);
|
||||
Standard_EXPORT static void* getIndexValue(const TreeModel_ItemBasePtr& theItem);
|
||||
|
||||
//! Returns presentations of sub items. Recursive method to get presentations of all children
|
||||
//! \param theItem an item to get own presentations and presentations of children
|
||||
//! \thePresentations[out] container of presentations found
|
||||
static void subItemsPresentations (const TreeModel_ItemBasePtr& theItem,
|
||||
static void subItemsPresentations(const TreeModel_ItemBasePtr& theItem,
|
||||
NCollection_List<Handle(Standard_Transient)>& thePresentations);
|
||||
|
||||
private:
|
||||
//! Creates root item
|
||||
//! \param theColumnId index of a column
|
||||
Standard_EXPORT void createRoot (const int theColumnId);
|
||||
Standard_EXPORT void createRoot(const int theColumnId);
|
||||
|
||||
protected:
|
||||
|
||||
QMap<int, TreeModel_ItemBasePtr> myRootItems; //!< container of root items, for each column own root item
|
||||
QMap<int, TreeModel_ItemBasePtr>
|
||||
myRootItems; //!< container of root items, for each column own root item
|
||||
QMap<int, TreeModel_HeaderSection> myHeaderValues; //!< header values
|
||||
//!< model subclass. The model is fulfilled by this item content
|
||||
|
||||
bool m_pUseVisibilityColumn; //!< the state whether column=0 is reserved for Visibility state
|
||||
TreeModel_VisibilityState* myVisibilityState; //!< the interface of item visibility
|
||||
QIcon myVisibleIcon; //!< icon of visible state
|
||||
QIcon myInvisibleIcon; //!< icon of invisible state
|
||||
QIcon myVisibleIcon; //!< icon of visible state
|
||||
QIcon myInvisibleIcon; //!< icon of invisible state
|
||||
|
||||
QModelIndexList myHighlightedIndices; //!< tree model indices that should be visualized as highlighted
|
||||
QModelIndexList
|
||||
myHighlightedIndices; //!< tree model indices that should be visualized as highlighted
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -11,7 +11,7 @@
|
||||
// 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.
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <inspector/TreeModel_Tools.hxx>
|
||||
#include <inspector/TreeModel_ModelBase.hxx>
|
||||
@@ -37,44 +37,44 @@ const int INFO_LENGHT = 60;
|
||||
// function : ToString
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
QString TreeModel_Tools::ToString (const QByteArray& theValue)
|
||||
QString TreeModel_Tools::ToString(const QByteArray& theValue)
|
||||
{
|
||||
char aBuffer[8];
|
||||
char aBuffer[8];
|
||||
QStringList aBytesList;
|
||||
for (int aByteId = 0; aByteId < theValue.size(); aByteId++)
|
||||
for (int aByteId = 0; aByteId < theValue.size(); aByteId++)
|
||||
{
|
||||
::sprintf (aBuffer, "#%02X", (unsigned char)theValue.at (aByteId));
|
||||
aBytesList.append (QString (aBuffer));
|
||||
::sprintf(aBuffer, "#%02X", (unsigned char)theValue.at(aByteId));
|
||||
aBytesList.append(QString(aBuffer));
|
||||
}
|
||||
return QString ("@ByteArray[%1]").arg (aBytesList.join (" "));
|
||||
return QString("@ByteArray[%1]").arg(aBytesList.join(" "));
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ToByteArray
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
QByteArray TreeModel_Tools::ToByteArray (const QString& theValue)
|
||||
QByteArray TreeModel_Tools::ToByteArray(const QString& theValue)
|
||||
{
|
||||
QByteArray aStateArray;
|
||||
if (!theValue.startsWith ("@ByteArray[") || !theValue.endsWith (']'))
|
||||
if (!theValue.startsWith("@ByteArray[") || !theValue.endsWith(']'))
|
||||
return aStateArray;
|
||||
|
||||
QString aValue = theValue.mid (11, theValue.size() - 12);
|
||||
QStringList lst = aValue.split (QRegExp ("[\\s|,]"), QString::SkipEmptyParts);
|
||||
QString aValue = theValue.mid(11, theValue.size() - 12);
|
||||
QStringList lst = aValue.split(QRegExp("[\\s|,]"), QString::SkipEmptyParts);
|
||||
for (QStringList::ConstIterator aByteId = lst.begin(); aByteId != lst.end(); ++aByteId)
|
||||
{
|
||||
int aBase = 10;
|
||||
int aBase = 10;
|
||||
QString aString = *aByteId;
|
||||
if (aString.startsWith ("#"))
|
||||
if (aString.startsWith("#"))
|
||||
{
|
||||
aBase = 16;
|
||||
aString = aString.mid (1);
|
||||
aBase = 16;
|
||||
aString = aString.mid(1);
|
||||
}
|
||||
bool isOk = false;
|
||||
int aNum = aString.toInt (&isOk, aBase);
|
||||
int aNum = aString.toInt(&isOk, aBase);
|
||||
if (!isOk || aNum < 0 || aNum > 255)
|
||||
continue;
|
||||
aStateArray.append ((char)aNum);
|
||||
aStateArray.append((char)aNum);
|
||||
}
|
||||
return aStateArray;
|
||||
}
|
||||
@@ -83,38 +83,43 @@ QByteArray TreeModel_Tools::ToByteArray (const QString& theValue)
|
||||
// function : SaveState
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void TreeModel_Tools::SaveState (QTreeView* theTreeView, QMap<QString, QString>& theItems,
|
||||
const QString& thePrefix)
|
||||
void TreeModel_Tools::SaveState(QTreeView* theTreeView,
|
||||
QMap<QString, QString>& theItems,
|
||||
const QString& thePrefix)
|
||||
{
|
||||
QStringList aColumnWidths;
|
||||
for (int aColumnId = 0; aColumnId < theTreeView->model()->columnCount(); aColumnId++)
|
||||
{
|
||||
if (theTreeView->isColumnHidden (aColumnId))
|
||||
if (theTreeView->isColumnHidden(aColumnId))
|
||||
{
|
||||
aColumnWidths.append (QString());
|
||||
aColumnWidths.append(QString());
|
||||
}
|
||||
else
|
||||
aColumnWidths.append (QString::number (theTreeView->columnWidth (aColumnId)));
|
||||
aColumnWidths.append(QString::number(theTreeView->columnWidth(aColumnId)));
|
||||
}
|
||||
theItems[thePrefix + "columns_width"] = aColumnWidths.join (",");
|
||||
theItems[thePrefix + "columns_width"] = aColumnWidths.join(",");
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : RestoreState
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool TreeModel_Tools::RestoreState (QTreeView* theTreeView, const QString& theKey, const QString& theValue,
|
||||
const QString& thePrefix)
|
||||
bool TreeModel_Tools::RestoreState(QTreeView* theTreeView,
|
||||
const QString& theKey,
|
||||
const QString& theValue,
|
||||
const QString& thePrefix)
|
||||
{
|
||||
if (theKey == thePrefix + "columns_width")
|
||||
{
|
||||
QStringList aValues = theValue.split (",");
|
||||
for (int aColumnId = 0; aColumnId < theTreeView->model()->columnCount() && aColumnId < aValues.size(); aColumnId++)
|
||||
QStringList aValues = theValue.split(",");
|
||||
for (int aColumnId = 0;
|
||||
aColumnId < theTreeView->model()->columnCount() && aColumnId < aValues.size();
|
||||
aColumnId++)
|
||||
{
|
||||
bool isOk;
|
||||
int aWidth = aValues.at (aColumnId).toInt (&isOk);
|
||||
if (isOk && !theTreeView->isColumnHidden (aColumnId)) // do not resize hidden columns
|
||||
theTreeView->setColumnWidth (aColumnId, aWidth);
|
||||
int aWidth = aValues.at(aColumnId).toInt(&isOk);
|
||||
if (isOk && !theTreeView->isColumnHidden(aColumnId)) // do not resize hidden columns
|
||||
theTreeView->setColumnWidth(aColumnId, aWidth);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -128,13 +133,14 @@ bool TreeModel_Tools::RestoreState (QTreeView* theTreeView, const QString& theKe
|
||||
// =======================================================================
|
||||
void TreeModel_Tools::SetDefaultHeaderSections(QTreeView* theTreeView)
|
||||
{
|
||||
TreeModel_ModelBase* aTreeModel = dynamic_cast<TreeModel_ModelBase*> (theTreeView->model());
|
||||
TreeModel_ModelBase* aTreeModel = dynamic_cast<TreeModel_ModelBase*>(theTreeView->model());
|
||||
|
||||
for (int aColumnId = 0, aNbColumns = aTreeModel->columnCount(); aColumnId < aNbColumns; aColumnId++)
|
||||
for (int aColumnId = 0, aNbColumns = aTreeModel->columnCount(); aColumnId < aNbColumns;
|
||||
aColumnId++)
|
||||
{
|
||||
TreeModel_HeaderSection* aSection = aTreeModel->ChangeHeaderItem (aColumnId);
|
||||
theTreeView->setColumnWidth (aColumnId, aSection->GetWidth());
|
||||
theTreeView->setColumnHidden (aColumnId, aSection->IsHidden());
|
||||
TreeModel_HeaderSection* aSection = aTreeModel->ChangeHeaderItem(aColumnId);
|
||||
theTreeView->setColumnWidth(aColumnId, aSection->GetWidth());
|
||||
theTreeView->setColumnHidden(aColumnId, aSection->IsHidden());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,53 +148,56 @@ void TreeModel_Tools::SetDefaultHeaderSections(QTreeView* theTreeView)
|
||||
// function : UseVisibilityColumn
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void TreeModel_Tools::UseVisibilityColumn (QTreeView* theTreeView, const bool theActive)
|
||||
void TreeModel_Tools::UseVisibilityColumn(QTreeView* theTreeView, const bool theActive)
|
||||
{
|
||||
QHeaderView* aHeader = theTreeView->header();
|
||||
#if QT_VERSION < 0x050000
|
||||
aHeader->setResizeMode (TreeModel_ColumnType_Visibility, QHeaderView::Fixed);
|
||||
aHeader->setResizeMode(TreeModel_ColumnType_Visibility, QHeaderView::Fixed);
|
||||
#else
|
||||
aHeader->setSectionResizeMode (TreeModel_ColumnType_Visibility, QHeaderView::Fixed);
|
||||
aHeader->setSectionResizeMode(TreeModel_ColumnType_Visibility, QHeaderView::Fixed);
|
||||
#endif
|
||||
aHeader->moveSection (TreeModel_ColumnType_Name, TreeModel_ColumnType_Visibility);
|
||||
aHeader->moveSection(TreeModel_ColumnType_Name, TreeModel_ColumnType_Visibility);
|
||||
|
||||
TreeModel_ModelBase* aModel = dynamic_cast<TreeModel_ModelBase*> (theTreeView->model());
|
||||
TreeModel_HeaderSection* anItem = aModel->ChangeHeaderItem ((int)TreeModel_ColumnType_Visibility);
|
||||
anItem->SetIsHidden (theActive);
|
||||
anItem->SetWidth (TreeModel_ModelBase::ColumnVisibilityWidth());
|
||||
TreeModel_ModelBase* aModel = dynamic_cast<TreeModel_ModelBase*>(theTreeView->model());
|
||||
TreeModel_HeaderSection* anItem = aModel->ChangeHeaderItem((int)TreeModel_ColumnType_Visibility);
|
||||
anItem->SetIsHidden(theActive);
|
||||
anItem->SetWidth(TreeModel_ModelBase::ColumnVisibilityWidth());
|
||||
|
||||
aModel->SetUseVisibilityColumn (theActive);
|
||||
aModel->SetUseVisibilityColumn(theActive);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : GetTextWidth
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
int TreeModel_Tools::GetTextWidth (const QString& theText, QObject*)
|
||||
int TreeModel_Tools::GetTextWidth(const QString& theText, QObject*)
|
||||
{
|
||||
// TODO: find margins like QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, (QWidget*)theParent);
|
||||
int aTextMargin = 10;
|
||||
QFontMetrics aFontMetrics (QApplication::font());
|
||||
QRect aBoundingRect = aFontMetrics.boundingRect (theText);
|
||||
return qMax (aBoundingRect.width(), aFontMetrics.width (theText)) + aTextMargin * 2;
|
||||
// TODO: find margins like QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0,
|
||||
// (QWidget*)theParent);
|
||||
int aTextMargin = 10;
|
||||
QFontMetrics aFontMetrics(QApplication::font());
|
||||
QRect aBoundingRect = aFontMetrics.boundingRect(theText);
|
||||
return qMax(aBoundingRect.width(), aFontMetrics.width(theText)) + aTextMargin * 2;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : CutString
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
QString TreeModel_Tools::CutString (const QString& theText, const int theWidth, const QString& theTail)
|
||||
QString TreeModel_Tools::CutString(const QString& theText,
|
||||
const int theWidth,
|
||||
const QString& theTail)
|
||||
{
|
||||
if (theText.isEmpty())
|
||||
return theText;
|
||||
|
||||
int aLength = theWidth < 0 ? INFO_LENGHT : theWidth - 3;
|
||||
|
||||
int anIndex = theText.indexOf ('\n');
|
||||
int anIndex = theText.indexOf('\n');
|
||||
if (anIndex > 0 && anIndex < aLength)
|
||||
aLength = anIndex;
|
||||
|
||||
return aLength < theText.length() ? theText.mid (0, aLength) + theTail : theText;
|
||||
return aLength < theText.length() ? theText.mid(0, aLength) + theTail : theText;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
@@ -197,7 +206,7 @@ QString TreeModel_Tools::CutString (const QString& theText, const int theWidth,
|
||||
// =======================================================================
|
||||
QColor TreeModel_Tools::LightHighlightColor()
|
||||
{
|
||||
QWidget aWidget;
|
||||
QWidget aWidget;
|
||||
QPalette aPalette = aWidget.palette();
|
||||
return aPalette.highlight().color().lighter();
|
||||
}
|
||||
@@ -206,15 +215,15 @@ QColor TreeModel_Tools::LightHighlightColor()
|
||||
// function : SetExpandedTo
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void TreeModel_Tools::SetExpandedTo (QTreeView* theTreeView, const QModelIndex& theIndex)
|
||||
void TreeModel_Tools::SetExpandedTo(QTreeView* theTreeView, const QModelIndex& theIndex)
|
||||
{
|
||||
QAbstractItemModel* aModel = theTreeView->model();
|
||||
|
||||
QModelIndex aParent = aModel->parent (theIndex);
|
||||
QModelIndex aParent = aModel->parent(theIndex);
|
||||
while (aParent.isValid())
|
||||
{
|
||||
theTreeView->setExpanded (aParent, true);
|
||||
aParent = aModel->parent (aParent);
|
||||
theTreeView->setExpanded(aParent, true);
|
||||
aParent = aModel->parent(aParent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,21 +231,23 @@ void TreeModel_Tools::SetExpandedTo (QTreeView* theTreeView, const QModelIndex&
|
||||
// function : setExpanded
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void TreeModel_Tools::SetExpanded (QTreeView* theTreeView, const QModelIndex& theIndex, const bool isExpanded,
|
||||
int& theLevels)
|
||||
void TreeModel_Tools::SetExpanded(QTreeView* theTreeView,
|
||||
const QModelIndex& theIndex,
|
||||
const bool isExpanded,
|
||||
int& theLevels)
|
||||
{
|
||||
bool isToExpand = theLevels == -1 || theLevels > 0;
|
||||
if (!isToExpand)
|
||||
return;
|
||||
|
||||
theTreeView->setExpanded (theIndex, isExpanded);
|
||||
theTreeView->setExpanded(theIndex, isExpanded);
|
||||
if (theLevels != -1)
|
||||
theLevels--;
|
||||
|
||||
QAbstractItemModel* aModel = theTreeView->model();
|
||||
for (int aRowId = 0, aRows = aModel->rowCount (theIndex); aRowId < aRows; aRowId++)
|
||||
for (int aRowId = 0, aRows = aModel->rowCount(theIndex); aRowId < aRows; aRowId++)
|
||||
{
|
||||
int aLevels = theLevels;
|
||||
SetExpanded (theTreeView, aModel->index (aRowId, 0, theIndex), isExpanded, aLevels);
|
||||
SetExpanded(theTreeView, aModel->index(aRowId, 0, theIndex), isExpanded, aLevels);
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@
|
||||
// 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.
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef TreeModel_Tools_H
|
||||
#define TreeModel_Tools_H
|
||||
@@ -38,20 +38,19 @@ class QTreeView;
|
||||
class TreeModel_Tools
|
||||
{
|
||||
public:
|
||||
|
||||
//! Converts a Qt string to byte array, string has mask: @ByteArray[...]
|
||||
//! \param theValue a converted string
|
||||
//! \return the extended filled array
|
||||
Standard_EXPORT static QString ToString (const QByteArray& theValue);
|
||||
Standard_EXPORT static QString ToString(const QByteArray& theValue);
|
||||
|
||||
//! Converts a Qt byte array to Qt string. It has mask: @ByteArray[...]
|
||||
//! \param theValue a converted string
|
||||
//! \return the extended filled array
|
||||
Standard_EXPORT static QByteArray ToByteArray (const QString& theValue);
|
||||
Standard_EXPORT static QByteArray ToByteArray(const QString& theValue);
|
||||
|
||||
//! Returns header margin, defined in style settings of application
|
||||
//! \return integer value
|
||||
static int HeaderSectionMargin() { return qApp->style()->pixelMetric (QStyle::PM_HeaderMargin); }
|
||||
static int HeaderSectionMargin() { return qApp->style()->pixelMetric(QStyle::PM_HeaderMargin); }
|
||||
|
||||
//! Saves state of tree view in a container in form: key, value. It saves:
|
||||
//! - visibility of columns,
|
||||
@@ -59,8 +58,9 @@ public:
|
||||
//! \param theTreeView a view instance
|
||||
//! \param[out] theItems properties
|
||||
//! \param thePrefix preference item prefix
|
||||
Standard_EXPORT static void SaveState (QTreeView* theTreeView, QMap<QString, QString>& theItems,
|
||||
const QString& thePrefix = QString());
|
||||
Standard_EXPORT static void SaveState(QTreeView* theTreeView,
|
||||
QMap<QString, QString>& theItems,
|
||||
const QString& thePrefix = QString());
|
||||
|
||||
//! Restores state of tree view by a container
|
||||
//! \param theTreeView a view instance
|
||||
@@ -68,49 +68,53 @@ public:
|
||||
//! \param theValue property value
|
||||
//! \param thePrefix preference item prefix
|
||||
//! \return boolean value whether the property is applied to the tree view
|
||||
Standard_EXPORT static bool RestoreState (QTreeView* theTreeView, const QString& theKey, const QString& theValue,
|
||||
const QString& thePrefix = QString());
|
||||
Standard_EXPORT static bool RestoreState(QTreeView* theTreeView,
|
||||
const QString& theKey,
|
||||
const QString& theValue,
|
||||
const QString& thePrefix = QString());
|
||||
|
||||
//! Fills tree view by default sections parameters obtained in view's tree model
|
||||
//! \param theTreeView tree view instance
|
||||
Standard_EXPORT static void SetDefaultHeaderSections (QTreeView* theTreeView);
|
||||
Standard_EXPORT static void SetDefaultHeaderSections(QTreeView* theTreeView);
|
||||
|
||||
//! Sets using visibility column in the tree view:
|
||||
//! - sets the state in the TreeModel
|
||||
//! - set section width, not resizable
|
||||
//! \param theTreeView a view instance
|
||||
//! \param theActive boolean value if the column should be connected/visible and other
|
||||
Standard_EXPORT static void UseVisibilityColumn (QTreeView* theTreeView, const bool theActive = true);
|
||||
Standard_EXPORT static void UseVisibilityColumn(QTreeView* theTreeView,
|
||||
const bool theActive = true);
|
||||
|
||||
//! Returns the text width
|
||||
//! \param theText source text
|
||||
//! \param theParent parent widget with its own style
|
||||
//! \return calculated width value
|
||||
Standard_EXPORT static int GetTextWidth (const QString& theText, QObject* theParent);
|
||||
Standard_EXPORT static int GetTextWidth(const QString& theText, QObject* theParent);
|
||||
|
||||
//! Returns string cut by width and '\n'
|
||||
//! \param theText processing string
|
||||
//! \param theWidth width value, if -1, default value is used
|
||||
//! \param theTail symbols added to the end of the cut string
|
||||
Standard_EXPORT static QString CutString (const QString& theText, const int theWidth = -1, const QString& theTail = "...");
|
||||
Standard_EXPORT static QString CutString(const QString& theText,
|
||||
const int theWidth = -1,
|
||||
const QString& theTail = "...");
|
||||
|
||||
//! Returns light highlight color
|
||||
//! \returns Qt color
|
||||
Standard_EXPORT static QColor LightHighlightColor();
|
||||
|
||||
//! Makes the view expanded from the root till the index
|
||||
Standard_EXPORT static void SetExpandedTo (QTreeView* theTreeView, const QModelIndex& theIndex);
|
||||
Standard_EXPORT static void SetExpandedTo(QTreeView* theTreeView, const QModelIndex& theIndex);
|
||||
|
||||
//! Expands items in tree view staring from the index recursive in given number of levels
|
||||
//! \param theTreeView an OCAF tree view
|
||||
//! \param theParentIndex an index which children should be expanded
|
||||
//! \param isExpanded a boolean state if the item should be expanded or collapsed
|
||||
//! \param theLevels a number of levels to be expanded, or -1 for all levels
|
||||
Standard_EXPORT static void SetExpanded (QTreeView* theTreeView,
|
||||
const QModelIndex& theIndex,
|
||||
const bool isExpanded,
|
||||
int& theLevels);
|
||||
|
||||
Standard_EXPORT static void SetExpanded(QTreeView* theTreeView,
|
||||
const QModelIndex& theIndex,
|
||||
const bool isExpanded,
|
||||
int& theLevels);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -11,7 +11,7 @@
|
||||
// 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.
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <inspector/TreeModel_VisibilityState.hxx>
|
||||
|
||||
@@ -19,14 +19,14 @@
|
||||
// function : OnClicked
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool TreeModel_VisibilityState::processClicked (const QModelIndex& theIndex)
|
||||
bool TreeModel_VisibilityState::processClicked(const QModelIndex& theIndex)
|
||||
{
|
||||
if (theIndex.column() != TreeModel_ColumnType_Visibility)
|
||||
return false;
|
||||
|
||||
if (!CanBeVisible (theIndex))
|
||||
if (!CanBeVisible(theIndex))
|
||||
return false;
|
||||
|
||||
SetVisible (theIndex, !IsVisible (theIndex), true);
|
||||
SetVisible(theIndex, !IsVisible(theIndex), true);
|
||||
return true;
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@
|
||||
// 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.
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef TreeModel_VisibilityState_H
|
||||
#define TreeModel_VisibilityState_H
|
||||
@@ -30,7 +30,10 @@ class TreeModel_VisibilityState
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
TreeModel_VisibilityState (TreeModel_ModelBase* theModel) : myModel (theModel) {}
|
||||
TreeModel_VisibilityState(TreeModel_ModelBase* theModel)
|
||||
: myModel(theModel)
|
||||
{
|
||||
}
|
||||
|
||||
//! Destructor
|
||||
~TreeModel_VisibilityState() {}
|
||||
@@ -38,26 +41,28 @@ public:
|
||||
//! Returns true if visibility of the item can be changed
|
||||
//! \param theIndex tree model index
|
||||
//! \return boolean value
|
||||
virtual bool CanBeVisible (const QModelIndex& theIndex) const = 0;
|
||||
virtual bool CanBeVisible(const QModelIndex& theIndex) const = 0;
|
||||
|
||||
//! Sets visibility state
|
||||
//! \param theIndex tree model index
|
||||
//! \param theState visibility state
|
||||
//! \param toEmitDataChanged boolean flag whether emit of the model should be done immediately
|
||||
//! \return true if state is changed
|
||||
virtual bool SetVisible (const QModelIndex& theIndex, const bool theState, const bool toEmitDataChanged = true) = 0;
|
||||
virtual bool SetVisible(const QModelIndex& theIndex,
|
||||
const bool theState,
|
||||
const bool toEmitDataChanged = true) = 0;
|
||||
|
||||
//! Returns visibility state value
|
||||
//! \param theIndex tree model index
|
||||
//! \return boolean value
|
||||
virtual bool IsVisible (const QModelIndex& theIndex) const = 0;
|
||||
virtual bool IsVisible(const QModelIndex& theIndex) const = 0;
|
||||
|
||||
protected:
|
||||
//! Processes the mouse clicked on the index.
|
||||
//! It changes the item visibility if model allows to change it.
|
||||
//! \theIndex tree model index
|
||||
//! \return true if click is processed
|
||||
Standard_EXPORT bool processClicked (const QModelIndex& theIndex);
|
||||
Standard_EXPORT bool processClicked(const QModelIndex& theIndex);
|
||||
|
||||
protected:
|
||||
//! tree view model
|
||||
|
Reference in New Issue
Block a user