1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

0029674: Improvements in Inspector tool

- preferences for dock windows geometry, tree view columns and current view projection;
- ViewControl package for common functionality between plugins;
- processing Location and Orientation for external TopoDS_Shape object
- 'F5' key to update content of each plugin
- visibility column in tree view (used now only in ShapeView)
- properties child item for context (presents tree of current Filters of context)
This commit is contained in:
nds
2018-03-23 16:08:11 +03:00
committed by bugmaster
parent 6dfdbb7ab8
commit 6822a3bef1
135 changed files with 4187 additions and 1603 deletions

View File

@@ -1,7 +1,15 @@
TreeModel.hxx
TreeModel.qrc
TreeModel_ColumnType.hxx
TreeModel_ContextMenu.cxx
TreeModel_ContextMenu.hxx
TreeModel_HeaderSection.hxx
TreeModel_ItemBase.cxx
TreeModel_ItemBase.hxx
TreeModel_ItemRole.hxx
TreeModel_MessageDialog.cxx
TreeModel_MessageDialog.hxx
TreeModel_ModelBase.cxx
TreeModel_ModelBase.hxx
TreeModel_Tools.cxx
TreeModel_Tools.hxx
TreeModel_VisibilityState.cxx
TreeModel_VisibilityState.hxx

View File

@@ -0,0 +1,33 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef TREEMODEL_H
#define TREEMODEL_H
#ifdef __TreeModel_DLL
#ifdef _WIN32
#define TREEMODEL_EXPORT __declspec(dllexport)
#else
#define TREEMODEL_EXPORT
#endif
#else
#ifdef _WIN32
#define TREEMODEL_EXPORT __declspec(dllimport)
#else
#define TREEMODEL_EXPORT
#endif
#endif
#endif

View File

@@ -0,0 +1,6 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>icons/item_invisible.png</file>
<file>icons/item_visible.png</file>
</qresource>
</RCC>

View File

@@ -0,0 +1,30 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef TreeModel_ColumnType_H
#define TreeModel_ColumnType_H
#include <Standard_WarningsDisable.hxx>
#include <Qt>
#include <Standard_WarningsRestore.hxx>
//! Sets custom item role of Tree view wmodel
enum TreeModel_ColumnType
{
TreeModel_ColumnType_Name = 0, //! name column
TreeModel_ColumnType_Visibility //! visibility state column
};
#endif

View File

@@ -0,0 +1,82 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/TreeModel_ContextMenu.hxx>
#include <inspector/TreeModel_ModelBase.hxx>
#include <inspector/TreeModel_Tools.hxx>
#include <inspector/ViewControl_Tools.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QHeaderView>
#include <QMenu>
#include <QTreeView>
#include <Standard_WarningsRestore.hxx>
// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
TreeModel_ContextMenu::TreeModel_ContextMenu (QTreeView* theTreeView)
: QObject (theTreeView), myTreeView (theTreeView)
{
myTreeView->header()->setContextMenuPolicy (Qt::CustomContextMenu);
#if QT_VERSION >= 0x050000
myTreeView->header()->setSectionsClickable (true);
#endif
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)
{
TreeModel_ModelBase* aModel = dynamic_cast<TreeModel_ModelBase*> (myTreeView->model());
if (!aModel)
return;
QMenu* aMenu = new QMenu (myTreeView);
int aNbSections = aModel->columnCount();
for (int aColumnId = 0; aColumnId < aNbSections; aColumnId++)
{
QAction* anAction = ViewControl_Tools::CreateAction (aModel->GetHeaderItem (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);
}
// =======================================================================
// function : onColumnVisibilityChanged
// purpose :
// =======================================================================
void TreeModel_ContextMenu::onColumnVisibilityChanged()
{
QAction* aClickedAction = (QAction*)sender();
myTreeView->setColumnHidden(aClickedAction->data().toInt(), !aClickedAction->isChecked());
}

View File

@@ -0,0 +1,53 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef TreeModel_ContextMenu_H
#define TreeModel_ContextMenu_H
#include <Standard.hxx>
#include <Standard_Macro.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QObject>
#include <QPoint>
#include <Standard_WarningsRestore.hxx>
class QTreeView;
//! \class TreeModel_ContextMenu
//! \brief Creates actions to show/hide tree view columns
class TreeModel_ContextMenu : public QObject
{
Q_OBJECT
public:
//! Constructor
Standard_EXPORT TreeModel_ContextMenu (QTreeView* theTreeView);
//! Destructor
~TreeModel_ContextMenu() {}
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);
//! Changes clicked column visiblity
void onColumnVisibilityChanged();
private:
QTreeView* myTreeView;
};
#endif

View File

@@ -0,0 +1,78 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef TreeModel_HeaderSection_H
#define TreeModel_HeaderSection_H
#include <Standard.hxx>
#include <Standard_Macro.hxx>
#include <inspector/TreeModel_Tools.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QString>
#include <Standard_WarningsRestore.hxx>
//! \class TreeModel_HeaderSection
//! \brief Container of tree view header sections, like width, visibility, text value
class TreeModel_HeaderSection
{
public:
//! Constructor
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) {}
//! Destructor
~TreeModel_HeaderSection() {}
//! Sets text value
//! \theName text value
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; }
//! Returns section width
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; }
//! Returns if the section is visiblt
bool IsHidden() const { return myIsHidden; }
//! Sets section width
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
};
#endif

View File

@@ -14,6 +14,7 @@
// commercial license or contractual agreement.
#include <inspector/TreeModel_ItemBase.hxx>
#include <inspector/TreeModel_ItemRole.hxx>
#include <Standard_WarningsDisable.hxx>
@@ -45,8 +46,19 @@ void TreeModel_ItemBase::Reset()
anItem->Reset();
}
m_bInitialized = false;
mycachedValues.clear();
myCachedValues.clear();
}
// =======================================================================
// function : Reset
// purpose :
// =======================================================================
void TreeModel_ItemBase::Reset (int theRole)
{
if (!myCachedValues.contains (theRole))
return;
myCachedValues.remove (theRole);
}
// =======================================================================
@@ -84,11 +96,11 @@ const TreeModel_ItemBasePtr TreeModel_ItemBase::currentItem()
// =======================================================================
QVariant TreeModel_ItemBase::cachedValue (const int theItemRole) const
{
if (mycachedValues.contains (theItemRole))
return mycachedValues[theItemRole];
if (myCachedValues.contains (theItemRole))
return myCachedValues[theItemRole];
const_cast<TreeModel_ItemBase*>(this)->mycachedValues.insert (theItemRole,
const_cast<TreeModel_ItemBase*>(this)->myCachedValues.insert (theItemRole,
theItemRole == TreeModel_ItemRole_RowCountRole ? QVariant (initRowCount()) : initValue (theItemRole));
return mycachedValues.contains (theItemRole) ? mycachedValues[theItemRole] : QVariant();
return myCachedValues.contains (theItemRole) ? myCachedValues[theItemRole] : QVariant();
}

View File

@@ -87,6 +87,10 @@ public:
//! If the item has internal values, there should be reseted here.
Standard_EXPORT virtual void Reset();
//! Resets the item cached value for the parameter role.
//! \param theRole an item role
Standard_EXPORT virtual void Reset(int theRole);
//! Gets the parent of the item, or TreeModel_ItemBasePtr() if it has no parent.
//! \return pointer to the item
TreeModel_ItemBasePtr Parent() const { return m_pParent; };
@@ -108,6 +112,11 @@ public:
//! \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);
//! 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); }
//! Returns the data stored under the given role for the current item
//! \param theIndex the item model index
//! \param theRole the item model role
@@ -154,7 +163,7 @@ private:
typedef QHash< QPair<int, int>, TreeModel_ItemBasePtr > PositionToItemHash;
PositionToItemHash m_ChildItems; //!< the hash of item children
QMap<int, QVariant> mycachedValues; //!< cached values, should be cleared by reset
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

View File

@@ -1,127 +0,0 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/TreeModel_MessageDialog.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QCheckBox>
#include <QCursor>
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
#include <QWidget>
#include <Standard_WarningsRestore.hxx>
// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
TreeModel_MessageDialog::TreeModel_MessageDialog (QWidget* theParent, const QString& theInformation,
const QString& theQuestion)
: QDialog (theParent), myDoNotShowItAgain (false), myPreviousAnswer (false), myInformation (theInformation),
myQuestion (theQuestion)
{
setWindowTitle ("Information");
QGridLayout* aLayout = new QGridLayout (this);
QString anInformation = theInformation;
if (!theQuestion.isEmpty())
anInformation += QString("\n\n%2").arg (myQuestion);
myInformationLabel = new QLabel (anInformation, this);
myInformationLabel->setWordWrap (true);
aLayout->addWidget (myInformationLabel, 0, 0, 1, 3);
myDoNotShowCheckBox = new QCheckBox ("Don't show this dialog again. Do the same next time.", this);
connect (myDoNotShowCheckBox, SIGNAL (toggled (bool)), this, SLOT (onDonNotShowToggled (bool) ));
aLayout->addWidget (myDoNotShowCheckBox, 1, 0, 1, 3);
myOkButton = new QPushButton ("Ok", this);
myCancelButton = new QPushButton ("Cancel", this);
connect (myOkButton, SIGNAL (clicked()), this, SLOT (onOkClicked() ));
connect (myCancelButton, SIGNAL (clicked()), this, SLOT (onCancelClicked() ));
aLayout->addWidget (myOkButton, 2, 1);
aLayout->addWidget (myCancelButton, 2, 2);
aLayout->setColumnStretch (0, 1);
myCancelButton->setDefault (true);
SetInformation (theInformation);
}
// =======================================================================
// function : Start
// purpose :
// =======================================================================
void TreeModel_MessageDialog::Start()
{
if (!myDoNotShowItAgain)
{
QString anInformation = myInformation;
if (!myQuestion.isEmpty())
anInformation += QString("\n\n%2").arg (myQuestion);
myInformationLabel->setText (anInformation);
exec();
return;
}
if (IsAccepted())
return;
// tool tip information window
QWidget* aWidget = new QWidget (this, Qt::Popup);
QVBoxLayout* aLayout = new QVBoxLayout (aWidget);
aLayout->addWidget (new QLabel(myInformation, aWidget));
aWidget->move(QCursor::pos());
aWidget->show();
}
// =======================================================================
// function : onOkClicked
// purpose :
// =======================================================================
void TreeModel_MessageDialog::onOkClicked()
{
myPreviousAnswer = true;
if (myDoNotShowItAgain)
setToolTipInfoMode();
accept();
}
// =======================================================================
// function : onCancelClicked
// purpose :
// =======================================================================
void TreeModel_MessageDialog::onCancelClicked()
{
myPreviousAnswer = false;
if (myDoNotShowItAgain)
setToolTipInfoMode();
reject();
}
// =======================================================================
// function : setToolTipInfoMode
// purpose :
// =======================================================================
void TreeModel_MessageDialog::setToolTipInfoMode()
{
//setWindowFlags (Qt::FramelessWindowHint);
//myDoNotShowCheckBox->setVisible (false);
//myOkButton->setVisible (false);
//myCancelButton->setVisible (false);
}

View File

@@ -1,87 +0,0 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef TreeModel_MessageDialog_H
#define TreeModel_MessageDialog_H
#include <Standard.hxx>
#include <Standard_Macro.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QCheckBox>
#include <QDialog>
#include <QLabel>
#include <QPushButton>
#include <QString>
#include <Standard_WarningsRestore.hxx>
class DFBrowser_Module;
class QWidget;
//! \class TreeModel_MessageDialog
//! Dialog providing information and a question.
//! It has a check box to do not the dialog again. In this case the previous value will be used as a result
class TreeModel_MessageDialog : public QDialog
{
Q_OBJECT
public:
//! Constructor
Standard_EXPORT TreeModel_MessageDialog (QWidget* theParent, const QString& theInformation, const QString& theQuestion);
//! Destructor
virtual ~TreeModel_MessageDialog() {}
//! Fills message dialog with the information
//! \param theInformation text
void SetInformation (const QString& theInformation) { myInformation = theInformation; }
//! Returns result of the dialog
//! \bool true if the dialog was accepted
bool IsAccepted() { return myPreviousAnswer; }
//! Either perform exec() for the dialog or show tool tip information depending do not be shown again state
Standard_EXPORT void Start();
private slots:
//! Processing this checkbox, store result in the dialog field to use by the next dialog start
//! \param theState current changed state of the check box
void onDonNotShowToggled (bool theState) { myDoNotShowItAgain = theState; }
//! Processing action button. Stores accept choice, change dialog state if do not show it again is on
void onOkClicked();
//! Processing action button. Stores reject choice, change dialog state if do not show it again is on
void onCancelClicked();
private:
//! Change state of the dialog to message tool tip. Only information control will be shown in the dialog
void setToolTipInfoMode();
private:
bool myDoNotShowItAgain; //! state if the dialog should not be shown again, the latest result is used as answer
bool myPreviousAnswer; //! the previous cached result of the dialog
QString myInformation; //! the information text
QString myQuestion; //! the question text
QLabel* myInformationLabel; //! message control
QCheckBox* myDoNotShowCheckBox; //! choice whether the dialog will be shown again
QPushButton* myOkButton; //! accept button
QPushButton* myCancelButton; //! reject button
};
#endif

View File

@@ -16,13 +16,20 @@
#include <inspector/TreeModel_ModelBase.hxx>
#include <inspector/TreeModel_ItemBase.hxx>
#include <inspector/TreeModel_Tools.hxx>
#include <inspector/TreeModel_VisibilityState.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QIcon>
#include <Standard_WarningsRestore.hxx>
// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
TreeModel_ModelBase::TreeModel_ModelBase (QObject* theParent)
: QAbstractItemModel (theParent), m_pRootItem (0)
: QAbstractItemModel (theParent), m_pRootItem (0), m_pUseVisibilityColumn (false),
myVisibilityState (0)
{
}
@@ -43,7 +50,11 @@ TreeModel_ItemBasePtr TreeModel_ModelBase::GetItemByIndex (const QModelIndex& th
void TreeModel_ModelBase::Reset()
{
for (int aColId = 0, aNbColumns = columnCount(); aColId < aNbColumns; aColId++)
RootItem (aColId)->Reset();
{
TreeModel_ItemBasePtr aRootItem = RootItem (aColId);
if (aRootItem)
aRootItem->Reset();
}
}
// =======================================================================
@@ -78,6 +89,27 @@ QVariant TreeModel_ModelBase::data (const QModelIndex& theIndex, int theRole) co
if (!theIndex.isValid())
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);
if (!anItem->IsInitialized())
anItem->Init();
if (!myVisibilityState || !myVisibilityState->CanBeVisible (theIndex))
return QVariant();
QVariant aValue = QIcon (myVisibilityState->IsVisible (theIndex) ? ":/icons/item_visible.png"
: ":/icons/item_invisible.png");
anItem->SetCustomData (aValue, theRole);
return aValue;
}
TreeModel_ItemBasePtr anItem = GetItemByIndex (theIndex);
return anItem->data (theIndex, theRole);
}
@@ -111,6 +143,21 @@ Qt::ItemFlags TreeModel_ModelBase::flags (const QModelIndex& theIndex) const
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
// =======================================================================
// function : headerData
// purpose :
// =======================================================================
QVariant TreeModel_ModelBase::headerData (int theSection, Qt::Orientation theOrientation, int theRole) const
{
if (theOrientation != Qt::Horizontal || theRole != Qt::DisplayRole)
return QVariant();
if (IsUseVisibilityColumn() && theSection == TreeModel_ColumnType_Visibility)
return QVariant();
return GetHeaderItem (theSection).GetName();
}
// =======================================================================
// function : rowCount
// purpose :
@@ -131,7 +178,7 @@ int TreeModel_ModelBase::rowCount (const QModelIndex& theParent) const
}
// =======================================================================
// function : emitLayoutChanged
// function : EmitLayoutChanged
// purpose :
// =======================================================================
void TreeModel_ModelBase::EmitLayoutChanged()
@@ -139,6 +186,44 @@ void TreeModel_ModelBase::EmitLayoutChanged()
emit layoutChanged();
}
// =======================================================================
// function : EmitLayoutChanged
// purpose :
// =======================================================================
void TreeModel_ModelBase::EmitDataChanged (const QModelIndex& theTopLeft, const QModelIndex& theBottomRight,
const QVector<int>& theRoles,
const bool isResetItem)
{
TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (theTopLeft);
if (anItemBase && isResetItem)
anItemBase->Reset();
#if QT_VERSION < 0x050000
(void)theRoles;
emit dataChanged (theTopLeft, theBottomRight);
#else
emit dataChanged (theTopLeft, theBottomRight, theRoles);
#endif
}
// =======================================================================
// function : SingleSelected
// purpose :
// =======================================================================
QModelIndex TreeModel_ModelBase::SingleSelected (const QModelIndexList& theIndices, const int theCellId,
const Qt::Orientation theOrientation)
{
QModelIndexList aFirstColumnSelectedIndices;
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))
aFirstColumnSelectedIndices.append (anIndex);
}
return aFirstColumnSelectedIndices.size() == 1 ? aFirstColumnSelectedIndices.first() : QModelIndex();
}
// =======================================================================
// function : getIndexValue
// purpose :

View File

@@ -18,14 +18,19 @@
#include <Standard.hxx>
#include <inspector/TreeModel_ItemBase.hxx>
#include <inspector/TreeModel_HeaderSection.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QAbstractItemModel>
#include <QExplicitlySharedDataPointer>
#include <QMap>
#include <QModelIndex>
#include <QVariant>
#include <QVector>
#include <Standard_WarningsRestore.hxx>
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 throught the base item architecture.
@@ -59,6 +64,26 @@ public:
//! 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);
//! Sets state whether visibility column (0) is used in the model
//! \param theState state
void SetUseVisibilityColumn (const bool theState) { m_pUseVisibilityColumn = theState; }
//! Returns state whether visibility column (0) is used in the model
//! \param theState state
bool IsUseVisibilityColumn() const { return m_pUseVisibilityColumn; }
//!< Fills visibility state checker
//!< \param theController the checker interface
void SetVisibilityState (TreeModel_VisibilityState* theController) { myVisibilityState = theController; }
//!< Returns visibility state checker
//!< \return the checker interface
TreeModel_VisibilityState* GetVisibilityState () const { return myVisibilityState; }
//! 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
@@ -92,8 +117,7 @@ public:
//! \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
{ (void)theSection, (void)theOrientation; (void)theRole; return QVariant(); }
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.
@@ -101,13 +125,40 @@ public:
//! \return the number of rows
Standard_EXPORT virtual int rowCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE;
//! Returns the number of columns for the children of the given parent.
//! \param theParent a parent model index
//! \return the number of columns
//! Returns whether the column is hidden by default
//! \param theColumnId a column index
//! \return header section values container
TreeModel_HeaderSection GetHeaderItem (const int theColumnId) const { return myHeaderValues[theColumnId]; }
//! Set header properties item.
//! \param theColumnId a column index
//! \param theSection a section value
void SetHeaderItem (const int theColumnId, const TreeModel_HeaderSection& theSection)
{ myHeaderValues[theColumnId] = theSection; createRootItem (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 1; }
{ (void)theParent; return myHeaderValues.size(); }
//! Returns default value of the visibility column
//! \return integer value
static int ColumnVisibilityWidth() { return 20; }
//! Returns single selected item in the cell of given orientation. If the orientation is Horizontal,
//! in the cell id colum, 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);
protected:
//! Creates root item
//! \param theColumnId index of a column
virtual void createRootItem (const int theColumnId) = 0;
//! Converts the item shared pointer to void* type
//! \param theItem
@@ -117,7 +168,11 @@ protected:
protected:
TreeModel_ItemBasePtr m_pRootItem; //!< the model root item. It should be created in the
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
};
#endif

View File

@@ -0,0 +1,213 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/TreeModel_Tools.hxx>
#include <inspector/TreeModel_ModelBase.hxx>
#include <inspector/TreeModel_ColumnType.hxx>
#include <inspector/TreeModel_VisibilityState.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QAction>
#include <QApplication>
#include <QFont>
#include <QFontMetrics>
#include <QHeaderView>
#include <QObject>
#include <QRegExp>
#include <QStringList>
#include <QStyle>
#include <QTreeView>
#include <Standard_WarningsRestore.hxx>
const int INFO_LENGHT = 60;
// =======================================================================
// function : ToString
// purpose :
// =======================================================================
QString TreeModel_Tools::ToString (const QByteArray& theValue)
{
char aBuffer[8];
QStringList aBytesList;
for (int aByteId = 0; aByteId < theValue.size(); aByteId++)
{
::sprintf (aBuffer, "#%02X", (unsigned char)theValue.at (aByteId));
aBytesList.append (QString (aBuffer));
}
return QString ("@ByteArray[%1]").arg (aBytesList.join (" "));
}
// =======================================================================
// function : ToByteArray
// purpose :
// =======================================================================
QByteArray TreeModel_Tools::ToByteArray (const QString& theValue)
{
QByteArray aStateArray;
if (!theValue.startsWith ("@ByteArray[") || !theValue.endsWith (']'))
return aStateArray;
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;
QString aString = *aByteId;
if (aString.startsWith ("#"))
{
aBase = 16;
aString = aString.mid (1);
}
bool isOk = false;
int aNum = aString.toInt (&isOk, aBase);
if (!isOk || aNum < 0 || aNum > 255)
continue;
aStateArray.append ((char)aNum);
}
return aStateArray;
}
// =======================================================================
// function : SaveState
// purpose :
// =======================================================================
void TreeModel_Tools::SaveState (QTreeView* theTreeView, QMap<QString, QString>& theItems,
const QString& thePrefix)
{
QStringList aColumnWidths, aHiddenColumns;
for (int aColumnId = 0; aColumnId < theTreeView->model()->columnCount(); aColumnId++)
{
if (theTreeView->isColumnHidden (aColumnId))
{
aHiddenColumns.append (QString::number (aColumnId));
aColumnWidths.append (QString());
}
else
aColumnWidths.append (QString::number (theTreeView->columnWidth (aColumnId)));
}
theItems[thePrefix + "columns_width"] = aColumnWidths.join (",");
theItems[thePrefix + "columns_hidden"] = aHiddenColumns.join (",");
}
// =======================================================================
// function : RestoreState
// purpose :
// =======================================================================
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++)
{
bool isOk;
int aWidth = aValues.at (aColumnId).toInt (&isOk);
if (isOk && !theTreeView->isColumnHidden (aColumnId)) // do not resize hidden columnsa
theTreeView->setColumnWidth (aColumnId, aWidth);
}
}
else if (theKey == thePrefix + "columns_hidden")
{
int aColumnSize = theTreeView->model()->columnCount();
QStringList aValues = theValue.split (",", QString::SkipEmptyParts);
QList<int> aColumnIds;
for (int aValueId = 0; aValueId < aValues.size(); aValueId++)
{
if (aValueId < aColumnSize)
aColumnIds.append (aValues.at (aValueId).toInt());
}
for (int aColumnId = 0; aColumnId < aColumnSize; aColumnId++)
{
theTreeView->setColumnHidden (aColumnId, aColumnIds.contains(aColumnId) == true);
}
}
else
return false;
return true;
}
// =======================================================================
// function : SetDefaultHeaderSections
// purpose :
// =======================================================================
void TreeModel_Tools::SetDefaultHeaderSections(QTreeView* theTreeView)
{
TreeModel_ModelBase* aTreeModel = dynamic_cast<TreeModel_ModelBase*> (theTreeView->model());
for (int aColumnId = 0, aNbColumns = aTreeModel->columnCount(); aColumnId < aNbColumns; aColumnId++)
{
TreeModel_HeaderSection aSection = aTreeModel->GetHeaderItem (aColumnId);
theTreeView->setColumnWidth (aColumnId, aSection.GetWidth());
theTreeView->setColumnHidden (aColumnId, aSection.IsHidden());
}
}
// =======================================================================
// function : UseVisibilityColumn
// purpose :
// =======================================================================
void TreeModel_Tools::UseVisibilityColumn (QTreeView* theTreeView, const bool theActive)
{
QHeaderView* aHeader = theTreeView->header();
#if QT_VERSION < 0x050000
aHeader->setResizeMode (TreeModel_ColumnType_Visibility, QHeaderView::Fixed);
#else
aHeader->setSectionResizeMode (TreeModel_ColumnType_Visibility, QHeaderView::Fixed);
#endif
aHeader->moveSection (TreeModel_ColumnType_Name, TreeModel_ColumnType_Visibility);
TreeModel_ModelBase* aModel = dynamic_cast<TreeModel_ModelBase*> (theTreeView->model());
aModel->SetHeaderItem (TreeModel_ColumnType_Visibility,
TreeModel_HeaderSection ("Visibility", TreeModel_ModelBase::ColumnVisibilityWidth()));
TreeModel_VisibilityState* aVisibilityState = aModel->GetVisibilityState ();
aModel->SetUseVisibilityColumn (true);
if (theActive && aVisibilityState)
QObject::connect (theTreeView, SIGNAL (clicked (const QModelIndex&)),
aVisibilityState, SLOT (OnClicked(const QModelIndex&)));
}
// =======================================================================
// function : GetTextWidth
// purpose :
// =======================================================================
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;
}
// =======================================================================
// function : CutString
// purpose :
// =======================================================================
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');
if (anIndex > 0 && anIndex < aLength)
aLength = anIndex;
return aLength < theText.length() ? theText.mid (0, aLength) + theTail : theText;
}

View File

@@ -0,0 +1,95 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef TreeModel_Tools_H
#define TreeModel_Tools_H
#include <Standard.hxx>
#include <Standard_Macro.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QApplication>
#include <QByteArray>
#include <QMap>
#include <QString>
#include <QStyle>
#include <Standard_WarningsRestore.hxx>
class QAction;
class QObject;
class QTreeView;
//! \class TreeModel_Tools
//! \brief The tool that gives auxiliary methods for qt elements manipulation
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);
//! 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);
//! Returns header margin, defined in style settings of application
//! \return integer value
Standard_EXPORT static int HeaderSectionMargin() { return qApp->style()->pixelMetric (QStyle::PM_HeaderMargin); }
//! Save state of three view in a container in form: key, value. It saves:
//! - visibiblity of columns,
//! - columns width
//! \param theTreeView a view instance
//! \param theItems [out] properties
//! \param thePrefix peference item prefix
Standard_EXPORT static void SaveState (QTreeView* theTreeView, QMap<QString, QString>& theItems,
const QString& thePrefix = QString());
//! Restore state of three view by a container
//! \param theTreeView a view instance
//! \param theKey property key
//! \param theValue property value
//! \param thePrefix peference item prefix
//! \return boolean value whether the property is applyed to the tree view
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);
//! 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);
//! 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);
//! 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 = "...");
};
#endif

View File

@@ -0,0 +1,32 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/TreeModel_VisibilityState.hxx>
// =======================================================================
// function : OnClicked
// purpose :
// =======================================================================
void TreeModel_VisibilityState::OnClicked (const QModelIndex& theIndex)
{
if (theIndex.column() != TreeModel_ColumnType_Visibility)
return;
if (!CanBeVisible (theIndex))
return;
SetVisible (theIndex, !IsVisible (theIndex), true);
emit itemClicked (theIndex);
}

View File

@@ -0,0 +1,81 @@
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef TreeModel_VisibilityState_H
#define TreeModel_VisibilityState_H
#include <inspector/TreeModel.hxx>
#include <inspector/TreeModel_ModelBase.hxx>
#include <inspector/TreeModel_ColumnType.hxx>
#include <Standard.hxx>
#include <Standard_Macro.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QObject>
#include <QString>
#include <Standard_WarningsRestore.hxx>
//! \class TreeModel_VisibilityState
//! \brief Interface that provides connection between model and visualization control to:
//! - know whether the model item is visible
//! - change visibility of the model item
class TREEMODEL_EXPORT TreeModel_VisibilityState : public QObject
{
Q_OBJECT
public:
//! Constructor
TreeModel_VisibilityState (TreeModel_ModelBase* theModel) : myModel (theModel) {}
//! Destructor
~TreeModel_VisibilityState() {}
//! 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;
//! Sets visibility state
//! \param theIndex tree model index
//! \param theState visibility state
//! \param toEmitDataChanged boolean flag whether emit of the model should be done immediatelly
//! \return true if state is changed
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;
public slots:
//! Processes the mouse clicked on the index.
//! It changes the item visibility if model allows to change it.
//! \theIndex tree model index
void OnClicked (const QModelIndex& theIndex);
signals:
//! Signal after OnClicked is performed
//! \theIndex tree model index
void itemClicked (const QModelIndex& theIndex);
protected:
//! tree view model
TreeModel_ModelBase* getModel() const { return myModel; }
private:
TreeModel_ModelBase* myModel; //! tree view model
};
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 478 B