Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix #10473 (raster preview icons in layer tree view)
  • Loading branch information
wonder-sk committed Jun 9, 2014
1 parent 6a17538 commit 7c0da6d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -2305,6 +2305,8 @@ void QgisApp::initLayerTreeView()
mLayerTreeView->setModel( model );
mLayerTreeView->setMenuProvider( new QgsAppLayerTreeViewMenuProvider( mLayerTreeView, mMapCanvas ) );

setupLayerTreeViewFromSettings();

connect( mLayerTreeView, SIGNAL( doubleClicked( QModelIndex ) ), this, SLOT( layerTreeViewDoubleClicked( QModelIndex ) ) );
connect( mLayerTreeView, SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( activeLayerChanged( QgsMapLayer* ) ) );
connect( mLayerTreeView->selectionModel(), SIGNAL( currentChanged( QModelIndex, QModelIndex ) ), this, SLOT( updateNewLayerInsertionPoint() ) );
Expand All @@ -2329,6 +2331,13 @@ void QgisApp::initLayerTreeView()
mLayerOrderDock->hide();
}

void QgisApp::setupLayerTreeViewFromSettings()
{
QSettings s;

mLayerTreeView->layerTreeModel()->setFlag( QgsLayerTreeModel::ShowRasterPreviewIcon, s.value( "/qgis/createRasterLegendIcons", false ).toBool() );
}


void QgisApp::updateNewLayerInsertionPoint()
{
Expand Down Expand Up @@ -7239,6 +7248,8 @@ void QgisApp::showOptionsDialog( QWidget *parent, QString currentPage )

QgsProject::instance()->layerTreeRegistryBridge()->setNewLayersVisible( mySettings.value( "/qgis/new_layers_visible", true ).toBool() );

setupLayerTreeViewFromSettings();

mMapCanvas->enableAntiAliasing( mySettings.value( "/qgis/enable_anti_aliasing" ).toBool() );

int action = mySettings.value( "/qgis/wheel_action", 2 ).toInt();
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -1338,6 +1338,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
/**Removes annotation items in the canvas*/
void removeAnnotationItems();

//! Configure layer tree view according to the user options from QSettings
void setupLayerTreeViewFromSettings();

/// QgisApp aren't copyable
QgisApp( QgisApp const & );
/// QgisApp aren't copyable
Expand Down
10 changes: 9 additions & 1 deletion src/gui/layertree/qgslayertreemodel.cpp
Expand Up @@ -189,7 +189,15 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
if ( !layer )
return QVariant();
if ( layer->type() == QgsMapLayer::RasterLayer )
return QgsLayerItem::iconRaster();
{
if ( testFlag( ShowRasterPreviewIcon ) )
{
QgsRasterLayer* rlayer = qobject_cast<QgsRasterLayer *>( layer );
return QIcon( rlayer->previewAsPixmap( QSize( 32, 32 ) ) );
}
else
return QgsLayerItem::iconRaster();
}
else if ( layer->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* vlayer = static_cast<QgsVectorLayer*>( layer );
Expand Down
1 change: 1 addition & 0 deletions src/gui/layertree/qgslayertreemodel.h
Expand Up @@ -89,6 +89,7 @@ class GUI_EXPORT QgsLayerTreeModel : public QAbstractItemModel
{
// display flags
ShowSymbology = 0x0001, //!< Add symbology items for layer nodes
ShowRasterPreviewIcon = 0x0002, //!< Will use real preview of raster layer as icon (may be slow)

// behavioral flags
AllowNodeReorder = 0x1000, //!< Allow reordering with drag'n'drop
Expand Down

0 comments on commit 7c0da6d

Please sign in to comment.