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