mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Make signals non-copyable
This commit is contained in:
parent
1649d27d0f
commit
59bc8b1f43
@ -336,12 +336,12 @@ void RimViewWindow::defineObjectEditorAttribute( QString uiConfigName, caf::PdmU
|
||||
if ( treeItemAttribute && RiaApplication::instance()->preferences()->showViewIdInProjectTree() && id() >= 0 )
|
||||
{
|
||||
treeItemAttribute->tags.clear();
|
||||
caf::PdmUiTreeViewItemAttribute::Tag tag;
|
||||
tag.text = QString( "%1" ).arg( id() );
|
||||
auto tag = caf::PdmUiTreeViewItemAttribute::Tag::create();
|
||||
tag->text = QString( "%1" ).arg( id() );
|
||||
cvf::Color3f viewColor = RiaColorTables::contrastCategoryPaletteColors().cycledColor3f( (size_t)id() );
|
||||
cvf::Color3f viewTextColor = RiaColorTools::contrastColor( viewColor );
|
||||
tag.bgColor = QColor( RiaColorTools::toQColor( viewColor ) );
|
||||
tag.fgColor = QColor( RiaColorTools::toQColor( viewTextColor ) );
|
||||
treeItemAttribute->tags.push_back( tag );
|
||||
tag->bgColor = QColor( RiaColorTools::toQColor( viewColor ) );
|
||||
tag->fgColor = QColor( RiaColorTools::toQColor( viewTextColor ) );
|
||||
treeItemAttribute->tags.push_back( std::move( tag ) );
|
||||
}
|
||||
}
|
||||
|
@ -112,30 +112,6 @@ public:
|
||||
m_emitter->addEmittedSignal( this );
|
||||
}
|
||||
|
||||
Signal( const Signal& rhs )
|
||||
: m_emitter( rhs.m_emitter )
|
||||
{
|
||||
m_emitter->addEmittedSignal( this );
|
||||
|
||||
for ( auto observerCallbackPair : rhs.m_observerCallbacks )
|
||||
{
|
||||
connect( observerCallbackPair.first, observerCallbackPair.second.first );
|
||||
}
|
||||
}
|
||||
|
||||
Signal& operator=( const Signal& rhs )
|
||||
{
|
||||
m_emitter = rhs.m_emitter;
|
||||
m_emitter->addEmittedSignal( this );
|
||||
|
||||
for ( auto observerCallbackPair : rhs.m_observerCallbacks )
|
||||
{
|
||||
connect( observerCallbackPair.first, observerCallbackPair.second.first );
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ~Signal()
|
||||
{
|
||||
for ( auto observerCallbackPair : m_observerCallbacks )
|
||||
@ -172,7 +148,7 @@ public:
|
||||
observer->removeObservedSignal( this );
|
||||
}
|
||||
|
||||
void send( Args... args )
|
||||
void send( Args... args ) const
|
||||
{
|
||||
for ( auto observerCallbackPair : m_observerCallbacks )
|
||||
{
|
||||
@ -198,6 +174,10 @@ public:
|
||||
}
|
||||
size_t observerCount() const { return m_observerCallbacks.size(); }
|
||||
|
||||
private:
|
||||
Signal( const Signal& rhs ) = delete;
|
||||
Signal& operator=( const Signal& rhs ) = delete;
|
||||
|
||||
private:
|
||||
std::map<SignalObserver*, MemberCallbackAndActiveFlag> m_observerCallbacks;
|
||||
const SignalEmitter* m_emitter;
|
||||
|
@ -522,33 +522,33 @@ void PdmUiTreeViewEditor::updateItemDelegateForSubTree( const QModelIndex& model
|
||||
{
|
||||
size_t indexInParent = static_cast<size_t>( index.row() );
|
||||
{
|
||||
caf::PdmUiTreeViewItemAttribute::Tag tag;
|
||||
tag.icon = caf::IconProvider( ":/caf/Up16x16.png" );
|
||||
tag.selectedOnly = true;
|
||||
auto tag = PdmUiTreeViewItemAttribute::Tag::create();
|
||||
tag->icon = caf::IconProvider( ":/caf/Up16x16.png" );
|
||||
tag->selectedOnly = true;
|
||||
if ( reorderability->canItemBeMovedUp( indexInParent ) )
|
||||
{
|
||||
tag.clicked.connect( reorderability, &PdmFieldReorderCapability::onMoveItemUp );
|
||||
tag->clicked.connect( reorderability, &PdmFieldReorderCapability::onMoveItemUp );
|
||||
}
|
||||
else
|
||||
{
|
||||
tag.icon.setActive( false );
|
||||
tag->icon.setActive( false );
|
||||
}
|
||||
|
||||
m_delegate->addTag( index, tag );
|
||||
m_delegate->addTag( index, std::move( tag ) );
|
||||
}
|
||||
{
|
||||
caf::PdmUiTreeViewItemAttribute::Tag tag;
|
||||
tag.icon = caf::IconProvider( ":/caf/Down16x16.png" );
|
||||
tag.selectedOnly = true;
|
||||
auto tag = PdmUiTreeViewItemAttribute::Tag::create();
|
||||
tag->icon = IconProvider( ":/caf/Down16x16.png" );
|
||||
tag->selectedOnly = true;
|
||||
if ( reorderability->canItemBeMovedDown( indexInParent ) )
|
||||
{
|
||||
tag.clicked.connect( reorderability, &PdmFieldReorderCapability::onMoveItemDown );
|
||||
tag->clicked.connect( reorderability, &PdmFieldReorderCapability::onMoveItemDown );
|
||||
}
|
||||
else
|
||||
{
|
||||
tag.icon.setActive( false );
|
||||
tag->icon.setActive( false );
|
||||
}
|
||||
m_delegate->addTag( index, tag );
|
||||
m_delegate->addTag( index, std::move( tag ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -556,11 +556,11 @@ void PdmUiTreeViewEditor::updateItemDelegateForSubTree( const QModelIndex& model
|
||||
|
||||
PdmUiTreeViewItemAttribute attribute;
|
||||
uiObjectHandle->objectEditorAttribute( "", &attribute );
|
||||
for ( const PdmUiTreeViewItemAttribute::Tag& tag : attribute.tags )
|
||||
for ( auto& tag : attribute.tags )
|
||||
{
|
||||
if ( !tag.text.isEmpty() || tag.icon.valid() )
|
||||
if ( !tag->text.isEmpty() || tag->icon.valid() )
|
||||
{
|
||||
m_delegate->addTag( index, tag );
|
||||
m_delegate->addTag( index, std::move( tag ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -612,10 +612,10 @@ void PdmUiTreeViewItemDelegate::clearAllTags()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiTreeViewItemDelegate::addTag( QModelIndex index, const PdmUiTreeViewItemAttribute::Tag& tag )
|
||||
void PdmUiTreeViewItemDelegate::addTag( QModelIndex index, std::unique_ptr<PdmUiTreeViewItemAttribute::Tag> tag )
|
||||
{
|
||||
std::vector<PdmUiTreeViewItemAttribute::Tag>& tagList = m_tags[index];
|
||||
tagList.push_back( tag );
|
||||
std::vector<std::unique_ptr<PdmUiTreeViewItemAttribute::Tag>>& tagList = m_tags[index];
|
||||
tagList.push_back( std::move( tag ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -632,13 +632,13 @@ QRect PdmUiTreeViewItemDelegate::tagRect( const QRect& itemRect, QModelIndex ind
|
||||
|
||||
for ( size_t i = 0; i < it->second.size(); ++i )
|
||||
{
|
||||
const PdmUiTreeViewItemAttribute::Tag& tag = it->second[i];
|
||||
if ( tag.icon.valid() )
|
||||
const PdmUiTreeViewItemAttribute::Tag* tag = it->second[i].get();
|
||||
if ( tag->icon.valid() )
|
||||
{
|
||||
auto icon = tag.icon.icon();
|
||||
auto icon = tag->icon.icon();
|
||||
QSize iconSize = icon->actualSize( fullSize );
|
||||
QRect iconRect;
|
||||
if ( tag.position == PdmUiTreeViewItemAttribute::Tag::AT_END )
|
||||
if ( tag->position == PdmUiTreeViewItemAttribute::Tag::AT_END )
|
||||
{
|
||||
QPoint bottomRight = itemRect.bottomRight() - offset;
|
||||
QPoint topLeft = bottomRight - QPoint( iconSize.width(), iconSize.height() );
|
||||
@ -676,16 +676,16 @@ void PdmUiTreeViewItemDelegate::paint( QPainter* painter, const QStyleOptionView
|
||||
|
||||
QPoint offset( 0, 0 );
|
||||
|
||||
for ( const PdmUiTreeViewItemAttribute::Tag& tag : it->second )
|
||||
for ( const std::unique_ptr<PdmUiTreeViewItemAttribute::Tag>& tag : it->second )
|
||||
{
|
||||
if ( tag.selectedOnly && !( option.state & QStyle::State_Selected ) ) continue;
|
||||
if ( tag->selectedOnly && !( option.state & QStyle::State_Selected ) ) continue;
|
||||
|
||||
if ( tag.icon.valid() )
|
||||
if ( tag->icon.valid() )
|
||||
{
|
||||
auto icon = tag.icon.icon();
|
||||
auto icon = tag->icon.icon();
|
||||
QSize iconSize = icon->actualSize( fullSize );
|
||||
QRect iconRect;
|
||||
if ( tag.position == PdmUiTreeViewItemAttribute::Tag::AT_END )
|
||||
if ( tag->position == PdmUiTreeViewItemAttribute::Tag::AT_END )
|
||||
{
|
||||
QPoint bottomRight = rect.bottomRight() - offset;
|
||||
QPoint topLeft = bottomRight - QPoint( iconSize.width(), iconSize.height() );
|
||||
@ -717,15 +717,15 @@ void PdmUiTreeViewItemDelegate::paint( QPainter* painter, const QStyleOptionView
|
||||
}
|
||||
painter->setFont( font );
|
||||
|
||||
QString text = tag.text;
|
||||
QColor bgColor = tag.bgColor;
|
||||
QColor fgColor = tag.fgColor;
|
||||
QString text = tag->text;
|
||||
QColor bgColor = tag->bgColor;
|
||||
QColor fgColor = tag->fgColor;
|
||||
|
||||
QSize textSize( QFontMetrics( font ).size( Qt::TextSingleLine, text ) );
|
||||
int textDiff = ( fullSize.height() - textSize.height() );
|
||||
|
||||
QRect textRect;
|
||||
if ( tag.position == PdmUiTreeViewItemAttribute::Tag::AT_END )
|
||||
if ( tag->position == PdmUiTreeViewItemAttribute::Tag::AT_END )
|
||||
{
|
||||
QPoint bottomRight = rect.bottomRight() - QPoint( outsideLeftRightMargins, 0 ) - offset;
|
||||
QPoint textBottomRight = bottomRight - QPoint( insideleftRightMargins, textDiff / 2 );
|
||||
@ -765,10 +765,19 @@ void PdmUiTreeViewItemDelegate::paint( QPainter* painter, const QStyleOptionView
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<caf::PdmUiTreeViewItemAttribute::Tag> PdmUiTreeViewItemDelegate::tags( QModelIndex index ) const
|
||||
std::vector<const caf::PdmUiTreeViewItemAttribute::Tag*> PdmUiTreeViewItemDelegate::tags( QModelIndex index ) const
|
||||
{
|
||||
std::vector<const caf::PdmUiTreeViewItemAttribute::Tag*> tagPtrVector;
|
||||
|
||||
auto it = m_tags.find( index );
|
||||
return it != m_tags.end() ? it->second : std::vector<caf::PdmUiTreeViewItemAttribute::Tag>();
|
||||
if ( it != m_tags.end() )
|
||||
{
|
||||
for ( const auto& tag : it->second )
|
||||
{
|
||||
tagPtrVector.push_back( tag.get() );
|
||||
}
|
||||
}
|
||||
return tagPtrVector;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -785,7 +794,7 @@ bool PdmUiTreeViewItemDelegate::editorEvent( QEvent* event,
|
||||
|
||||
if ( mouseEvent->button() == Qt::LeftButton && mouseEvent->modifiers() == Qt::NoModifier )
|
||||
{
|
||||
PdmUiTreeViewItemAttribute::Tag tag;
|
||||
const PdmUiTreeViewItemAttribute::Tag* tag;
|
||||
if ( tagClicked( mouseEvent->pos(), option.rect, itemIndex, &tag ) )
|
||||
{
|
||||
QModelIndex parentIndex = itemIndex.parent();
|
||||
@ -793,7 +802,7 @@ bool PdmUiTreeViewItemDelegate::editorEvent( QEvent* event,
|
||||
auto uiItem = m_treeView->uiItemFromModelIndex( itemIndex );
|
||||
auto parentUiItem = m_treeView->uiItemFromModelIndex( parentIndex );
|
||||
|
||||
tag.clicked.send( (size_t)itemIndex.row() );
|
||||
tag->clicked.send( (size_t)itemIndex.row() );
|
||||
|
||||
m_treeView->updateSubTree( parentUiItem );
|
||||
m_treeView->selectAsCurrentItem( uiItem );
|
||||
@ -807,10 +816,10 @@ bool PdmUiTreeViewItemDelegate::editorEvent( QEvent* event,
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PdmUiTreeViewItemDelegate::tagClicked( const QPoint& pos,
|
||||
const QRect& itemRect,
|
||||
const QModelIndex& itemIndex,
|
||||
PdmUiTreeViewItemAttribute::Tag* tag ) const
|
||||
bool PdmUiTreeViewItemDelegate::tagClicked( const QPoint& pos,
|
||||
const QRect& itemRect,
|
||||
const QModelIndex& itemIndex,
|
||||
const PdmUiTreeViewItemAttribute::Tag** tag ) const
|
||||
{
|
||||
if ( itemIndex.isValid() )
|
||||
{
|
||||
|
@ -50,6 +50,8 @@
|
||||
#include <QTreeView>
|
||||
#include <QWidget>
|
||||
|
||||
#include <memory>
|
||||
|
||||
class MySortFilterProxyModel;
|
||||
|
||||
class QGridLayout;
|
||||
@ -93,9 +95,15 @@ public:
|
||||
bool selectedOnly;
|
||||
|
||||
caf::Signal<size_t> clicked;
|
||||
|
||||
static std::unique_ptr<Tag> create() { return std::unique_ptr<Tag>( new Tag ); }
|
||||
|
||||
private:
|
||||
Tag( const Tag& rhs ) = default;
|
||||
Tag& operator =( const Tag& rhs ) { return *this; }
|
||||
};
|
||||
|
||||
std::vector<Tag> tags;
|
||||
std::vector<std::unique_ptr<Tag>> tags;
|
||||
};
|
||||
|
||||
class PdmUiTreeViewItemDelegate : public QStyledItemDelegate
|
||||
@ -104,25 +112,25 @@ public:
|
||||
PdmUiTreeViewItemDelegate( PdmUiTreeViewEditor* parent, PdmUiTreeViewQModel* model );
|
||||
void clearTags( QModelIndex index );
|
||||
void clearAllTags();
|
||||
void addTag( QModelIndex index, const PdmUiTreeViewItemAttribute::Tag& tag );
|
||||
void addTag( QModelIndex index, std::unique_ptr<PdmUiTreeViewItemAttribute::Tag> tag );
|
||||
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const override;
|
||||
std::vector<PdmUiTreeViewItemAttribute::Tag> tags( QModelIndex index ) const;
|
||||
std::vector<const PdmUiTreeViewItemAttribute::Tag*> tags( QModelIndex index ) const;
|
||||
|
||||
protected:
|
||||
bool editorEvent( QEvent* event,
|
||||
QAbstractItemModel* model,
|
||||
const QStyleOptionViewItem& option,
|
||||
const QModelIndex& itemIndex ) override;
|
||||
bool tagClicked( const QPoint& clickPos,
|
||||
const QRect& itemRect,
|
||||
const QModelIndex& itemIndex,
|
||||
PdmUiTreeViewItemAttribute::Tag* tag ) const;
|
||||
bool tagClicked( const QPoint& clickPos,
|
||||
const QRect& itemRect,
|
||||
const QModelIndex& itemIndex,
|
||||
const PdmUiTreeViewItemAttribute::Tag** tag ) const;
|
||||
QRect tagRect( const QRect& itemRect, QModelIndex itemIndex, size_t tagIndex ) const;
|
||||
|
||||
private:
|
||||
PdmUiTreeViewEditor* m_treeView;
|
||||
PdmUiTreeViewQModel* m_model;
|
||||
std::map<QModelIndex, std::vector<PdmUiTreeViewItemAttribute::Tag>> m_tags;
|
||||
PdmUiTreeViewEditor* m_treeView;
|
||||
PdmUiTreeViewQModel* m_model;
|
||||
std::map<QModelIndex, std::vector<std::unique_ptr<PdmUiTreeViewItemAttribute::Tag>>> m_tags;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user