Skip to content

Commit

Permalink
Ignore model font style and color in embed layers dialog
Browse files Browse the repository at this point in the history
And always show layers in standard font and colors. Otherwise
they inherit the styling of the standard layer tree model,
which means unchecked layers show in a "disabled" looking
style, which is misleading (and meaningless) for the embedded
layer choice.
  • Loading branch information
nyalldawson committed Jun 11, 2018
1 parent a9b25ed commit 6ea79e3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/app/qgsprojectlayergroupdialog.cpp
Expand Up @@ -26,6 +26,24 @@
#include <QFileInfo>
#include <QMessageBox>




QgsEmbeddedLayerTreeModel::QgsEmbeddedLayerTreeModel( QgsLayerTree *rootNode, QObject *parent )
: QgsLayerTreeModel( rootNode, parent )
{
}

QVariant QgsEmbeddedLayerTreeModel::data( const QModelIndex &index, int role ) const
{
if ( role == Qt::ForegroundRole || role == Qt::FontRole )
return QVariant();

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



QgsProjectLayerGroupDialog::QgsProjectLayerGroupDialog( QWidget *parent, const QString &projectFile, Qt::WindowFlags f )
: QDialog( parent, f )
, mRootGroup( new QgsLayerTree )
Expand Down Expand Up @@ -180,7 +198,7 @@ void QgsProjectLayerGroupDialog::changeProjectFile()
if ( !mShowEmbeddedContent )
removeEmbeddedNodes( mRootGroup );

QgsLayerTreeModel *model = new QgsLayerTreeModel( mRootGroup, this );
QgsEmbeddedLayerTreeModel *model = new QgsEmbeddedLayerTreeModel( mRootGroup, this );
mTreeView->setModel( model );

connect( mTreeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &QgsProjectLayerGroupDialog::onTreeViewSelectionChanged );
Expand Down
19 changes: 19 additions & 0 deletions src/app/qgsprojectlayergroupdialog.h
Expand Up @@ -18,12 +18,31 @@
#include "QDialog"
#include "ui_qgsprojectlayergroupdialogbase.h"
#include "qgshelp.h"
#include "qgslayertreemodel.h"
#include "qgis_app.h"

class QDomElement;

class QgsLayerTree;

/**
* Subclass of QgsLayerTreeModel which overrides font styling
* from base model.
*/
class QgsEmbeddedLayerTreeModel : public QgsLayerTreeModel
{
Q_OBJECT
public:

/**
* Construct a new tree model with given layer tree (root node must not be null pointer).
* The root node is not transferred by the model.
*/
explicit QgsEmbeddedLayerTreeModel( QgsLayerTree *rootNode, QObject *parent = nullptr );

QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
};

//! A dialog to select layers and groups from a qgs project
class APP_EXPORT QgsProjectLayerGroupDialog: public QDialog, private Ui::QgsProjectLayerGroupDialogBase
{
Expand Down

0 comments on commit 6ea79e3

Please sign in to comment.