Skip to content
Permalink
Browse files
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
  • Loading branch information
mhugent committed Jun 5, 2010
1 parent 8696c2f commit 29729e24879a8fcffee07165f3d95cfb83912d57
Showing with 24 additions and 3 deletions.
  1. +3 −0 src/core/CMakeLists.txt
  2. +18 −3 src/core/composer/qgslegendmodel.cpp
  3. +3 −0 src/core/composer/qgslegendmodel.h
@@ -428,6 +428,9 @@ SET(QGIS_CORE_HDRS
qgsvectoroverlay.h
qgstolerance.h

composer/qgslegendmodel.h
composer/qgscomposerlegenditem.h

raster/qgscliptominmaxenhancement.h
raster/qgscolorrampshader.h
raster/qgscolorrampshader.h
@@ -27,6 +27,7 @@
#include "qgssymbol.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
#include <QApplication>
#include <QDomDocument>
#include <QDomElement>
#include <QMimeData>
@@ -40,6 +41,9 @@ QgsLegendModel::QgsLegendModel(): QStandardItemModel()
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( addLayer( QgsMapLayer* ) ) );
}
setItemPrototype( new QgsComposerSymbolItem() );

QWidgetList topLevelWidgets = QApplication::topLevelWidgets();
mHasTopLevelWindow = ( topLevelWidgets.size() > 0 );
}

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

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

currentSymbolItem = new QgsComposerSymbolItem( QIcon( QPixmap::fromImage( symbolImage ) ), itemText );
currentSymbolItem = new QgsComposerSymbolItem( itemText );
if ( mHasTopLevelWindow )//only use QIcon / QPixmap if we have a running x-server
{
currentSymbolItem->setIcon( QIcon( QPixmap::fromImage( symbolImage ) ) );
}

if ( !currentSymbolItem )
{
@@ -109,6 +109,9 @@ class CORE_EXPORT QgsLegendModel: public QStandardItemModel

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

#endif

0 comments on commit 29729e2

Please sign in to comment.