Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Some changes to use qgslegendmodel without a running x-server
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13660 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jun 5, 2010
1 parent b541da5 commit ab8b65c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -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
Expand Down
21 changes: 18 additions & 3 deletions src/core/composer/qgslegendmodel.cpp
Expand Up @@ -27,6 +27,7 @@
#include "qgssymbol.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
#include <QApplication>
#include <QDomDocument>
#include <QDomElement>
#include <QMimeData>
Expand All @@ -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()
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 )
{
Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgslegendmodel.h
Expand Up @@ -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 ab8b65c

Please sign in to comment.