~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/app/qgssinglesymboldialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                         qgssinglesymboldialog.cpp  -  description
 
3
                             -------------------
 
4
    begin                : Oct 2003
 
5
    copyright            : (C) 2003 by Marco Hugentobler
 
6
    email                : mhugent@geo.unizh.ch
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
/* $Id$ */
 
18
 
 
19
#include "qgssinglesymboldialog.h"
 
20
#include "qgsmarkercatalogue.h"
 
21
#include "qgssinglesymbolrenderer.h"
 
22
#include "qgsfield.h"
 
23
#include "qgssymbol.h"
 
24
#include "qgssymbologyutils.h"
 
25
#include "qgsvectorlayer.h"
 
26
#include "qgsvectordataprovider.h"
 
27
#include "qgslogger.h"
 
28
 
 
29
#include <QColorDialog>
 
30
#include <QPainter>
 
31
#include <QImage>
 
32
#include <QFileDialog>
 
33
#include <QListWidgetItem>
 
34
#include <QKeyEvent>
 
35
 
 
36
#define DO_NOT_USE_STR "<off>"
 
37
 
 
38
QgsSingleSymbolDialog::QgsSingleSymbolDialog(): QDialog(), mVectorLayer( 0 )
 
39
{
 
40
  setupUi( this );
 
41
  QgsDebugMsg( "entered." );
 
42
}
 
43
 
 
44
QgsSingleSymbolDialog::QgsSingleSymbolDialog( QgsVectorLayer * layer, bool disabled ): QDialog(), mVectorLayer( layer ), mDisabled( disabled )
 
45
{
 
46
  setupUi( this );
 
47
  QgsDebugMsg( "entered." );
 
48
 
 
49
  //
 
50
  //set point symbol list
 
51
  //
 
52
 
 
53
  // If this layer doesn't have points, break out of the following
 
54
  // two loops after the first iteration. This gives one point
 
55
  // symbol in the dialog, etc so that other code can rely on such a
 
56
  // fact, but avoids the long time required to load all of the
 
57
  // available symbols when they are not needed.
 
58
 
 
59
  // NOTE BY Tim: I think the note above and the break out in the
 
60
  // loops can be removed now with changes I have made to use combo
 
61
  // boxes for line style and fill style...test and remove if poss.
 
62
 
 
63
  QAction *refreshAction = new QAction( tr( "Refresh markers" ), lstSymbols );
 
64
  lstSymbols->addAction( refreshAction );
 
65
  connect( refreshAction, SIGNAL( triggered() ), QgsMarkerCatalogue::instance(), SLOT( refreshList() ) );
 
66
  connect( QgsMarkerCatalogue::instance(), SIGNAL( markersRefreshed() ), this, SLOT( refreshMarkers() ) );
 
67
  lstSymbols->setContextMenuPolicy( Qt::ActionsContextMenu );
 
68
 
 
69
  //do the signal/slot connections
 
70
  connect( btnOutlineColor, SIGNAL( clicked() ), this, SLOT( selectOutlineColor() ) );
 
71
  connect( btnFillColor, SIGNAL( clicked() ), this, SLOT( selectFillColor() ) );
 
72
  connect( outlinewidthspinbox, SIGNAL( valueChanged( double ) ), this, SLOT( resendSettingsChanged() ) );
 
73
  connect( mLabelEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( resendSettingsChanged() ) );
 
74
  connect( lstSymbols, SIGNAL( currentItemChanged( QListWidgetItem *, QListWidgetItem * ) ),
 
75
           this, SLOT( symbolChanged( QListWidgetItem *, QListWidgetItem * ) ) );
 
76
  connect( mPointSizeSpinBox, SIGNAL( valueChanged( double ) ), this, SLOT( resendSettingsChanged() ) );
 
77
  connect( mPointSizeUnitsCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( resendSettingsChanged() ) );
 
78
  connect( mRotationClassificationComboBox, SIGNAL( currentIndexChanged( const QString & ) ),
 
79
           this, SLOT( resendSettingsChanged() ) );
 
80
  connect( mScaleClassificationComboBox, SIGNAL( currentIndexChanged( const QString & ) ),
 
81
           this, SLOT( resendSettingsChanged() ) );
 
82
  connect( mSymbolComboBox, SIGNAL( currentIndexChanged( const QString & ) ),
 
83
           this, SLOT( resendSettingsChanged() ) );
 
84
  connect( cboOutlineStyle, SIGNAL(
 
85
             currentIndexChanged( const QString & ) ), this, SLOT( resendSettingsChanged() ) );
 
86
  connect( cboFillStyle, SIGNAL(
 
87
             currentIndexChanged( const QString & ) ), this, SLOT( resendSettingsChanged() ) );
 
88
  //need this to deal with when texture fill is selected or deselected
 
89
  connect( cboFillStyle, SIGNAL(
 
90
             currentIndexChanged( int ) ), this, SLOT( fillStyleChanged( int ) ) );
 
91
  connect( toolSelectTexture, SIGNAL( clicked() ), this, SLOT( selectTextureImage() ) );
 
92
 
 
93
  refreshMarkers();
 
94
}
 
95
 
 
96
void QgsSingleSymbolDialog::refreshMarkers()
 
97
{
 
98
  lstSymbols->blockSignals( true );
 
99
  lstSymbols->clear();
 
100
 
 
101
  QPen pen( QColor( 0, 0, 255 ) );
 
102
  QBrush brush( QColor( 220, 220, 220 ), Qt::SolidPattern );
 
103
  int size = 18;
 
104
  int myCounter = 0;
 
105
  QStringList ml = QgsMarkerCatalogue::instance()->list();
 
106
  for ( QStringList::iterator it = ml.begin(); it != ml.end(); ++it )
 
107
  {
 
108
    QPixmap myPixmap = QPixmap::fromImage( QgsMarkerCatalogue::instance()->imageMarker( *it, size, pen, brush ) );
 
109
    QListWidgetItem * mypItem = new QListWidgetItem( lstSymbols );
 
110
    QIcon myIcon;
 
111
    myIcon.addPixmap( myPixmap );
 
112
    mypItem->setIcon( myIcon );
 
113
    mypItem->setText( "" );
 
114
    mypItem->setToolTip( *it );
 
115
    //store the symbol offset in the UserData role for later retrieval
 
116
    mypItem->setData( Qt::UserRole, *it );
 
117
    mypItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
 
118
    if ( mVectorLayer && mVectorLayer->geometryType() != QGis::Point )
 
119
    {
 
120
      break;
 
121
    }
 
122
    ++myCounter;
 
123
  }
 
124
 
 
125
  // Find out the numerical fields of mVectorLayer, and populate the ComboBoxes
 
126
  QgsVectorDataProvider *provider = mVectorLayer->dataProvider();
 
127
  if ( provider )
 
128
  {
 
129
    const QgsFieldMap & fields = provider->fields();
 
130
    QString str;
 
131
 
 
132
    mRotationClassificationComboBox->addItem( DO_NOT_USE_STR, -1 );
 
133
    mScaleClassificationComboBox->addItem( DO_NOT_USE_STR, -1 );
 
134
    mSymbolComboBox->addItem( DO_NOT_USE_STR, -1 );
 
135
    for ( QgsFieldMap::const_iterator it = fields.begin();
 
136
          it != fields.end();
 
137
          ++it )
 
138
    {
 
139
      QVariant::Type type = ( *it ).type();
 
140
      if ( type == QVariant::Int || type == QVariant::Double )
 
141
      {
 
142
        mRotationClassificationComboBox->addItem( it->name(), it.key() );
 
143
        mScaleClassificationComboBox->addItem( it->name(), it.key() );
 
144
      }
 
145
      else if ( type == QVariant::String )
 
146
      {
 
147
        mSymbolComboBox->addItem( it->name(), it.key() );
 
148
      }
 
149
    }
 
150
  }
 
151
  else
 
152
  {
 
153
    QgsDebugMsg( "Warning, data provider is null" );
 
154
    return;
 
155
  }
 
156
  //
 
157
  //set outline / line style
 
158
  //
 
159
  cboOutlineStyle->addItem( QIcon( QgsSymbologyUtils::char2LinePixmap( "SolidLine" ) ), "", "SolidLine" );
 
160
  cboOutlineStyle->addItem( QIcon( QgsSymbologyUtils::char2LinePixmap( "DashLine" ) ), "", "DashLine" );
 
161
  cboOutlineStyle->addItem( QIcon( QgsSymbologyUtils::char2LinePixmap( "DotLine" ) ), "", "DotLine" );
 
162
  cboOutlineStyle->addItem( QIcon( QgsSymbologyUtils::char2LinePixmap( "DashDotLine" ) ), "" , "DashDotLine" );
 
163
  cboOutlineStyle->addItem( QIcon( QgsSymbologyUtils::char2LinePixmap( "DashDotDotLine" ) ), "", "DashDotDotLine" );
 
164
  cboOutlineStyle->addItem( QIcon( QgsSymbologyUtils::char2LinePixmap( "NoPen" ) ), tr( "None" ), "NoPen" );
 
165
 
 
166
  //
 
167
  //set pattern icons and state
 
168
  //
 
169
  cboFillStyle->addItem( QIcon( QgsSymbologyUtils::char2PatternPixmap( "SolidPattern" ) ), "", "SolidPattern" );
 
170
  cboFillStyle->addItem( QIcon( QgsSymbologyUtils::char2PatternPixmap( "HorPattern" ) ), "", "HorPattern" );
 
171
  cboFillStyle->addItem( QIcon( QgsSymbologyUtils::char2PatternPixmap( "VerPattern" ) ), "", "VerPattern" );
 
172
  cboFillStyle->addItem( QIcon( QgsSymbologyUtils::char2PatternPixmap( "CrossPattern" ) ), "", "CrossPattern" );
 
173
  cboFillStyle->addItem( QIcon( QgsSymbologyUtils::char2PatternPixmap( "BDiagPattern" ) ), "", "BDiagPattern" );
 
174
  cboFillStyle->addItem( QIcon( QgsSymbologyUtils::char2PatternPixmap( "FDiagPattern" ) ), "", "FDiagPattern" );
 
175
  cboFillStyle->addItem( QIcon( QgsSymbologyUtils::char2PatternPixmap( "DiagCrossPattern" ) ), "", "DiagCrossPattern" );
 
176
  cboFillStyle->addItem( QIcon( QgsSymbologyUtils::char2PatternPixmap( "Dense1Pattern" ) ), "", "Dense1Pattern" );
 
177
  cboFillStyle->addItem( QIcon( QgsSymbologyUtils::char2PatternPixmap( "Dense2Pattern" ) ), "", "Dense2Pattern" );
 
178
  cboFillStyle->addItem( QIcon( QgsSymbologyUtils::char2PatternPixmap( "Dense3Pattern" ) ), "", "Dense3Pattern" );
 
179
  cboFillStyle->addItem( QIcon( QgsSymbologyUtils::char2PatternPixmap( "Dense4Pattern" ) ), "", "Dense4Pattern" );
 
180
  cboFillStyle->addItem( QIcon( QgsSymbologyUtils::char2PatternPixmap( "Dense5Pattern" ) ), "", "Dense5Pattern" );
 
181
  cboFillStyle->addItem( QIcon( QgsSymbologyUtils::char2PatternPixmap( "Dense6Pattern" ) ), "", "Dense6Pattern" );
 
182
  cboFillStyle->addItem( QIcon( QgsSymbologyUtils::char2PatternPixmap( "Dense7Pattern" ) ), "", "Dense7Pattern" );
 
183
  cboFillStyle->addItem( QIcon( QgsSymbologyUtils::char2PatternPixmap( "NoBrush" ) ), tr( "None" ), "NoBrush" );
 
184
  cboFillStyle->addItem( QIcon( QgsSymbologyUtils::char2PatternPixmap( "TexturePattern" ) ), tr( "Texture" ), "TexturePattern" );
 
185
 
 
186
  if ( mVectorLayer && mVectorLayer->geometryType() != QGis::Point )
 
187
  {
 
188
    mGroupPoint->setVisible( false );
 
189
    mGroupPoint->setEnabled( false );
 
190
    mGroupDrawingByField->setVisible( false );
 
191
    mGroupDrawingByField->setEnabled( false );
 
192
  }
 
193
 
 
194
  if ( mDisabled )
 
195
  {
 
196
    unset();
 
197
  }
 
198
  else
 
199
  {
 
200
    if ( mVectorLayer )
 
201
    {
 
202
      const QgsSingleSymbolRenderer *renderer = dynamic_cast<const QgsSingleSymbolRenderer *>( mVectorLayer->renderer() );
 
203
 
 
204
      if ( renderer )
 
205
      {
 
206
        // Set from the existing renderer
 
207
        set( renderer->symbols().first() );
 
208
      }
 
209
      else
 
210
      {
 
211
        // Take values from an example instance
 
212
        QgsSingleSymbolRenderer exampleRenderer = QgsSingleSymbolRenderer( mVectorLayer->geometryType() );
 
213
        set( exampleRenderer.symbols().first() );
 
214
      }
 
215
    }
 
216
    else
 
217
    {
 
218
      QgsDebugMsg( "Warning, layer is a null pointer" );
 
219
    }
 
220
  }
 
221
 
 
222
  lstSymbols->blockSignals( false );
 
223
}
 
224
 
 
225
QgsSingleSymbolDialog::~QgsSingleSymbolDialog()
 
226
{
 
227
  QgsDebugMsg( "entered." );
 
228
}
 
229
 
 
230
void QgsSingleSymbolDialog::selectOutlineColor()
 
231
{
 
232
  QColor c = QColorDialog::getColor( btnOutlineColor->color(), this );
 
233
 
 
234
  if ( c.isValid() )
 
235
  {
 
236
    btnOutlineColor->setColor( c );
 
237
    emit settingsChanged();
 
238
  }
 
239
 
 
240
  activateWindow();
 
241
}
 
242
 
 
243
void QgsSingleSymbolDialog::selectFillColor()
 
244
{
 
245
  QColor c = QColorDialog::getColor( btnFillColor->color(), this );
 
246
 
 
247
  if ( c.isValid() )
 
248
  {
 
249
    btnFillColor->setColor( c );
 
250
    emit settingsChanged();
 
251
  }
 
252
 
 
253
  activateWindow();
 
254
}
 
255
 
 
256
//should this method have a different name?
 
257
void QgsSingleSymbolDialog::selectTextureImage()
 
258
{
 
259
  QString fileName = QFileDialog::getOpenFileName( this, "Open File",
 
260
                     mTexturePath,
 
261
                     "Images (*.png *.xpm *.jpg)" ); //should we allow other types of images?
 
262
 
 
263
  if ( fileName.isNull() == false )
 
264
  { //only process the string if the user clicked OK
 
265
    mTexturePath = fileName;
 
266
    resendSettingsChanged();
 
267
  }
 
268
}
 
269
 
 
270
void QgsSingleSymbolDialog::apply( QgsSymbol *sy )
 
271
{
 
272
  //query the values of the widgets and set the symbology of the vector layer
 
273
  if ( btnFillColor->isEnabled() )
 
274
    sy->setFillColor( btnFillColor->color() );
 
275
 
 
276
  if ( outlinewidthspinbox->isEnabled() )
 
277
    sy->setLineWidth( outlinewidthspinbox->value() );
 
278
 
 
279
  if ( btnOutlineColor->isEnabled() )
 
280
    sy->setColor( btnOutlineColor->color() );
 
281
 
 
282
  //
 
283
  // Apply point symbol
 
284
  //
 
285
  if ( lstSymbols->isEnabled() && lstSymbols->currentItem() )
 
286
  {
 
287
    sy->setNamedPointSymbol( lstSymbols->currentItem()->data( Qt::UserRole ).toString() ) ;
 
288
  }
 
289
 
 
290
  if ( mPointSizeSpinBox->isEnabled() )
 
291
    sy->setPointSize( mPointSizeSpinBox->value() );
 
292
 
 
293
  if ( mPointSizeUnitsCheckBox->isEnabled() )
 
294
    sy->setPointSizeUnits( mPointSizeUnitsCheckBox->isChecked() );
 
295
 
 
296
  std::map<QString, int>::iterator iter;
 
297
  if ( mRotationClassificationComboBox->isEnabled() )
 
298
  {
 
299
    sy->setRotationClassificationField( mRotationClassificationComboBox->itemData( mRotationClassificationComboBox->currentIndex() ).toInt() );
 
300
  }
 
301
 
 
302
  if ( mScaleClassificationComboBox->isEnabled() )
 
303
  {
 
304
    sy->setScaleClassificationField( mScaleClassificationComboBox->itemData( mScaleClassificationComboBox->currentIndex() ).toInt() );
 
305
  }
 
306
 
 
307
  if ( mSymbolComboBox->isEnabled() )
 
308
  {
 
309
    sy->setSymbolField( mSymbolComboBox->itemData( mSymbolComboBox->currentIndex() ).toInt() );
 
310
  }
 
311
 
 
312
  //
 
313
  // Apply the line style
 
314
  //
 
315
  if ( cboOutlineStyle->isEnabled() )
 
316
  {
 
317
    QString myLineStyle =
 
318
      cboOutlineStyle->itemData( cboOutlineStyle->currentIndex(), Qt::UserRole ).toString();
 
319
    sy->setLineStyle( QgsSymbologyUtils::qString2PenStyle( myLineStyle ) );
 
320
  }
 
321
 
 
322
  //
 
323
  // Apply the pattern
 
324
  //
 
325
 
 
326
  //Store the file path, and set the brush to TexturePattern.  If we have a different button selected,
 
327
  // the below code will override it, but leave the file path alone.
 
328
 
 
329
  sy->setCustomTexture( mTexturePath );
 
330
 
 
331
  if ( cboFillStyle->isEnabled() )
 
332
  {
 
333
    QString myFillStyle =
 
334
      cboFillStyle->itemData( cboFillStyle->currentIndex(), Qt::UserRole ).toString();
 
335
    sy->setFillStyle( QgsSymbologyUtils::qString2BrushStyle( myFillStyle ) );
 
336
  }
 
337
 
 
338
  if ( mLabelEdit->isEnabled() )
 
339
    sy->setLabel( mLabelEdit->text() );
 
340
}
 
341
 
 
342
void QgsSingleSymbolDialog::apply()
 
343
{
 
344
  QgsSymbol* sy = new QgsSymbol( mVectorLayer->geometryType() );
 
345
  apply( sy );
 
346
 
 
347
  QgsSingleSymbolRenderer *renderer = new QgsSingleSymbolRenderer( mVectorLayer->geometryType() );
 
348
  renderer->addSymbol( sy );
 
349
  renderer->updateSymbolAttributes();
 
350
 
 
351
  mVectorLayer->setRenderer( renderer );
 
352
}
 
353
 
 
354
void QgsSingleSymbolDialog::unset()
 
355
{
 
356
  mLabelEdit->setEnabled( false );
 
357
  lstSymbols->setEnabled( false );
 
358
  mPointSizeSpinBox->setEnabled( false );
 
359
  mPointSizeUnitsCheckBox->setEnabled( false );
 
360
  mRotationClassificationComboBox->setEnabled( false );
 
361
  mScaleClassificationComboBox->setEnabled( false );
 
362
  mSymbolComboBox->setEnabled( false );
 
363
  outlinewidthspinbox->setEnabled( false );
 
364
  btnOutlineColor->setEnabled( false );
 
365
  cboOutlineStyle->setEnabled( false );
 
366
 
 
367
  cboFillStyle->setEnabled( false );
 
368
  btnFillColor->setEnabled( false );
 
369
}
 
370
 
 
371
void QgsSingleSymbolDialog::set( const QgsSymbol *sy )
 
372
{
 
373
  //set label
 
374
  mLabelEdit->setText( sy->label() );
 
375
 
 
376
  // Set point symbol
 
377
  QString mySymbolName = sy->pointSymbolName();
 
378
  for ( int i = 0; i < lstSymbols->count(); ++i )
 
379
  {
 
380
    if ( lstSymbols->item( i )->data( Qt::UserRole ).toString() == ( mySymbolName ) )
 
381
    {
 
382
      lstSymbols->setCurrentItem( lstSymbols->item( i ) );
 
383
      lstSymbols->item( i )->setBackground( QBrush( Qt::cyan ) );
 
384
      break;
 
385
    }
 
386
  }
 
387
  mPointSizeSpinBox->setValue( sy->pointSize() );
 
388
  mPointSizeUnitsCheckBox->setChecked( sy->pointSizeUnits() );
 
389
 
 
390
  int index;
 
391
 
 
392
  index = mRotationClassificationComboBox->findData( sy->rotationClassificationField() );
 
393
  mRotationClassificationComboBox->setCurrentIndex( index < 0 ? 0 : index );
 
394
 
 
395
  index = mScaleClassificationComboBox->findData( sy->scaleClassificationField() );
 
396
  mScaleClassificationComboBox->setCurrentIndex( index < 0 ? 0 : index );
 
397
 
 
398
  index = mSymbolComboBox->findData( sy->symbolField() );
 
399
  mSymbolComboBox->setCurrentIndex( index < 0 ? 0 : index );
 
400
 
 
401
  outlinewidthspinbox->setValue( sy->pen().widthF() );
 
402
 
 
403
  //set line width 1 as minimum to avoid confusion between line width 0 and no pen line style
 
404
  // ... but, drawLine is not correct with width > 0 -> until solved set to 0
 
405
  outlinewidthspinbox->setMinimum( 0 );
 
406
 
 
407
  btnFillColor->setColor( sy->brush().color() );
 
408
 
 
409
  btnOutlineColor->setColor( sy->pen().color() );
 
410
 
 
411
  //load the icons stored in QgsSymbologyUtils.cpp (to avoid redundancy)
 
412
 
 
413
  //
 
414
  // Set the line style combo
 
415
  //
 
416
 
 
417
  QPen myPen = sy->pen();
 
418
  QString myLineStyle = QgsSymbologyUtils::penStyle2QString( myPen.style() );
 
419
  for ( int i = 0; i < cboOutlineStyle->count(); ++i )
 
420
  {
 
421
    if ( cboOutlineStyle->itemData( i, Qt::UserRole ).toString() == myLineStyle )
 
422
    {
 
423
      cboOutlineStyle->setCurrentIndex( i );
 
424
      break;
 
425
    }
 
426
  }
 
427
 
 
428
  //
 
429
  // Set the brush combo
 
430
  //
 
431
 
 
432
  QBrush myBrush = sy->brush();
 
433
  QString myFillStyle =  QgsSymbologyUtils::brushStyle2QString( myBrush.style() );
 
434
  for ( int i = 0; i < cboFillStyle->count(); ++i )
 
435
  {
 
436
    if ( cboFillStyle->itemData( i, Qt::UserRole ).toString() == myFillStyle )
 
437
    {
 
438
      cboFillStyle->setCurrentIndex( i );
 
439
      break;
 
440
    }
 
441
  }
 
442
 
 
443
  //get and show the file path, even if we aren't using it.
 
444
  mTexturePath = sy->customTexture();
 
445
  //if the file path isn't empty, show the image on the button
 
446
  if ( sy->customTexture().size() > 0 )
 
447
  {
 
448
    //show the current texture image
 
449
    // texture->setPixmap(QPixmap(sy->customTexture()));
 
450
  }
 
451
  else
 
452
  {
 
453
    //show the default question mark
 
454
    //texture->setPixmap(QgsSymbologyUtils::char2PatternPixmap("TexturePattern"));
 
455
  }
 
456
 
 
457
  mLabelEdit->setEnabled( true );
 
458
  lstSymbols->setEnabled( true );
 
459
  mPointSizeSpinBox->setEnabled( true );
 
460
  mPointSizeUnitsCheckBox->setEnabled( true );
 
461
  mRotationClassificationComboBox->setEnabled( true );
 
462
  mScaleClassificationComboBox->setEnabled( true );
 
463
  mSymbolComboBox->setEnabled( true );
 
464
  outlinewidthspinbox->setEnabled( true );
 
465
  btnOutlineColor->setEnabled( true );
 
466
  cboOutlineStyle->setEnabled( true );
 
467
 
 
468
  if ( mVectorLayer && mVectorLayer->geometryType() != QGis::Line )
 
469
  {
 
470
    btnFillColor->setEnabled( true );
 
471
    cboFillStyle->setEnabled( true );
 
472
  }
 
473
}
 
474
 
 
475
void QgsSingleSymbolDialog::updateSet( const QgsSymbol *sy )
 
476
{
 
477
  if ( mLabelEdit->isEnabled() && mLabelEdit->text() != sy->label() )
 
478
    mLabelEdit->setEnabled( false );
 
479
 
 
480
  if ( lstSymbols->isEnabled() && lstSymbols->currentItem()->data( Qt::UserRole ).toString() != sy->pointSymbolName() )
 
481
    lstSymbols->setEnabled( false );
 
482
 
 
483
  if ( mPointSizeSpinBox->isEnabled() && !doubleNear( mPointSizeSpinBox->value(), sy->pointSize() ) )
 
484
    mPointSizeSpinBox->setEnabled( false );
 
485
 
 
486
  if ( mPointSizeUnitsCheckBox->isEnabled() && mPointSizeUnitsCheckBox->isChecked() != sy->pointSizeUnits() )
 
487
    mPointSizeUnitsCheckBox->setEnabled( false );
 
488
 
 
489
  if ( mRotationClassificationComboBox->isEnabled() &&
 
490
       mRotationClassificationComboBox->itemData( mRotationClassificationComboBox->currentIndex() ).toInt() != sy->rotationClassificationField() )
 
491
    mRotationClassificationComboBox->setEnabled( false );
 
492
 
 
493
  if ( mScaleClassificationComboBox->isEnabled() &&
 
494
       mScaleClassificationComboBox->itemData( mScaleClassificationComboBox->currentIndex() ).toInt() != sy->scaleClassificationField() )
 
495
    mScaleClassificationComboBox->setEnabled( false );
 
496
 
 
497
  if ( mSymbolComboBox->isEnabled() &&
 
498
       mSymbolComboBox->itemData( mSymbolComboBox->currentIndex() ).toInt() != sy->symbolField() )
 
499
    mSymbolComboBox->setEnabled( false );
 
500
 
 
501
  if ( outlinewidthspinbox->isEnabled() && !doubleNear( outlinewidthspinbox->value(), sy->pen().widthF() ) )
 
502
    outlinewidthspinbox->setEnabled( false );
 
503
 
 
504
  if ( btnFillColor->isEnabled() &&  btnFillColor->color() != sy->brush().color() )
 
505
    btnFillColor->setEnabled( false );
 
506
 
 
507
  if ( btnOutlineColor->isEnabled() &&  btnOutlineColor->color() != sy->pen().color() )
 
508
    btnOutlineColor->setEnabled( false );
 
509
 
 
510
  if ( cboOutlineStyle->isEnabled() )
 
511
  {
 
512
    QPen myPen = sy->pen();
 
513
    QString myLineStyle = QgsSymbologyUtils::penStyle2QString( myPen.style() );
 
514
    if ( cboOutlineStyle->itemData( cboOutlineStyle->currentIndex(), Qt::UserRole ).toString() != myLineStyle )
 
515
      cboOutlineStyle->setEnabled( false );
 
516
  }
 
517
 
 
518
  if ( cboFillStyle->isEnabled() )
 
519
  {
 
520
    QBrush myBrush = sy->brush();
 
521
    QString myFillStyle =  QgsSymbologyUtils::brushStyle2QString( myBrush.style() );
 
522
    if ( cboFillStyle->itemData( cboFillStyle->currentIndex(), Qt::UserRole ).toString() != myFillStyle )
 
523
      cboFillStyle->setEnabled( false );
 
524
  }
 
525
}
 
526
 
 
527
void QgsSingleSymbolDialog::setOutlineColor( QColor& c )
 
528
{
 
529
  btnOutlineColor->setColor( c );
 
530
}
 
531
 
 
532
void QgsSingleSymbolDialog::setOutlineStyle( Qt::PenStyle pstyle )
 
533
{
 
534
  QString myLineStyle = QgsSymbologyUtils::penStyle2QString( pstyle );
 
535
  for ( int i = 0; i < cboOutlineStyle->count(); ++i )
 
536
  {
 
537
    if ( cboOutlineStyle->itemData( i, Qt::UserRole ).toString() == myLineStyle )
 
538
    {
 
539
      cboOutlineStyle->setCurrentIndex( i );
 
540
      break;
 
541
    }
 
542
  }
 
543
}
 
544
 
 
545
void QgsSingleSymbolDialog::setFillColor( QColor& c )
 
546
{
 
547
  btnFillColor->setColor( c );
 
548
}
 
549
 
 
550
void QgsSingleSymbolDialog::setFillStyle( Qt::BrushStyle fstyle )
 
551
{
 
552
  QgsDebugMsg( QString( "Setting fill style: %1" ).arg( QgsSymbologyUtils::brushStyle2QString( fstyle ) ) );
 
553
 
 
554
  QString myFillStyle =  QgsSymbologyUtils::brushStyle2QString( fstyle );
 
555
  for ( int i = 0; i < cboFillStyle->count(); ++i )
 
556
  {
 
557
    if ( cboFillStyle->itemData( i, Qt::UserRole ).toString() == myFillStyle )
 
558
    {
 
559
      cboFillStyle->setCurrentIndex( i );
 
560
      break;
 
561
    }
 
562
  }
 
563
}
 
564
 
 
565
void QgsSingleSymbolDialog::setOutlineWidth( double width )
 
566
{
 
567
  outlinewidthspinbox->setValue( width );
 
568
}
 
569
 
 
570
QColor QgsSingleSymbolDialog::getOutlineColor()
 
571
{
 
572
  return btnOutlineColor->color();
 
573
}
 
574
 
 
575
Qt::PenStyle QgsSingleSymbolDialog::getOutlineStyle()
 
576
{
 
577
  QString myLineStyle =
 
578
    cboOutlineStyle->itemData( cboOutlineStyle->currentIndex(), Qt::UserRole ).toString();
 
579
  return QgsSymbologyUtils::qString2PenStyle( myLineStyle );
 
580
}
 
581
 
 
582
double QgsSingleSymbolDialog::getOutlineWidth()
 
583
{
 
584
  return outlinewidthspinbox->value();
 
585
}
 
586
 
 
587
QColor QgsSingleSymbolDialog::getFillColor()
 
588
{
 
589
  return btnFillColor->color();
 
590
}
 
591
 
 
592
Qt::BrushStyle QgsSingleSymbolDialog::getFillStyle()
 
593
{
 
594
  QString myFillStyle =
 
595
    cboFillStyle->itemData( cboFillStyle->currentIndex(), Qt::UserRole ).toString();
 
596
  return QgsSymbologyUtils::qString2BrushStyle( myFillStyle );
 
597
}
 
598
 
 
599
void QgsSingleSymbolDialog::resendSettingsChanged()
 
600
{
 
601
  emit settingsChanged();
 
602
}
 
603
 
 
604
QString QgsSingleSymbolDialog::label()
 
605
{
 
606
  return mLabelEdit->text();
 
607
}
 
608
 
 
609
void QgsSingleSymbolDialog::setLabel( QString label )
 
610
{
 
611
  mLabelEdit->setText( label );
 
612
}
 
613
 
 
614
void QgsSingleSymbolDialog::symbolChanged
 
615
( QListWidgetItem * current, QListWidgetItem * previous )
 
616
{
 
617
  current->setBackground( QBrush( Qt::cyan ) );
 
618
  if ( previous )
 
619
  {
 
620
    previous->setBackground( QBrush( Qt::white ) );
 
621
  }
 
622
  emit settingsChanged();
 
623
}
 
624
 
 
625
void QgsSingleSymbolDialog::fillStyleChanged( int theIndex )
 
626
{
 
627
  //if the new style is texture we need to enable the texture
 
628
  //selection button, otherwise disable it
 
629
  QString myFillStyle =
 
630
    cboFillStyle->itemData( theIndex, Qt::UserRole ).toString();
 
631
  if ( "TexturePattern" == myFillStyle )
 
632
  {
 
633
    toolSelectTexture->setEnabled( true );
 
634
  }
 
635
  else
 
636
  {
 
637
    toolSelectTexture->setEnabled( false );
 
638
  }
 
639
 
 
640
}
 
641
 
 
642
void QgsSingleSymbolDialog::keyPressEvent( QKeyEvent * e )
 
643
{
 
644
  // Ignore the ESC key to avoid close the dialog without the properties window
 
645
  if ( e->key() == Qt::Key_Escape )
 
646
  {
 
647
    e->ignore();
 
648
  }
 
649
}