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

0031362: Inspectors - MessageView plugin for message alerts

- append new MessageView plugin to display content of Message_Report;

- correct DumpJson of TDataStd array attributes to print Lower/Upper values;
- correct remove level of Message_Report to store stop time during removing all levels;
- append DumpJson for TFunction, TPrsStd attributes;
- correct DumpJson of XCAFDoc tools due to simplify performance of it;
- move AttributeInfo functionality from XDEDRAW into a static public method of XCAFDoc to call it outside;
- remove obsolete pane classes in DFBrowser plugin, now we may use DumpJSon panel to visualize this content of attributes;
- add new property panel in DFBrowser (synchronized with the same in other plugins);
- add button to switch ON DumpJson in DFBrowser(OFF by default, for better performance), also there is a context menu item in tree view;
- rename in DFBrowser "Property Panel" into "Property Panel (custom)";
- implement ViewControl_ColorSeletor and setting color in TreeModel_ItemProperties. Use only for light in VInspector now;
- implement setting false for all created AIS_Shape presentation to don't modify source TopoDS_Shape;
- remove not use VInspector_CallBack. It's possible using Message_Report/MessageView to track commands way;
- remove History panel in VInspector as not used, MessageView will be better solution for this;
- implement item and actions in VInspector for setting Lights in the view.
This commit is contained in:
nds
2021-04-26 18:01:38 +03:00
committed by bugmaster
parent 9a5bfc1c07
commit d16ecfe28e
239 changed files with 6001 additions and 8009 deletions

View File

@@ -1,3 +1,5 @@
ViewControl_ColorSelector.cxx
ViewControl_ColorSelector.hxx
ViewControl_EditType.hxx
ViewControl_MessageDialog.cxx
ViewControl_MessageDialog.hxx
@@ -5,6 +7,8 @@ ViewControl_PropertyView.cxx
ViewControl_PropertyView.hxx
ViewControl_Table.cxx
ViewControl_Table.hxx
ViewControl_TableItemDelegate.cxx
ViewControl_TableItemDelegate.hxx
ViewControl_TableModel.cxx
ViewControl_TableModel.hxx
ViewControl_TableModelValues.cxx

View File

@@ -0,0 +1,518 @@
// Created on: 2021-04-27
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2021 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/ViewControl_ColorSelector.hxx>
#include <inspector/ViewControl_TableItemDelegate.hxx>
#include <inspector/ViewControl_TableModel.hxx>
#include <inspector/ViewControl_TableModelValues.hxx>
#include <inspector/ViewControl_Tools.hxx>
#include <inspector/TreeModel_Tools.hxx>
#include <Standard_Dump.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QAbstractTableModel>
#include <QDialogButtonBox>
#include <QHeaderView>
#include <QGridLayout>
#include <QItemSelectionModel>
#include <QPainter>
#include <QPushButton>
#include <QTableView>
#include <QWidget>
#include <Standard_WarningsRestore.hxx>
//! Kinds of delegate cell in OCCT Color model to present a custom presentation (rect bounded by a colored frame)
enum ViewControl_ColorDelegateKind
{
ViewControl_ColorDelegateKind_None, //!< usual item
ViewControl_ColorDelegateKind_Activated, //!< active item
ViewControl_ColorDelegateKind_Highlighted, //!< highlighted item
ViewControl_ColorDelegateKind_Selected //!< selected item
};
//! Model for a table of parameters: Current Color, Red, Green, Blue, Alpha, OCCT color name
class ViewControl_ParametersModel : public ViewControl_TableModelValues
{
public:
ViewControl_ParametersModel (ViewControl_ColorSelector* theSelector)
: ViewControl_TableModelValues(), mySelector (theSelector) {}
virtual ~ViewControl_ParametersModel() {}
//! Inits model by the parameter color
//! \param theColor model active color
void SetColor (const Quantity_ColorRGBA& theColor, ViewControl_TableModel* theModel)
{ myColor = theColor; theModel->EmitLayoutChanged(); }
//! Returns current selected color
//! \return color value
Quantity_ColorRGBA GetColor() const { return myColor; }
//! Returns item information(short) for display role.
//! \param theIndex a model index
//! \param theRole a view role
//! \return value intepreted depending on the given role
Standard_EXPORT virtual QVariant Data (const int theRow, const int theColumn,
int theRole = Qt::DisplayRole) const Standard_OVERRIDE
{
//(void)theRow; (void)theColumn; (void) theRole;
if (theRole == Qt::BackgroundRole && theColumn == 1 && theRow == 0)
return ViewControl_ColorSelector::ColorToQColor (myColor);
if (theRole == Qt::ForegroundRole && theColumn == 1 && theRow >= 2 && theRow <= 5)
return ViewControl_TableModelValues::EditCellColor();
if (theRole != Qt::DisplayRole)
return QVariant();
bool isFirstColumn = theColumn == 0;
switch (theRow)
{
case 0: return isFirstColumn ? QVariant ("Color") : QVariant ();
case 1:
{
if (isFirstColumn)
return QVariant ("Name");
Quantity_NameOfColor aColorName;
if (ViewControl_ColorSelector::IsExactColorName(myColor, aColorName))
return Quantity_Color::StringName(aColorName);
}
break;
case 2: return isFirstColumn ? QVariant ("Red") : ViewControl_Tools::ToVariant (myColor.GetRGB().Red());
case 3: return isFirstColumn ? QVariant ("Green") : ViewControl_Tools::ToVariant (myColor.GetRGB().Green());
case 4: return isFirstColumn ? QVariant ("Blue") : ViewControl_Tools::ToVariant (myColor.GetRGB().Blue());
case 5: return isFirstColumn ? QVariant ("Alpha") : ViewControl_Tools::ToVariant (myColor.Alpha());
case 6: return isFirstColumn ? QVariant ("Near Name")
: Quantity_Color::StringName(myColor.GetRGB().Name());
}
return QVariant();
}
//! Sets content of the model index for the given role, it is applyed 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
virtual bool SetData (const int theRow, const int theColumn, const QVariant& theValue, int)
{
if (theColumn != 1 || theRow < 2 || theRow > 5)
return false;
switch (theRow)
{
case 2:
case 3:
case 4:
{
myColor.ChangeRGB().SetValues (theRow == 2 ? ViewControl_Tools::ToShortRealValue (theValue) : myColor.GetRGB().Red(),
theRow == 3 ? ViewControl_Tools::ToShortRealValue (theValue) : myColor.GetRGB().Green(),
theRow == 4 ? ViewControl_Tools::ToShortRealValue (theValue) : myColor.GetRGB().Blue(),
Quantity_TOC_RGB);
}
break;
case 5: myColor.SetAlpha (ViewControl_Tools::ToShortRealValue (theValue)); break;
}
mySelector->ParameterColorChanged();
return true;
}
//! Returns number of tree level line items = colums in table view
virtual int ColumnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
{ (void)theParent; return 2; }
//! Returns onlly one row in table view
virtual int RowCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
{ (void)theParent; return 7; }
//! Returns editable flag for color RGB and alpha rows
//! \return flags
Qt::ItemFlags Flags (const QModelIndex& theIndex) const
{
Qt::ItemFlags aFlags = ViewControl_TableModelValues::Flags (theIndex);
if (theIndex.column() == 1 && theIndex.row() >= 2 && theIndex.row() <= 5)
aFlags = aFlags | Qt::ItemIsEditable;
return aFlags;
}
//! 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
virtual ViewControl_EditType GetEditType (const int theRow, const int theColumn) const
{
if (theColumn == 1 && theRow >= 2 && theRow <= 5)
return ViewControl_EditType_Double;
return ViewControl_EditType_None;
}
private:
Quantity_ColorRGBA myColor;
ViewControl_ColorSelector* mySelector;
};
//! Table of parameters: Red, Green, Blue, Alpha, OCCT color name
class ViewControl_OCCTColorModel : public QAbstractTableModel
{
public:
ViewControl_OCCTColorModel (QObject* theParent)
: QAbstractTableModel (theParent), myCurrentIndexKind (ViewControl_ColorDelegateKind_None) {}
virtual ~ViewControl_OCCTColorModel() {}
//! Sets current color, that should have custom presented
//! \param theColor current color
//! \param theKind presentation kind
void SetColor (const Quantity_NameOfColor& theColor, const ViewControl_ColorDelegateKind theKind)
{
int aColorPosition = (int)theColor;
int aRow = (int) (aColorPosition / columnCount());
int aColumn = aColorPosition - aRow * columnCount();
myCurrentIndex = index (aRow, aColumn);
myCurrentIndexKind = theKind;
emit layoutChanged();
}
//! Returns OCCT name of color if index position does not exceed Quantity_NameOfColor elements
//! \param theIndex model index
//! \param theNameOfColor [out] OCCT color name
//! \return true if the color is found
bool GetOCCTColor (const QModelIndex& theIndex, Quantity_NameOfColor& theNameOfColor) const
{
int aNameOfColorId = theIndex.row() * columnCount() + theIndex.column();
if (aNameOfColorId > Quantity_NOC_WHITE)
return false;
theNameOfColor = (Quantity_NameOfColor)aNameOfColorId;
return true;
}
//! Returns index that has custom presentation
//! \return model index
QModelIndex GetCurrentIndex() const { return myCurrentIndex; }
//! Returns index color kind that has custom presentation
//! \return kind
ViewControl_ColorDelegateKind GetCurrentIndexKind() const { return myCurrentIndexKind; }
//! Returns item information(short) for display role.
//! \param theIndex a model index
//! \param theRole a view role
//! \return value intepreted depending on the given role
Standard_EXPORT virtual QVariant data (const QModelIndex& theIndex,
int theRole = Qt::DisplayRole) const Standard_OVERRIDE
{
if (theRole != Qt::ToolTipRole) // background is processed in table item delegate
return QVariant();
Quantity_NameOfColor aNameOfColor;
if (!GetOCCTColor (theIndex, aNameOfColor))
return QVariant();
if (theRole == Qt::ToolTipRole)
return QString("%1").arg (ViewControl_ColorSelector::ColorToString (Quantity_Color (aNameOfColor)));
return QVariant();
}
//! Returns number of tree level line items = colums in table view
virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
{ (void)theParent; return 26; }
//! Returns onlly one row in table view
virtual int rowCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
{ (void)theParent; return 20; }
//! Returns color for the delegate kind
//! \param theKind kind
//! \return color
static QColor GetKindColor (const ViewControl_ColorDelegateKind theKind)
{
switch (theKind)
{
case ViewControl_ColorDelegateKind_Activated:
case ViewControl_ColorDelegateKind_Highlighted: return Qt::blue;
case ViewControl_ColorDelegateKind_Selected: return Qt::black;
default: break;
}
return QColor();
}
private:
QModelIndex myCurrentIndex; //!< index to be presented through item delegate
ViewControl_ColorDelegateKind myCurrentIndexKind; //!< kind of custom item
};
//! \class DFBrowser_HighlightDelegate
//! \brief An item delegate to paint in highlight color the cell when the mouse cursor is over it
class ViewControl_OCCTColorDelegate : public QItemDelegate
{
public:
//! Constructor
ViewControl_OCCTColorDelegate (QObject* theParent = 0) : QItemDelegate (theParent) {}
//! Destructor
virtual ~ViewControl_OCCTColorDelegate() Standard_OVERRIDE {}
//! Redefine of the parent virtual method to color the cell rectangle in highlight style
//! \param thePainter a painter
//! \param theOption a paint options
//! \param theIndex a view index
virtual void paint (QPainter* thePainter, const QStyleOptionViewItem& theOption,
const QModelIndex& theIndex) const Standard_OVERRIDE
{
QRect aBaseRect = theOption.rect;
int aNameOfColorId = theIndex.row() * theIndex.model()->columnCount(theIndex) + theIndex.column();
Quantity_NameOfColor aNameOfColor = Quantity_NOC_WHITE;
if (aNameOfColorId < (int)Quantity_NOC_WHITE)
aNameOfColor = (Quantity_NameOfColor)aNameOfColorId;
Quantity_Color anOCCTColor (aNameOfColor);
QColor aQColor = ViewControl_ColorSelector::ColorToQColor (Quantity_ColorRGBA (anOCCTColor));
thePainter->fillRect (aBaseRect, aQColor);
QColor aColor;
// highlight cell
if (theOption.state & QStyle::State_MouseOver)
aColor = ViewControl_OCCTColorModel::GetKindColor (ViewControl_ColorDelegateKind_Highlighted);
else
{
const ViewControl_OCCTColorModel* aTableModel = dynamic_cast<const ViewControl_OCCTColorModel*> (theIndex.model());
QModelIndex anIndex = aTableModel->GetCurrentIndex();
if (anIndex.isValid() && anIndex.row() == theIndex.row() && anIndex.column() == theIndex.column())
aColor = ViewControl_OCCTColorModel::GetKindColor (aTableModel->GetCurrentIndexKind());
}
if (aColor.isValid())
{
int aRectSize = 2;
thePainter->fillRect (QRect (aBaseRect.topLeft(), QPoint (aBaseRect.bottomLeft().x() + aRectSize, aBaseRect.bottomLeft().y())),
aColor);
thePainter->fillRect (QRect (QPoint (aBaseRect.topRight().x() - aRectSize, aBaseRect.topRight().y()), aBaseRect.bottomRight()),
aColor);
thePainter->fillRect (QRect (QPoint (aBaseRect.topLeft().x() + aRectSize, aBaseRect.topLeft().y()),
QPoint (aBaseRect.topRight().x() - aRectSize, aBaseRect.topRight().y() + aRectSize)),
aColor);
thePainter->fillRect (QRect (QPoint (aBaseRect.bottomLeft().x() + aRectSize, aBaseRect.bottomLeft().y() - aRectSize),
QPoint (aBaseRect.bottomRight().x() - aRectSize, aBaseRect.bottomRight().y())),
aColor);
}
}
};
//! Color picker class
class ViewControl_ColorPicker : public QWidget
{
public:
ViewControl_ColorPicker (QWidget* theParent) : QWidget (theParent) {}
virtual ~ViewControl_ColorPicker() {}
};
// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
ViewControl_ColorSelector::ViewControl_ColorSelector (QWidget* theParent)
: QDialog (theParent)
{
QGridLayout* aLayout = new QGridLayout (this);
aLayout->setContentsMargins (0, 0, 0, 0);
myParameters = new QTableView (this);
ViewControl_TableModel* aTableModel = new ViewControl_TableModel (myParameters);
aTableModel->SetModelValues (new ViewControl_ParametersModel (this));
myParameters->setModel(aTableModel);
ViewControl_TableItemDelegate* anItemDelegate = new ViewControl_TableItemDelegate();
anItemDelegate->SetModelValues (aTableModel->ModelValues());
myParameters->setItemDelegate(anItemDelegate);
myParameters->verticalHeader()->setDefaultSectionSize (myParameters->verticalHeader()->minimumSectionSize());
myParameters->verticalHeader()->setVisible (false);
myParameters->horizontalHeader()->setVisible (false);
myParameters->setMinimumHeight (myParameters->verticalHeader()->minimumSectionSize() * aTableModel->rowCount() +
TreeModel_Tools::HeaderSectionMargin());
QItemSelectionModel* aSelectionModel = new QItemSelectionModel (myParameters->model());
myParameters->setSelectionMode (QAbstractItemView::SingleSelection);
myParameters->setSelectionModel (aSelectionModel);
aLayout->addWidget (myParameters, 0, 0);
myColorPicker = new ViewControl_ColorPicker (this);
aLayout->addWidget (myColorPicker, 0, 1);
myOCCTColors = new QTableView (this);
myOCCTColors->setFixedSize (525, 405);
myOCCTColors->verticalHeader()->setDefaultSectionSize (20);
myOCCTColors->verticalHeader()->setVisible (false);
myOCCTColors->horizontalHeader()->setDefaultSectionSize (20);
myOCCTColors->horizontalHeader()->setVisible (false);
myOCCTColors->setModel(new ViewControl_OCCTColorModel(myOCCTColors));
myOCCTColors->viewport()->setAttribute (Qt::WA_Hover);
myOCCTColors->setItemDelegate (new ViewControl_OCCTColorDelegate (myOCCTColors));
aSelectionModel = new QItemSelectionModel (myOCCTColors->model());
myOCCTColors->setSelectionMode (QAbstractItemView::SingleSelection);
myOCCTColors->setSelectionModel (aSelectionModel);
connect (aSelectionModel, SIGNAL (selectionChanged (const QItemSelection&, const QItemSelection&)),
this, SLOT (onOCCTColorsTableSelectionChanged (const QItemSelection&, const QItemSelection&)));
aLayout->addWidget (myOCCTColors, 1, 0, 1, 2);
QWidget* aBtnWidget = new QWidget (this);
aLayout->addWidget (aBtnWidget, 2, 0, 1, 2);
QHBoxLayout* aBtnLayout = new QHBoxLayout (aBtnWidget);
myOkButton = new QPushButton ("Ok", aBtnWidget);
myCancelButton = new QPushButton ("Cancel", aBtnWidget);
connect (myOkButton, SIGNAL (clicked()), this, SLOT (accept()));
connect (myCancelButton, SIGNAL (clicked()), this, SLOT (reject()));
aBtnLayout->addStretch ();
aBtnLayout->addWidget (myOkButton);
aBtnLayout->addWidget (myCancelButton);
}
// =======================================================================
// function : SetStreamValue
// purpose :
// =======================================================================
void ViewControl_ColorSelector::SetStreamValue (const QString& theValue)
{
Quantity_ColorRGBA aColor = StringToColorRGBA (theValue);
// parameters model
ViewControl_TableModel* aTableModel = dynamic_cast<ViewControl_TableModel*> (myParameters->model());
ViewControl_ParametersModel* aParametersModel = dynamic_cast<ViewControl_ParametersModel*> (aTableModel->ModelValues());
aParametersModel->SetColor (aColor, aTableModel);
// OCCT color model
Quantity_NameOfColor aColorName;
bool isExactColorName = ViewControl_ColorSelector::IsExactColorName(aColor, aColorName);
ViewControl_OCCTColorModel* anOCCTColorModel = dynamic_cast<ViewControl_OCCTColorModel*>(myOCCTColors->model());
anOCCTColorModel->SetColor (aColorName, isExactColorName ? ViewControl_ColorDelegateKind_Selected
: ViewControl_ColorDelegateKind_Activated);
}
// =======================================================================
// function : GetStreamValue
// purpose :
// =======================================================================
QString ViewControl_ColorSelector::GetStreamValue() const
{
ViewControl_TableModel* aTableModel = dynamic_cast<ViewControl_TableModel*> (myParameters->model());
ViewControl_ParametersModel* aParametersModel = dynamic_cast<ViewControl_ParametersModel*> (aTableModel->ModelValues());
Quantity_ColorRGBA aColor = aParametersModel->GetColor();
Standard_SStream aStream;
aColor.DumpJson (aStream);
return Standard_Dump::Text (aStream).ToCString();
}
// =======================================================================
// function : ParameterColorChanged
// purpose :
// =======================================================================
void ViewControl_ColorSelector::ParameterColorChanged()
{
ViewControl_TableModel* aTableModel = dynamic_cast<ViewControl_TableModel*> (myParameters->model());
ViewControl_ParametersModel* aParametersModel = dynamic_cast<ViewControl_ParametersModel*> (aTableModel->ModelValues());
Quantity_ColorRGBA aColor = aParametersModel->GetColor();
// OCCT color model
Quantity_NameOfColor aColorName;
bool isExactColorName = ViewControl_ColorSelector::IsExactColorName(aColor, aColorName);
ViewControl_OCCTColorModel* anOCCTColorModel = dynamic_cast<ViewControl_OCCTColorModel*>(myOCCTColors->model());
anOCCTColorModel->SetColor (aColorName, isExactColorName ? ViewControl_ColorDelegateKind_Selected
: ViewControl_ColorDelegateKind_Activated);
}
// =======================================================================
// function : ColorToString
// purpose :
// =======================================================================
QString ViewControl_ColorSelector::ColorToString (const Quantity_Color& theColor)
{
Standard_Real aRed, aGreen, aBlue;
theColor.Values (aRed, aGreen, aBlue, Quantity_TOC_RGB);
return QString::number (aRed) + ViewControl_ColorSelector::ColorSeparator() +
QString::number (aGreen) + ViewControl_ColorSelector::ColorSeparator() +
QString::number (aBlue);
}
// =======================================================================
// function : ColorToQColor
// purpose :
// =======================================================================
QColor ViewControl_ColorSelector::ColorToQColor (const Quantity_ColorRGBA& theColor)
{
int aDelta = 255;
Standard_Real aRed, aGreen, aBlue;
theColor.GetRGB().Values (aRed, aGreen, aBlue, Quantity_TOC_RGB);
return QColor((int)(aRed * aDelta), (int)(aGreen * aDelta), (int)(aBlue * aDelta));
}
// =======================================================================
// function : StringToColorRGBA
// purpose :
// =======================================================================
Quantity_ColorRGBA ViewControl_ColorSelector::StringToColorRGBA (const QString& theColor)
{
Quantity_ColorRGBA aColorRGBA;
Standard_SStream aStream;
aStream << theColor.toStdString();
int aStreamPos = 1;
aColorRGBA.InitFromJson (aStream, aStreamPos);
return aColorRGBA;
}
// =======================================================================
// function : IsExactColorName
// purpose :
// =======================================================================
Standard_Boolean ViewControl_ColorSelector::IsExactColorName (const Quantity_ColorRGBA& theColor,
Quantity_NameOfColor& theColorName)
{
theColorName = theColor.GetRGB().Name();
return Quantity_Color (theColorName).IsEqual (theColor.GetRGB());
}
// =======================================================================
// function : onOCCTColorsTableSelectionChanged
// purpose :
// =======================================================================
void ViewControl_ColorSelector::onOCCTColorsTableSelectionChanged (const QItemSelection& theSelected, const QItemSelection&)
{
QModelIndexList aSelectedIndices = theSelected.indexes();
if (aSelectedIndices.size() != 1)
return;
ViewControl_OCCTColorModel* anOCCTColorModel = dynamic_cast<ViewControl_OCCTColorModel*>(myOCCTColors->model());
Quantity_NameOfColor aNameOfColor;
if (!anOCCTColorModel->GetOCCTColor (aSelectedIndices.first(), aNameOfColor))
return;
anOCCTColorModel->SetColor (aNameOfColor, ViewControl_ColorDelegateKind_Selected);
// parameters model
ViewControl_TableModel* aTableModel = dynamic_cast<ViewControl_TableModel*> (myParameters->model());
ViewControl_ParametersModel* aParametersModel = dynamic_cast<ViewControl_ParametersModel*> (aTableModel->ModelValues());
Quantity_Color anOCCTColor (aNameOfColor);
aParametersModel->SetColor (Quantity_ColorRGBA (anOCCTColor), aTableModel);
}

View File

@@ -0,0 +1,93 @@
// Created on: 2021-04-27
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2021 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 ViewControl_ColorSelector_H
#define ViewControl_ColorSelector_H
#include <Quantity_ColorRGBA.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QColor>
#include <QDialog>
#include <QItemSelection>
#include <QString>
#include <QWidget>
#include <Standard_WarningsRestore.hxx>
class ViewControl_ColorPicker;
class QPushButton;
class QTableView;
//! \class ViewControl_ColorSelector
//! \brief Selector of OCCT color
class ViewControl_ColorSelector : public QDialog
{
Q_OBJECT
public:
//! Constructor
ViewControl_ColorSelector (QWidget* theParent);
//! Destructor
virtual ~ViewControl_ColorSelector() Standard_OVERRIDE {}
//! Inits control by the color value
//! \param theColor text color value
void SetStreamValue (const QString& theColor);
//! Returns current selected color value
//! \return text color value
QString GetStreamValue() const;
//! Updates OCCT color model by changing color in parameter model
void ParameterColorChanged();
//! Converts color to string value in form: r;g;b
//! \param theColor color value
//! \return text value
static QString ColorToString (const Quantity_Color& theColor);
//! Converts color to QColor value in form: r;g;b;a
//! \param theColor color value
//! \return qt color value
static QColor ColorToQColor (const Quantity_ColorRGBA& theColor);
//! Converts string to color value from a form: r;g;b;a
//! \param theColor text color value
//! \return color value
static Quantity_ColorRGBA StringToColorRGBA (const QString& theColor);
static Standard_Boolean IsExactColorName (const Quantity_ColorRGBA& theColor,
Quantity_NameOfColor& theColorName);
private:
//! Returns symbol used as a separtor of color components in string conversion
//! \return symbol value
static QString ColorSeparator() { return ";"; }
private slots:
//! Slots listen selection change and update the current control content by selection
//! \param theSelected container of selected items
//! \param theDeselected container of items that become deselected
void onOCCTColorsTableSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected);
private:
QTableView* myParameters; //!< current color parameters (RGB, alpha, color name)
ViewControl_ColorPicker* myColorPicker; //!< color picker
QTableView* myOCCTColors; //!< OCCT color values
QPushButton* myOkButton; //!< accept button
QPushButton* myCancelButton; //!< reject button
};
#endif

View File

@@ -21,6 +21,7 @@ enum ViewControl_EditType
{
ViewControl_EditType_None, //!< View widget is null
ViewControl_EditType_Bool, //!< check box widget
ViewControl_EditType_Color, //!< color selector widget
ViewControl_EditType_Double, //!< line edit widget used double validator
ViewControl_EditType_Line, //!< line edit widget
ViewControl_EditType_Spin, //!< spin box widget

View File

@@ -14,6 +14,7 @@
// commercial license or contractual agreement.
#include <inspector/ViewControl_Table.hxx>
#include <inspector/ViewControl_TableItemDelegate.hxx>
#include <inspector/ViewControl_TableModel.hxx>
#include <inspector/ViewControl_Tools.hxx>
@@ -46,6 +47,8 @@ ViewControl_Table::ViewControl_Table (QWidget* theParent)
myTableView = new QTableView (myMainWidget);
myTableView->setVerticalScrollMode (QAbstractItemView::ScrollPerPixel);
myTableView->setItemDelegate (new ViewControl_TableItemDelegate (theParent));
QHeaderView* aVHeader = myTableView->verticalHeader();
int aDefCellSize = aVHeader->minimumSectionSize();
aVHeader->setDefaultSectionSize (aDefCellSize);
@@ -82,6 +85,9 @@ void ViewControl_Table::Init (ViewControl_TableModelValues* theModelValues)
myTableView->horizontalHeader()->setVisible (theModelValues->IsHeaderVisible (Qt::Horizontal));
ViewControl_TableItemDelegate* anItemDelegate = dynamic_cast<ViewControl_TableItemDelegate*>(myTableView->itemDelegate());
anItemDelegate->SetModelValues (theModelValues);
myTableView->verticalHeader()->setVisible (theModelValues->IsHeaderVisible (Qt::Vertical));
int aSectionSize;
if (theModelValues->DefaultSectionSize (Qt::Vertical, aSectionSize) )

View File

@@ -0,0 +1,193 @@
// Created on: 2021-04-27
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2021 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/ViewControl_TableItemDelegate.hxx>
#include <inspector/ViewControl_ColorSelector.hxx>
#include <inspector/ViewControl_TableModelValues.hxx>
#include <inspector/ViewControl_EditType.hxx>
#include <inspector/TreeModel_ItemProperties.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QFont>
#include <QCheckBox>
#include <QComboBox>
#include <QDoubleValidator>
#include <QLineEdit>
#include <QPushButton>
#include <QSpinBox>
#include <Standard_WarningsRestore.hxx>
// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
ViewControl_TableItemDelegate::ViewControl_TableItemDelegate (QObject* theParent)
: QItemDelegate (theParent), myModelValues (0)
{
}
// =======================================================================
// function : createEditor
// purpose :
// =======================================================================
QWidget* ViewControl_TableItemDelegate::createEditor (QWidget* theParent,
const QStyleOptionViewItem&,
const QModelIndex& theIndex) const
{
if (!myModelValues)
return 0;
int aRow = theIndex.row();
int aColumn = theIndex.column();
ViewControl_EditType anEditType = myModelValues->EditType (aRow, aColumn);
QWidget* anEditor = createEditorControl (theParent, anEditType);
initEditorParameters (anEditor, anEditType, myModelValues, aRow, aColumn);
return anEditor;
}
// =======================================================================
// function : setEditorData
// purpose :
// =======================================================================
void ViewControl_TableItemDelegate::setEditorData (QWidget* theEditor, const QModelIndex& theIndex) const
{
if (!myModelValues)
return;
int aRow = theIndex.row();
int aColumn = theIndex.column();
ViewControl_EditType anEditType = myModelValues->EditType (aRow, aColumn);
setEditorValue (theEditor, anEditType, theIndex.model()->data(theIndex));
}
// =======================================================================
// function : setModelData
// purpose :
// =======================================================================
void ViewControl_TableItemDelegate::setModelData (QWidget* theEditor, QAbstractItemModel* theModel,
const QModelIndex& theIndex) const
{
if (!myModelValues)
return;
int aRow = theIndex.row();
int aColumn = theIndex.column();
ViewControl_EditType anEditType = myModelValues->EditType (aRow, aColumn);
theModel->setData (theIndex, getEditorValue (theEditor, anEditType));
}
// =======================================================================
// function : createEditorControl
// purpose :
// =======================================================================
QWidget* ViewControl_TableItemDelegate::createEditorControl (QWidget* theParent, const ViewControl_EditType theEditType)
{
switch (theEditType)
{
case ViewControl_EditType_None: return 0;
case ViewControl_EditType_Bool: return new QComboBox (theParent);
case ViewControl_EditType_Color: return new ViewControl_ColorSelector (theParent);
case ViewControl_EditType_Double:
{
QLineEdit* aLineEdit = new QLineEdit (theParent);
aLineEdit->setValidator (new QDoubleValidator (theParent));
return aLineEdit;
}
case ViewControl_EditType_Line: return new QLineEdit (theParent);
case ViewControl_EditType_Spin:
{
QSpinBox* aSpinBox = new QSpinBox (theParent);
aSpinBox->setRange (IntegerFirst(), IntegerLast());
return aSpinBox;
}
case ViewControl_EditType_DoAction: return new QPushButton (theParent);
default: return 0;
}
}
// =======================================================================
// function : initEditorParameters
// purpose :
// =======================================================================
void ViewControl_TableItemDelegate::initEditorParameters (QWidget* theEditor,
const ViewControl_EditType theEditType,
ViewControl_TableModelValues*,
const int, const int)
{
switch (theEditType)
{
case ViewControl_EditType_Bool:
{
(qobject_cast<QComboBox*> (theEditor))->insertItem(0, "true");
(qobject_cast<QComboBox*> (theEditor))->insertItem(1, "false");
break;
}
case ViewControl_EditType_Double:
{
}
default: break;
}
}
// =======================================================================
// function : setEditorValue
// purpose :
// =======================================================================
void ViewControl_TableItemDelegate::setEditorValue (QWidget* theEditor, const ViewControl_EditType theEditType,
const QVariant& theValue) const
{
switch (theEditType)
{
case ViewControl_EditType_None: break;
case ViewControl_EditType_Bool: (qobject_cast<QComboBox*>(theEditor))->setCurrentIndex (theValue.toBool() ? 0 : 1); break;
case ViewControl_EditType_Color:
{
if (!myModelValues)
break;
const TCollection_AsciiString& aStreamValue = myModelValues->Properties()->StreamValue();
(qobject_cast<ViewControl_ColorSelector*>(theEditor))->SetStreamValue (aStreamValue.ToCString());
break;
}
case ViewControl_EditType_Double:
case ViewControl_EditType_Line: (qobject_cast<QLineEdit*>(theEditor))->setText (theValue.toString()); break;
case ViewControl_EditType_Spin: (qobject_cast<QSpinBox*>(theEditor))->setValue (theValue.toInt()); break;
case ViewControl_EditType_DoAction: (qobject_cast<QPushButton*>(theEditor))->setText ("UnSelect"); break;
default: break;
}
}
// =======================================================================
// function : getEditorValue
// purpose :
// =======================================================================
QVariant ViewControl_TableItemDelegate::getEditorValue (QWidget* theEditor, const ViewControl_EditType theEditType)
{
switch (theEditType)
{
case ViewControl_EditType_None: return QVariant();
case ViewControl_EditType_Bool: return (qobject_cast<QComboBox*>(theEditor))->currentIndex() == 0 ? true : false;
case ViewControl_EditType_Color: return (qobject_cast<ViewControl_ColorSelector*>(theEditor))->GetStreamValue();
case ViewControl_EditType_Double:
case ViewControl_EditType_Line: return (qobject_cast<QLineEdit*>(theEditor))->text();
case ViewControl_EditType_Spin: return (qobject_cast<QSpinBox*>(theEditor))->value();
case ViewControl_EditType_DoAction: return QVariant ("Clicked");
default: return QVariant();
}
}

View File

@@ -0,0 +1,98 @@
// Created on: 2021-04-27
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2021 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 ViewControl_TableItemDelegate_H
#define ViewControl_TableItemDelegate_H
#include <Standard_Macro.hxx>
#include <inspector/ViewControl_EditType.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QItemDelegate>
#include <Standard_WarningsRestore.hxx>
class ViewControl_TableModelValues;
//! \class ViewControl_TableItemDelegate
//! \brief This is an implementation for table cell editor
class ViewControl_TableItemDelegate : public QItemDelegate
{
public:
//! Constructor
//! \param theParent parent object
Standard_EXPORT ViewControl_TableItemDelegate (QObject* theParent = 0);
//! Destructor
virtual ~ViewControl_TableItemDelegate() Standard_OVERRIDE {}
//! Sets table model values
//! \param theModelValues instance of model values
void SetModelValues (ViewControl_TableModelValues* theModelValues) { myModelValues = theModelValues; }
//! Creates widget editor: spin box, combo box or line edit
//! \param theParent parent widget
//! \param theOption style option
//! \param theIndex index of requested widget
virtual QWidget* createEditor (QWidget* theParent, const QStyleOptionViewItem& theOption,
const QModelIndex& theIndex) const Standard_OVERRIDE;
//! Sets the data to be displayed and edited by the editor from the data model item specified by the model index
//! \param theEditor editor to be filled
//! \param theIndex index of requested widget, contains information about model
virtual void setEditorData (QWidget* theEditor, const QModelIndex& theIndex) const Standard_OVERRIDE;
//! Gets data from the editor widget and stores it in the specified model at the item index.
//! \param theEditor editor to be filled
//! \param theModel data model
//! \param theIndex index of requested widget, contains information about model
virtual void setModelData (QWidget* theEditor, QAbstractItemModel* theModel,
const QModelIndex& theIndex) const Standard_OVERRIDE;
private:
//! Creates an editor
//! \param theParent parent widget
//! \param theEditType edition control type
//! \return edit control
static QWidget* createEditorControl (QWidget* theParent, const ViewControl_EditType theEditType);
//! Inits an editor by model values parameters
//! \param theEditor editor
//! \param theEditType edition control type
//! \param theModelValues custom implementation to provide parameters
//! \param theRow a model index row
//! \param theColumn a model index column
//! \return edit control
static void initEditorParameters (QWidget* theEditor, const ViewControl_EditType theEditType,
ViewControl_TableModelValues* theModelValues,
const int theRow, const int theColumn);
//! Sets editor value
//! \param theEditor editor
//! \param theEditType editor typ
//! \param theValue new value
void setEditorValue (QWidget* theEditor, const ViewControl_EditType theEditType, const QVariant& theValue) const;
//! Returns value of spin box editor
//! \param theEditor editor
//! \param theEditType editor typ
//! \return current value
static QVariant getEditorValue (QWidget* theEditor, const ViewControl_EditType theEditType);
private:
ViewControl_TableModelValues* myModelValues; //!< table model values
};
#endif

View File

@@ -44,7 +44,7 @@ public:
virtual ~ViewControl_TableModelValues() {}
//! Returns item table properties builder
Handle(TreeModel_ItemProperties) Properties() const { return myProperties; }
const Handle(TreeModel_ItemProperties)& Properties() const { return myProperties; }
//! Sets item table properties builder
void SetProperties (const Handle(TreeModel_ItemProperties)& theProperties) { myProperties = theProperties; }

View File

@@ -106,3 +106,39 @@ ViewControl_TableModelValues* ViewControl_Tools::CreateTableModelValues (QItemSe
aTableValues->SetProperties (anItemProperties);
return aTableValues;
}
// =======================================================================
// function : ToVariant
// purpose :
// =======================================================================
QVariant ViewControl_Tools::ToVariant (const Standard_ShortReal theValue)
{
return QVariant (QLocale().toString (theValue));
}
// =======================================================================
// function : ToVariant
// purpose :
// =======================================================================
QVariant ViewControl_Tools::ToVariant (const Standard_Real theValue)
{
return QVariant (QLocale().toString (theValue));
}
// =======================================================================
// function : ToRealValue
// purpose :
// =======================================================================
Standard_ShortReal ViewControl_Tools::ToShortRealValue (const QVariant& theValue)
{
return QLocale().toFloat (theValue.toString());
}
// =======================================================================
// function : ToRealValue
// purpose :
// =======================================================================
Standard_Real ViewControl_Tools::ToRealValue (const QVariant& theValue)
{
return QLocale().toDouble (theValue.toString());
}

View File

@@ -22,6 +22,7 @@
#include <Standard_WarningsDisable.hxx>
#include <QString>
#include <QVariant>
#include <Standard_WarningsRestore.hxx>
class ViewControl_TableModelValues;
@@ -63,6 +64,26 @@ public:
//! It is created if the selection contains only one item and it has a property item
Standard_EXPORT static ViewControl_TableModelValues* CreateTableModelValues (QItemSelectionModel* theSelectionModel);
//! Convert real value to string value
//! \param theValue a short real value
//! \return the string value
Standard_EXPORT static QVariant ToVariant (const Standard_ShortReal theValue);
//! Convert real value to string value
//! \param theValue a real value
//! \return the string value
Standard_EXPORT static QVariant ToVariant (const Standard_Real theValue);
//! Convert real value to real value
//! \param theValue a string value
//! \return the real value
Standard_EXPORT static Standard_ShortReal ToShortRealValue (const QVariant& theValue);
//! Convert real value to string value
//! \param theValue a string value
//! \return the real value
Standard_EXPORT static Standard_Real ToRealValue (const QVariant& theValue);
};
#endif