Skip to content
Permalink
Browse files

[layouts] Fix selected items appear in bold in all widgets

instead of just the items list panel

E.g. we don't want selected items to show in bold in the item
combo boxes
  • Loading branch information
nyalldawson committed Dec 17, 2018
1 parent bebc34b commit 4131e0b303cc3ecb97319baa822c1bc1b9f2d9a1
@@ -21,6 +21,54 @@
#include <QHeaderView>
#include <QMouseEvent>


QgsLayoutItemsListViewModel::QgsLayoutItemsListViewModel( QgsLayoutModel *model, QObject *parent )
: QSortFilterProxyModel( parent )
, mModel( model )
{
setSourceModel( mModel );
}

QgsLayoutItem *QgsLayoutItemsListViewModel::itemFromIndex( const QModelIndex &index ) const
{
return mModel->itemFromIndex( mapToSource( index ) );
}

void QgsLayoutItemsListViewModel::setSelected( const QModelIndex &index )
{
mModel->setSelected( mapToSource( index ) );
}

QVariant QgsLayoutItemsListViewModel::data( const QModelIndex &index, int role ) const
{
if ( !index.isValid() )
return QVariant();

QgsLayoutItem *item = itemFromIndex( index );
if ( !item )
{
return QVariant();
}

if ( role == Qt::FontRole )
{
if ( index.column() == QgsLayoutModel::ItemId && item->isSelected() )
{
//draw name of selected items in bold
QFont boldFont;
boldFont.setBold( true );
return boldFont;
}
}

return QSortFilterProxyModel::data( index, role );
}


//
// QgsLayoutItemsListView
//

QgsLayoutItemsListView::QgsLayoutItemsListView( QWidget *parent, QgsLayoutDesignerDialog *designer )
: QTreeView( parent )
, mDesigner( designer )
@@ -39,7 +87,7 @@ QgsLayoutItemsListView::QgsLayoutItemsListView( QWidget *parent, QgsLayoutDesign
void QgsLayoutItemsListView::setCurrentLayout( QgsLayout *layout )
{
mLayout = layout;
mModel = layout->itemsModel();
mModel = new QgsLayoutItemsListViewModel( layout->itemsModel(), this );
setModel( mModel );

header()->setSectionResizeMode( 0, QHeaderView::Fixed );
@@ -48,7 +96,7 @@ void QgsLayoutItemsListView::setCurrentLayout( QgsLayout *layout )
setColumnWidth( 1, Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "xxxx" ) ) );
header()->setSectionsMovable( false );

connect( selectionModel(), &QItemSelectionModel::currentChanged, mLayout->itemsModel(), &QgsLayoutModel::setSelected );
connect( selectionModel(), &QItemSelectionModel::currentChanged, mModel, &QgsLayoutItemsListViewModel::setSelected );
}

void QgsLayoutItemsListView::showContextMenu( QPoint point )
@@ -18,10 +18,31 @@

#include "qgis.h"
#include <QTreeView>
#include <QSortFilterProxyModel>

class QgsLayout;
class QgsLayoutDesignerDialog;
class QgsLayoutModel;
class QgsLayoutItem;

class QgsLayoutItemsListViewModel : public QSortFilterProxyModel
{
Q_OBJECT

public:

QgsLayoutItemsListViewModel( QgsLayoutModel *model, QObject *parent );

QgsLayoutItem *itemFromIndex( const QModelIndex &index ) const; \
QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;

public slots:
void setSelected( const QModelIndex &index );

private:

QgsLayoutModel *mModel = nullptr;
};

/**
* A list view for showing items in a layout
@@ -46,7 +67,7 @@ class QgsLayoutItemsListView : public QTreeView
private:

QgsLayout *mLayout = nullptr;
QgsLayoutModel *mModel = nullptr;
QgsLayoutItemsListViewModel *mModel = nullptr;
QgsLayoutDesignerDialog *mDesigner = nullptr;
};

@@ -182,16 +182,6 @@ QVariant QgsLayoutModel::data( const QModelIndex &index, int role ) const
return QVariant();
}

case Qt::FontRole:
if ( index.column() == ItemId && item->isSelected() )
{
//draw name of selected items in bold
QFont boldFont;
boldFont.setBold( true );
return boldFont;
}
return QVariant();

default:
return QVariant();
}

0 comments on commit 4131e0b

Please sign in to comment.
You can’t perform that action at this time.