Skip to content

Commit 29729e2

Browse files
author
mhugent
committed
Some changes to use qgslegendmodel without a running x-server
git-svn-id: http://svn.osgeo.org/qgis/trunk@13660 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 8696c2f commit 29729e2

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/core/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,9 @@ SET(QGIS_CORE_HDRS
428428
qgsvectoroverlay.h
429429
qgstolerance.h
430430

431+
composer/qgslegendmodel.h
432+
composer/qgscomposerlegenditem.h
433+
431434
raster/qgscliptominmaxenhancement.h
432435
raster/qgscolorrampshader.h
433436
raster/qgscolorrampshader.h

src/core/composer/qgslegendmodel.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "qgssymbol.h"
2828
#include "qgsvectordataprovider.h"
2929
#include "qgsvectorlayer.h"
30+
#include <QApplication>
3031
#include <QDomDocument>
3132
#include <QDomElement>
3233
#include <QMimeData>
@@ -40,6 +41,9 @@ QgsLegendModel::QgsLegendModel(): QStandardItemModel()
4041
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( addLayer( QgsMapLayer* ) ) );
4142
}
4243
setItemPrototype( new QgsComposerSymbolItem() );
44+
45+
QWidgetList topLevelWidgets = QApplication::topLevelWidgets();
46+
mHasTopLevelWindow = ( topLevelWidgets.size() > 0 );
4347
}
4448

4549
QgsLegendModel::~QgsLegendModel()
@@ -147,7 +151,10 @@ int QgsLegendModel::addVectorLayerItemsV2( QStandardItem* layerItem, QgsVectorLa
147151
currentSymbolItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
148152
if ( symbolIt->second )
149153
{
150-
currentSymbolItem->setIcon( QgsSymbolLayerV2Utils::symbolPreviewIcon( symbolIt->second, QSize( 30, 30 ) ) );
154+
if ( mHasTopLevelWindow ) //only use QIcon / QPixmap if we have a running x-server
155+
{
156+
currentSymbolItem->setIcon( QgsSymbolLayerV2Utils::symbolPreviewIcon( symbolIt->second, QSize( 30, 30 ) ) );
157+
}
151158
currentSymbolItem->setSymbolV2( symbolIt->second->clone() );
152159
}
153160
layerItem->setChild( layerItem->rowCount(), 0, currentSymbolItem );
@@ -228,8 +235,12 @@ int QgsLegendModel::addRasterLayerItem( QStandardItem* layerItem, QgsMapLayer* r
228235
return 2;
229236
}
230237

238+
QgsComposerRasterSymbolItem* currentSymbolItem = new QgsComposerRasterSymbolItem();
231239
//use a vector symbol item without symbol
232-
QgsComposerRasterSymbolItem* currentSymbolItem = new QgsComposerRasterSymbolItem( QIcon( rasterLayer->legendAsPixmap( true ) ), "" );
240+
if ( mHasTopLevelWindow ) //only use QIcon / QPixmap if we have a running x-server
241+
{
242+
currentSymbolItem->setIcon( QIcon( rasterLayer->legendAsPixmap( true ) ) );
243+
}
233244
currentSymbolItem->setLayerID( rasterLayer->getLayerID() );
234245
int currentRowCount = layerItem->rowCount();
235246
layerItem->setChild( currentRowCount, 0, currentSymbolItem );
@@ -421,7 +432,11 @@ QStandardItem* QgsLegendModel::itemFromSymbol( QgsSymbol* s, int opacity, const
421432
}
422433
}
423434

424-
currentSymbolItem = new QgsComposerSymbolItem( QIcon( QPixmap::fromImage( symbolImage ) ), itemText );
435+
currentSymbolItem = new QgsComposerSymbolItem( itemText );
436+
if ( mHasTopLevelWindow )//only use QIcon / QPixmap if we have a running x-server
437+
{
438+
currentSymbolItem->setIcon( QIcon( QPixmap::fromImage( symbolImage ) ) );
439+
}
425440

426441
if ( !currentSymbolItem )
427442
{

src/core/composer/qgslegendmodel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ class CORE_EXPORT QgsLegendModel: public QStandardItemModel
109109

110110
protected:
111111
QStringList mLayerIds;
112+
/**True if this application has toplevel windows (normally true). If this is false, this means that the application
113+
might not have a running x-server on unix systems and so QPixmap and QIcon cannot be used*/
114+
bool mHasTopLevelWindow;
112115
};
113116

114117
#endif

0 commit comments

Comments
 (0)