1
/***************************************************************************
3
Single marker renderer dialog
6
copyright : (C) 2004 by Marco Hugentobler
7
email : mhugent@geo.unizh.ch
8
***************************************************************************/
10
/***************************************************************************
12
* This program is free software; you can redistribute it and/or modify *
13
* it under the terms of the GNU General Public License as published by *
14
* the Free Software Foundation; either version 2 of the License, or *
15
* (at your option) any later version. *
17
***************************************************************************/
18
/* $Id: qgssimadialog.cpp,v 1.29 2004/11/14 08:42:46 telwertowski Exp $ */
20
#include "qgssimadialog.h"
21
#include "qgssimarenderer.h"
22
#include "qgsvectorlayer.h"
23
#include "qgsmarkerdialog.h"
24
#include "qgsmarkersymbol.h"
25
#include "qgsrenderitem.h"
26
#include "qgsdlgvectorlayerproperties.h"
27
#include "qgslegenditem.h"
28
#include "qgssvgcache.h"
29
#include <qapplication.h>
31
#include <qfileinfo.h>
32
#include <qfiledialog.h>
34
#include <qpushbutton.h>
35
#include <qlineedit.h>
38
#include <qiconview.h>
41
QgsSiMaDialog::QgsSiMaDialog(QgsVectorLayer* vectorlayer): QgsSiMaDialogBase(), mVectorLayer(vectorlayer)
45
QgsSiMaRenderer *renderer;
47
//initial settings, use the buffer of the propertiesDialog if possible. If this is not possible, use the renderer of the vectorlayer directly
48
if (mVectorLayer->propertiesDialog())
50
renderer = dynamic_cast < QgsSiMaRenderer * >(mVectorLayer->propertiesDialog()->getBufferRenderer());
54
renderer = dynamic_cast < QgsSiMaRenderer * >(mVectorLayer->renderer());
59
QgsMarkerSymbol* sy=dynamic_cast < QgsMarkerSymbol* >(renderer->item()->getSymbol());
62
double scalefactor=sy->scaleFactor();
63
mScaleSpin->setValue((int)(scalefactor*100.0));
64
mSelectedMarker=sy->picture();
65
pmPreview->setPixmap(QgsSVGCache::instance().
66
getPixmap(mSelectedMarker, scalefactor));
70
qWarning("Warning, typecast failed in qgssimadialog.cpp on line 51");
71
mScaleSpin->setValue(100);
76
qWarning("Warning, typecast failed in qgssimadialog.cpp on line 42 or 46");
79
//set the dir to the default svg dir
80
#if defined(WIN32) || defined(Q_OS_MACX)
81
QString PKGDATAPATH = qApp->applicationDirPath() + "/share/qgis";
83
mCurrentDir=QString(PKGDATAPATH)+"/svg/";
85
qWarning("mCurrentDir in constructor: "+mCurrentDir);
87
visualizeMarkers(mCurrentDir);
88
mDirectoryEdit->setText(mCurrentDir);
89
//QString(PKGDATAPATH);
95
QgsSiMaDialog::~QgsSiMaDialog()
100
void QgsSiMaDialog::apply()
103
qWarning("in QgsSiMaDialog::apply()");
106
QgsMarkerSymbol* ms= new QgsMarkerSymbol();
107
QString string(mSelectedMarker);
112
ms->setPicture(string);
113
//set the scaled factor at the same time converting units from percentage
114
ms->setScaleFactor(mScaleSpin->value()/100.0);
116
QgsRenderItem* ri = new QgsRenderItem();
119
QgsSiMaRenderer *renderer = dynamic_cast < QgsSiMaRenderer * >(mVectorLayer->renderer());
123
renderer->addItem(ri);
127
qWarning("typecast failed in QgsSiMaDialog::apply()");
131
//add a pixmap to the legend item
133
//font tor the legend text
134
QFont f("arial", 10, QFont::Normal);
138
if (mVectorLayer->propertiesDialog())
140
name = mVectorLayer->propertiesDialog()->displayName();
148
QPixmap *pix = mVectorLayer->legendPixmap();
150
//spaces between legend pixmap elements
157
// get the marker used, calculate width and height of the legend pixmap
159
QgsSVGCache::instance().getPixmap(string, ms->scaleFactor());
160
int width = symbolPix.width() + fm.width(name) + leftspace +
161
betweenspace + rightspace;
162
int height = (symbolPix.height() > fm.height() ?
163
symbolPix.height() + topspace+bottomspace :
164
fm.height() + topspace+bottomspace);
165
pix->resize(width, height);
168
// paint symbol and layer name
170
p.drawPixmap(leftspace, topspace, symbolPix);
173
p.drawText(leftspace + betweenspace + symbolPix.width(),
174
pix->height() - bottomspace,name);
176
mVectorLayer->updateItemPixmap();
178
if (mVectorLayer->propertiesDialog())
180
mVectorLayer->propertiesDialog()->setRendererDirty(false);
182
//repaint the map canvas
183
mVectorLayer->triggerRepaint();
186
void QgsSiMaDialog::setMarker(const QString& file, double scaleFactor) {
192
mCurrentDir = fi.dir().path() + "/";
193
visualizeMarkers(mCurrentDir);
194
mDirectoryEdit->setText(mCurrentDir);
196
QIconViewItem* item = mIconView->findItem(fi.fileName(), Qt::ExactMatch);
199
mIconView->setSelected(item, true);
201
// set the scale factor
202
mScaleSpin->setValue(scaleFactor * 100.0);
205
emit settingsChanged();
208
const QString& QgsSiMaDialog::getPicture() const {
209
return mSelectedMarker;
212
double QgsSiMaDialog::getScaleFactor() const {
213
return mScaleSpin->value() / 100.0;
216
void QgsSiMaDialog::mIconView_selectionChanged(QIconViewItem * theIconViewItem)
218
mSelectedMarker=mCurrentDir+theIconViewItem->text();
220
//draw the SVG-Image on the button
221
double scalefactor=mScaleSpin->value()/100.0;
222
pmPreview->setPixmap(QgsSVGCache::instance().
223
getPixmap(mSelectedMarker, scalefactor));
225
emit settingsChanged();
228
void QgsSiMaDialog::mScaleSpin_valueChanged( int theSize)
231
std::cout << "mScaleSpin_valueChanged(" << theSize << ") " << std::endl;
233
//draw the SVG-Image on the button
234
if(!mSelectedMarker.isEmpty())
236
//user enters scaling factor as a percentage
237
double scalefactor=mScaleSpin->value()/100.0;
238
pmPreview->setPixmap(QgsSVGCache::instance().
239
getPixmap(mSelectedMarker, scalefactor));
242
emit settingsChanged();
245
void QgsSiMaDialog::mBrowseDirectoriesButton_clicked()
247
QString newdir=QFileDialog::getExistingDirectory(mCurrentDir,this,"get existing directory","Choose a directory",TRUE);
248
if (!newdir.isEmpty())
251
visualizeMarkers(mCurrentDir);
252
mDirectoryEdit->setText(mCurrentDir);
256
void QgsSiMaDialog::visualizeMarkers(QString directory)
261
QStringList files=dir.entryList("*.svg;*.SVG");
263
for(QStringList::Iterator it = files.begin(); it != files.end(); ++it )
268
QPixmap pix = QgsSVGCache::instance().getPixmap(mCurrentDir +
270
QIconViewItem* ivi=new QIconViewItem(mIconView,*it,pix);
274
QString QgsSiMaDialog::defaultDir()
276
#if defined(WIN32) || defined(Q_OS_MACX)
277
QString PKGDATAPATH = qApp->applicationDirPath() + "/share/qgis";
279
QString dir = QString(PKGDATAPATH)+"/svg";