Improve ensemble curve colors

* Use unique_ptr
* Improve default assignment of curve appearance
* Improve display of color tags in tree view items
* Select curve or ensemble instead of plot
* Only change curves connected to a Rim-object

* Improve color management for ensemble curves
Use a base color for statistics curves and set realization curves transparent
Make sure new curves are assigned a unique color
Harmonize how dropped addresses are handled

* Update all tags always
The update of tags for a subset of tree nodes is currently broken. Always update all tags.

* Add const
This commit is contained in:
Magne Sjaastad
2023-04-19 15:36:06 +02:00
committed by GitHub
parent d11f51fcae
commit 643ccd67b8
19 changed files with 399 additions and 170 deletions
@@ -66,6 +66,19 @@ PdmUiColorEditor::PdmUiColorEditor()
m_color = QColor::Invalid;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QColor PdmUiColorEditor::getColor( const QColor& sourceColor )
{
QColorDialog::ColorDialogOptions flags;
#ifndef WIN32
flags = QColorDialog::DontUseNativeDialog;
#endif
return QColorDialog::getColor( sourceColor, nullptr, "Select color", flags );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -76,6 +76,8 @@ public:
PdmUiColorEditor();
~PdmUiColorEditor() override {}
static QColor getColor( const QColor& sourceColor );
protected:
QWidget* createEditorWidget( QWidget* parent ) override;
QWidget* createLabelWidget( QWidget* parent ) override;
@@ -41,6 +41,8 @@
#include "cafPdmUiFieldEditorHandle.h"
#include "cafSignal.h"
#include <memory>
namespace caf
{
class PdmUiTreeViewItemAttribute : public PdmUiEditorAttribute
@@ -48,14 +50,13 @@ class PdmUiTreeViewItemAttribute : public PdmUiEditorAttribute
public:
struct Tag : public SignalEmitter
{
enum Position
enum class Position
{
IN_FRONT,
AT_END
};
Tag()
: text()
, position( AT_END )
: position( Position::AT_END )
, bgColor( Qt::red )
, fgColor( Qt::white )
, selectedOnly( false )
@@ -71,7 +72,7 @@ public:
caf::Signal<size_t> clicked;
static std::unique_ptr<Tag> create() { return std::unique_ptr<Tag>( new Tag ); }
static std::unique_ptr<Tag> create() { return std::make_unique<Tag>(); }
private:
Tag& operator=( const Tag& rhs ) { return *this; }
@@ -325,8 +325,7 @@ void PdmUiTreeViewEditor::updateMySubTree( PdmUiItem* uiItem, bool notifyEditors
}
m_treeViewModel->updateSubTree( itemToUpdate, notifyEditors );
QModelIndex itemIndex = m_treeViewModel->findModelIndex( itemToUpdate );
updateItemDelegateForSubTree( itemIndex );
updateItemDelegateForSubTree();
}
}
@@ -101,6 +101,19 @@ QRect PdmUiTreeViewItemDelegate::tagRect( const QRect& itemRect, QModelIndex ind
auto it = m_tags.find( index );
if ( it == m_tags.end() ) return QRect();
if ( it->second.size() == 1 )
{
const PdmUiTreeViewItemAttribute::Tag* tag = it->second[0].get();
if ( !tag->icon.valid() && tag->position == PdmUiTreeViewItemAttribute::Tag::Position::AT_END )
{
// Special case for single tag at end, which is not an icon
QPoint bottomRight = itemRect.bottomRight();
QPoint topLeft = itemRect.topRight() - QPoint( itemRect.height() * 1.5, 0 );
return QRect( topLeft, bottomRight );
}
}
QSize fullSize = itemRect.size();
QPoint offset( 0, 0 );
@@ -113,7 +126,7 @@ QRect PdmUiTreeViewItemDelegate::tagRect( const QRect& itemRect, QModelIndex ind
auto icon = tag->icon.icon();
QSize iconSize = icon->actualSize( fullSize );
QRect iconRect;
if ( tag->position == PdmUiTreeViewItemAttribute::Tag::AT_END )
if ( tag->position == PdmUiTreeViewItemAttribute::Tag::Position::AT_END )
{
QPoint bottomRight = itemRect.bottomRight() - offset;
QPoint topLeft = bottomRight - QPoint( iconSize.width(), iconSize.height() );
@@ -162,7 +175,7 @@ void PdmUiTreeViewItemDelegate::paint( QPainter* painter, const QStyleOptionView
auto icon = tag->icon.icon();
QSize iconSize = icon->actualSize( fullSize );
QRect iconRect;
if ( tag->position == PdmUiTreeViewItemAttribute::Tag::AT_END )
if ( tag->position == PdmUiTreeViewItemAttribute::Tag::Position::AT_END )
{
QPoint bottomRight( rect.bottomRight().x() - offset.x(), center.y() + iconSize.height() / 2 );
QPoint topLeft( bottomRight.x() - iconSize.width(), bottomRight.y() - iconSize.height() );
@@ -202,7 +215,7 @@ void PdmUiTreeViewItemDelegate::paint( QPainter* painter, const QStyleOptionView
int textDiff = ( fullSize.height() - textSize.height() );
QRect textRect;
if ( tag->position == PdmUiTreeViewItemAttribute::Tag::AT_END )
if ( tag->position == PdmUiTreeViewItemAttribute::Tag::Position::AT_END )
{
QPoint bottomRight = rect.bottomRight() - QPoint( outsideLeftRightMargins, 0 ) - offset;
QPoint textBottomRight = bottomRight - QPoint( insideleftRightMargins, textDiff / 2 );
@@ -283,14 +296,14 @@ bool PdmUiTreeViewItemDelegate::editorEvent( QEvent* event,
PdmObjectHandle* pdmObject = uiObjectHandle->objectHandle();
if ( pdmObject )
{
PdmFieldReorderCapability* reorderability =
PdmFieldReorderCapability::reorderCapabilityOfParentContainer( pdmObject );
size_t indexInParent = 0;
if ( reorderability )
if ( PdmFieldReorderCapability* reorderability =
PdmFieldReorderCapability::reorderCapabilityOfParentContainer( pdmObject ) )
{
size_t indexInParent = reorderability->indexOf( pdmObject );
tag->clicked.send( indexInParent );
indexInParent = reorderability->indexOf( pdmObject );
}
tag->clicked.send( indexInParent );
}
}