QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
qgsstylev2managerdialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsstylev2managerdialog.cpp
3  ---------------------
4  begin : November 2009
5  copyright : (C) 2009 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
17 
18 #include "qgsstylev2.h"
19 #include "qgssymbolv2.h"
20 #include "qgssymbollayerv2utils.h"
21 #include "qgsvectorcolorrampv2.h"
22 
30 
31 #include <QFile>
32 #include <QFileDialog>
33 #include <QInputDialog>
34 #include <QMessageBox>
35 #include <QSettings>
36 #include <QStandardItemModel>
37 #include <QAction>
38 #include <QMenu>
39 
40 #include "qgsapplication.h"
41 #include "qgslogger.h"
42 
44  : QDialog( parent ), mStyle( style ), mModified( false )
45 {
46  setupUi( this );
47 #ifdef Q_OS_MAC
48  setWindowModality( Qt::WindowModal );
49 #endif
50 
51  QSettings settings;
52  restoreGeometry( settings.value( "/Windows/StyleV2Manager/geometry" ).toByteArray() );
53  mSplitter->setSizes( QList<int>() << 170 << 540 );
54  mSplitter->restoreState( settings.value( "/Windows/StyleV2Manager/splitter" ).toByteArray() );
55 
56  tabItemType->setDocumentMode( true );
57  searchBox->setPlaceholderText( tr( "Type here to filter symbols..." ) );
58 
59  connect( this, SIGNAL( finished( int ) ), this, SLOT( onFinished() ) );
60 
61  connect( listItems, SIGNAL( doubleClicked( const QModelIndex & ) ), this, SLOT( editItem() ) );
62 
63  connect( btnAddItem, SIGNAL( clicked() ), this, SLOT( addItem() ) );
64  connect( btnEditItem, SIGNAL( clicked() ), this, SLOT( editItem() ) );
65  connect( btnRemoveItem, SIGNAL( clicked() ), this, SLOT( removeItem() ) );
66 
67  QMenu *shareMenu = new QMenu( tr( "Share Menu" ), this );
68  QAction *exportAsPNGAction = shareMenu->addAction( tr( "Export as PNG" ) );
69  QAction *exportAsSVGAction = shareMenu->addAction( tr( "Export as SVG" ) );
70  QAction *exportAction = shareMenu->addAction( tr( "Export" ) );
71  QAction *importAction = shareMenu->addAction( tr( "Import" ) );
72  exportAsPNGAction->setIcon( QIcon( QgsApplication::iconPath( "mActionSharingExport.svg" ) ) );
73  exportAsSVGAction->setIcon( QIcon( QgsApplication::iconPath( "mActionSharingExport.svg" ) ) );
74  exportAction->setIcon( QIcon( QgsApplication::iconPath( "mActionSharingExport.svg" ) ) );
75  importAction->setIcon( QIcon( QgsApplication::iconPath( "mActionSharingImport.svg" ) ) );
76  connect( exportAsPNGAction, SIGNAL( triggered() ), this, SLOT( exportItemsPNG() ) );
77  connect( exportAsSVGAction, SIGNAL( triggered() ), this, SLOT( exportItemsSVG() ) );
78  connect( exportAction, SIGNAL( triggered() ), this, SLOT( exportItems() ) );
79  connect( importAction, SIGNAL( triggered() ), this, SLOT( importItems() ) );
80  btnShare->setMenu( shareMenu );
81 
82  // Set editing mode off by default
83  mGrouppingMode = false;
84 
85  QStandardItemModel* model = new QStandardItemModel( listItems );
86  listItems->setModel( model );
87  listItems->setSelectionMode( QAbstractItemView::ExtendedSelection );
88 
89  connect( model, SIGNAL( itemChanged( QStandardItem* ) ), this, SLOT( itemChanged( QStandardItem* ) ) );
90  connect( listItems->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ),
91  this, SLOT( symbolSelected( const QModelIndex& ) ) );
92 
93  populateTypes();
94 
95  QStandardItemModel* groupModel = new QStandardItemModel( groupTree );
96  groupTree->setModel( groupModel );
97  groupTree->setHeaderHidden( true );
99  connect( groupTree->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ),
100  this, SLOT( groupChanged( const QModelIndex& ) ) );
101  connect( groupModel, SIGNAL( itemChanged( QStandardItem* ) ),
102  this, SLOT( groupRenamed( QStandardItem* ) ) );
103 
104  QMenu *groupMenu = new QMenu( tr( "Group Actions" ), this );
105  QAction *groupSymbols = groupMenu->addAction( tr( "Group Symbols" ) );
106  QAction *editSmartgroup = groupMenu->addAction( tr( "Edit Smart Group" ) );
107  btnManageGroups->setMenu( groupMenu );
108  connect( groupSymbols, SIGNAL( triggered() ), this, SLOT( groupSymbolsAction() ) );
109  connect( editSmartgroup, SIGNAL( triggered() ), this, SLOT( editSmartgroupAction() ) );
110 
111  connect( btnAddGroup, SIGNAL( clicked() ), this, SLOT( addGroup() ) );
112  connect( btnRemoveGroup, SIGNAL( clicked() ), this, SLOT( removeGroup() ) );
113 
115 
116  connect( searchBox, SIGNAL( textChanged( QString ) ), this, SLOT( filterSymbols( QString ) ) );
117  tagsLineEdit->installEventFilter( this );
118 
119  // Context menu for groupTree
120  groupTree->setContextMenuPolicy( Qt::CustomContextMenu );
121  connect( groupTree, SIGNAL( customContextMenuRequested( const QPoint& ) ),
122  this, SLOT( grouptreeContextMenu( const QPoint& ) ) );
123 
124  // Context menu for listItems
125  listItems->setContextMenuPolicy( Qt::CustomContextMenu );
126  connect( listItems, SIGNAL( customContextMenuRequested( const QPoint& ) ),
127  this, SLOT( listitemsContextMenu( const QPoint& ) ) );
128 
129 }
130 
132 {
133  if ( mModified )
134  {
135  mStyle->save();
136  }
137 
138  QSettings settings;
139  settings.setValue( "/Windows/StyleV2Manager/geometry", saveGeometry() );
140  settings.setValue( "/Windows/StyleV2Manager/splitter", mSplitter->saveState() );
141 }
142 
144 {
145 #if 0
146  // save current selection index in types combo
147  int current = ( tabItemType->count() > 0 ? tabItemType->currentIndex() : 0 );
148 
149 // no counting of style items
150  int markerCount = 0, lineCount = 0, fillCount = 0;
151 
152  QStringList symbolNames = mStyle->symbolNames();
153  for ( int i = 0; i < symbolNames.count(); ++i )
154  {
155  switch ( mStyle->symbolRef( symbolNames[i] )->type() )
156  {
157  case QgsSymbolV2::Marker:
158  markerCount++;
159  break;
160  case QgsSymbolV2::Line:
161  lineCount++;
162  break;
163  case QgsSymbolV2::Fill:
164  fillCount++;
165  break;
166  default: Q_ASSERT( 0 && "unknown symbol type" );
167  break;
168  }
169  }
170 
171  cboItemType->clear();
172  cboItemType->addItem( tr( "Marker symbol (%1)" ).arg( markerCount ), QVariant( QgsSymbolV2::Marker ) );
173  cboItemType->addItem( tr( "Line symbol (%1)" ).arg( lineCount ), QVariant( QgsSymbolV2::Line ) );
174  cboItemType->addItem( tr( "Fill symbol (%1)" ).arg( fillCount ), QVariant( QgsSymbolV2::Fill ) );
175 
176  cboItemType->addItem( tr( "Color ramp (%1)" ).arg( mStyle->colorRampCount() ), QVariant( 3 ) );
177 
178  // update current index to previous selection
179  cboItemType->setCurrentIndex( current );
180 #endif
181 }
182 
184 {
185  // when in Color Ramp tab, add menu to add item button
186  if ( currentItemType() == 3 )
187  {
188  QStringList rampTypes;
189  rampTypes << tr( "Gradient" ) << tr( "Random" ) << tr( "ColorBrewer" );
190  rampTypes << tr( "cpt-city" ); // todo, only for rasters?
191  QMenu* menu = new QMenu( btnAddItem );
192  foreach ( QString rampType, rampTypes )
193  {
194  menu->addAction( rampType );
195  }
196  btnAddItem->setMenu( menu );
197  connect( menu, SIGNAL( triggered( QAction* ) ),
198  this, SLOT( addColorRamp( QAction* ) ) );
199  }
200  else
201  {
202  if ( btnAddItem->menu() )
203  {
204  disconnect( btnAddItem->menu(), SIGNAL( triggered( QAction* ) ),
205  this, SLOT( addColorRamp( QAction* ) ) );
206  btnAddItem->setMenu( 0 );
207  }
208  }
209 
210  // set icon and grid size, depending on type
211  if ( currentItemType() == 1 || currentItemType() == 3 )
212  {
213  listItems->setIconSize( QSize( 75, 50 ) );
214  listItems->setGridSize( QSize( 100, 80 ) );
215  }
216  else
217  {
218  listItems->setIconSize( QSize( 50, 50 ) );
219  listItems->setGridSize( QSize( 75, 80 ) );
220  }
221 
222  populateList();
223 }
224 
226 {
227  if ( currentItemType() > 3 )
228  {
229  Q_ASSERT( 0 && "not implemented" );
230  return;
231  }
232  groupChanged( groupTree->selectionModel()->currentIndex() );
233 }
234 
236 {
237  QStandardItemModel* model = qobject_cast<QStandardItemModel*>( listItems->model() );
238  model->clear();
239 
240  int type = currentItemType();
241 
242  for ( int i = 0; i < symbolNames.count(); ++i )
243  {
244  QString name = symbolNames[i];
245  QgsSymbolV2* symbol = mStyle->symbol( name );
246  if ( symbol && symbol->type() == type )
247  {
248  QStandardItem* item = new QStandardItem( name );
249  QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( symbol, listItems->iconSize() );
250  item->setIcon( icon );
251  item->setData( name ); // used to find out original name when user edited the name
252  item->setCheckable( check );
253  item->setToolTip( name );
254  // add to model
255  model->appendRow( item );
256  }
257  delete symbol;
258  }
259 }
260 
261 
263 {
264  QStandardItemModel* model = qobject_cast<QStandardItemModel*>( listItems->model() );
265  model->clear();
266 
267  for ( int i = 0; i < colorRamps.count(); ++i )
268  {
269  QString name = colorRamps[i];
270  QgsVectorColorRampV2* ramp = mStyle->colorRamp( name );
271 
272  QStandardItem* item = new QStandardItem( name );
273  QIcon icon = QgsSymbolLayerV2Utils::colorRampPreviewIcon( ramp, listItems->iconSize() );
274  item->setIcon( icon );
275  item->setData( name ); // used to find out original name when user edited the name
276  item->setCheckable( check );
277  item->setToolTip( name );
278  model->appendRow( item );
279  delete ramp;
280  }
281 }
282 
284 {
285  switch ( tabItemType->currentIndex() )
286  {
287  case 0: return QgsSymbolV2::Marker;
288  case 1: return QgsSymbolV2::Line;
289  case 2: return QgsSymbolV2::Fill;
290  case 3: return 3;
291  default: return 0;
292  }
293 }
294 
296 {
297  QModelIndex index = listItems->selectionModel()->currentIndex();
298  if ( !index.isValid() )
299  return QString();
300  return index.model()->data( index, 0 ).toString();
301 }
302 
304 {
305  bool changed = false;
306  if ( currentItemType() < 3 )
307  {
308  changed = addSymbol();
309  }
310  else if ( currentItemType() == 3 )
311  {
312  changed = addColorRamp();
313  }
314  else
315  {
316  Q_ASSERT( 0 && "not implemented" );
317  }
318 
319  if ( changed )
320  {
321  populateList();
322  populateTypes();
323  }
324 }
325 
327 {
328  // create new symbol with current type
329  QgsSymbolV2* symbol;
330  QString name = tr( "new symbol" );
331  switch ( currentItemType() )
332  {
333  case QgsSymbolV2::Marker:
334  symbol = new QgsMarkerSymbolV2();
335  name = tr( "new marker" );
336  break;
337  case QgsSymbolV2::Line:
338  symbol = new QgsLineSymbolV2();
339  name = tr( "new line" );
340  break;
341  case QgsSymbolV2::Fill:
342  symbol = new QgsFillSymbolV2();
343  name = tr( "new fill symbol" );
344  break;
345  default:
346  Q_ASSERT( 0 && "unknown symbol type" );
347  return false;
348  }
349 
350  // get symbol design
351  // NOTE : Set the parent widget as "this" to notify the Symbol selector
352  // that, it is being called by Style Manager, so recursive calling
353  // of style manager and symbol selector can be arrested
354  // See also: editSymbol()
355  QgsSymbolV2SelectorDialog dlg( symbol, mStyle, NULL, this );
356  if ( dlg.exec() == 0 )
357  {
358  delete symbol;
359  return false;
360  }
361 
362  // get unique name
363  bool nameInvalid = true;
364 
365  while ( nameInvalid )
366  {
367  bool ok;
368  name = QInputDialog::getText( this, tr( "Symbol Name" ),
369  tr( "Please enter a name for new symbol:" ),
370  QLineEdit::Normal, name, &ok );
371  if ( !ok )
372  {
373  delete symbol;
374  return false;
375  }
376  // validate name
377  if ( name.isEmpty() )
378  {
379  QMessageBox::warning( this, tr( "Save symbol" ),
380  tr( "Cannot save symbol without name. Enter a name." ) );
381  }
382  else if ( mStyle->symbolNames().contains( name ) )
383  {
384  int res = QMessageBox::warning( this, tr( "Save symbol" ),
385  tr( "Symbol with name '%1' already exists. Overwrite?" )
386  .arg( name ),
387  QMessageBox::Yes | QMessageBox::No );
388  if ( res == QMessageBox::Yes )
389  {
390  nameInvalid = false;
391  }
392  }
393  else
394  {
395  // valid name
396  nameInvalid = false;
397  }
398  }
399 
400  // add new symbol to style and re-populate the list
401  mStyle->addSymbol( name, symbol, true );
402  // TODO groups and tags
403  mModified = true;
404  return true;
405 }
406 
407 
409 {
410  // let the user choose the color ramp type if rampType is not given
411  bool ok = true;
412  if ( rampType.isEmpty() )
413  {
414  QStringList rampTypes;
415  rampTypes << tr( "Gradient" ) << tr( "Random" ) << tr( "ColorBrewer" );
416  rampTypes << tr( "cpt-city" ); // todo, only for rasters?
417  rampType = QInputDialog::getItem( parent, tr( "Color ramp type" ),
418  tr( "Please select color ramp type:" ), rampTypes, 0, false, &ok );
419  }
420  if ( !ok || rampType.isEmpty() )
421  return QString();
422 
423  QString name = tr( "new ramp" );
424 
425  QgsVectorColorRampV2 *ramp = NULL;
426  if ( rampType == tr( "Gradient" ) )
427  {
429  QgsVectorGradientColorRampV2Dialog dlg( gradRamp, parent );
430  if ( !dlg.exec() )
431  {
432  delete gradRamp;
433  return QString();
434  }
435  ramp = gradRamp;
436  name = tr( "new gradient ramp" );
437  }
438  else if ( rampType == tr( "Random" ) )
439  {
441  QgsVectorRandomColorRampV2Dialog dlg( randRamp, parent );
442  if ( !dlg.exec() )
443  {
444  delete randRamp;
445  return QString();
446  }
447  ramp = randRamp;
448  name = tr( "new random ramp" );
449  }
450  else if ( rampType == tr( "ColorBrewer" ) )
451  {
453  QgsVectorColorBrewerColorRampV2Dialog dlg( brewerRamp, parent );
454  if ( !dlg.exec() )
455  {
456  delete brewerRamp;
457  return QString();
458  }
459  ramp = brewerRamp;
460  name = brewerRamp->schemeName() + QString::number( brewerRamp->colors() );
461  }
462  else if ( rampType == tr( "cpt-city" ) )
463  {
464  QgsCptCityColorRampV2* cptCityRamp = new QgsCptCityColorRampV2( "", "" );
465  QgsCptCityColorRampV2Dialog dlg( cptCityRamp, parent );
466  if ( !dlg.exec() )
467  {
468  delete cptCityRamp;
469  return QString();
470  }
471  // name = dlg.selectedName();
472  name = QFileInfo( cptCityRamp->schemeName() ).baseName() + cptCityRamp->variantName();
473  if ( dlg.saveAsGradientRamp() )
474  {
475  ramp = cptCityRamp->cloneGradientRamp();
476  delete cptCityRamp;
477  }
478  else
479  {
480  ramp = cptCityRamp;
481  }
482  }
483  else
484  {
485  // Q_ASSERT( 0 && "invalid ramp type" );
486  // bailing out is rather harsh!
487  QgsDebugMsg( "invalid ramp type " + rampType );
488  return QString();
489  }
490 
491  // get unique name
492  bool nameInvalid = true;
493 
494  while ( nameInvalid )
495  {
496  bool ok;
497  name = QInputDialog::getText( parent, tr( "Color Ramp Name" ),
498  tr( "Please enter a name for new color ramp:" ),
499  QLineEdit::Normal, name, &ok );
500  if ( !ok )
501  {
502  delete ramp;
503  return QString();
504  }
505  // validate name
506  if ( name.isEmpty() )
507  {
508  QMessageBox::warning( parent, tr( "Save Color Ramp" ),
509  tr( "Cannot save color ramp without name. Enter a name." ) );
510  }
511  else if ( style->colorRampNames().contains( name ) )
512  {
513  int res = QMessageBox::warning( parent, tr( "Save color ramp" ),
514  tr( "Color ramp with name '%1' already exists. Overwrite?" )
515  .arg( name ),
516  QMessageBox::Yes | QMessageBox::No );
517  if ( res == QMessageBox::Yes )
518  {
519  nameInvalid = false;
520  }
521  }
522  else
523  {
524  // valid name
525  nameInvalid = false;
526  }
527  }
528 
529  // add new symbol to style and re-populate the list
530  style->addColorRamp( name, ramp, true );
531  // TODO groups and tags, using saveColorRamp
532  return name;
533 }
534 
535 
537 {
538  return addColorRamp( 0 );
539 }
540 
542 {
543  // pass the action text, which is the color ramp type
544  QString rampName = addColorRampStatic( this, mStyle,
545  action ? action->text() : QString() );
546  if ( !rampName.isEmpty() )
547  {
548  mModified = true;
549  populateList();
550  return true;
551  }
552 
553  return false;
554 }
555 
557 {
558  bool changed = false;
559  if ( currentItemType() < 3 )
560  {
561  changed = editSymbol();
562  }
563  else if ( currentItemType() == 3 )
564  {
565  changed = editColorRamp();
566  }
567  else
568  {
569  Q_ASSERT( 0 && "not implemented" );
570  }
571 
572  if ( changed )
573  populateList();
574 }
575 
577 {
578  QString symbolName = currentItemName();
579  if ( symbolName.isEmpty() )
580  return false;
581 
582  QgsSymbolV2* symbol = mStyle->symbol( symbolName );
583 
584  // let the user edit the symbol and update list when done
585  QgsSymbolV2SelectorDialog dlg( symbol, mStyle, NULL, this );
586  if ( dlg.exec() == 0 )
587  {
588  delete symbol;
589  return false;
590  }
591 
592  // by adding symbol to style with the same name the old effectively gets overwritten
593  mStyle->addSymbol( symbolName, symbol, true );
594  mModified = true;
595  return true;
596 }
597 
599 {
601  if ( name.isEmpty() )
602  return false;
603 
604  QgsVectorColorRampV2* ramp = mStyle->colorRamp( name );
605 
606  if ( ramp->type() == "gradient" )
607  {
608  QgsVectorGradientColorRampV2* gradRamp = static_cast<QgsVectorGradientColorRampV2*>( ramp );
609  QgsVectorGradientColorRampV2Dialog dlg( gradRamp, this );
610  if ( !dlg.exec() )
611  {
612  delete ramp;
613  return false;
614  }
615  }
616  else if ( ramp->type() == "random" )
617  {
618  QgsVectorRandomColorRampV2* randRamp = static_cast<QgsVectorRandomColorRampV2*>( ramp );
619  QgsVectorRandomColorRampV2Dialog dlg( randRamp, this );
620  if ( !dlg.exec() )
621  {
622  delete ramp;
623  return false;
624  }
625  }
626  else if ( ramp->type() == "colorbrewer" )
627  {
628  QgsVectorColorBrewerColorRampV2* brewerRamp = static_cast<QgsVectorColorBrewerColorRampV2*>( ramp );
629  QgsVectorColorBrewerColorRampV2Dialog dlg( brewerRamp, this );
630  if ( !dlg.exec() )
631  {
632  delete ramp;
633  return false;
634  }
635  }
636  else if ( ramp->type() == "cpt-city" )
637  {
638  QgsCptCityColorRampV2* cptCityRamp = static_cast<QgsCptCityColorRampV2*>( ramp );
639  QgsCptCityColorRampV2Dialog dlg( cptCityRamp, this );
640  if ( !dlg.exec() )
641  {
642  delete ramp;
643  return false;
644  }
645  if ( dlg.saveAsGradientRamp() )
646  {
647  ramp = cptCityRamp->cloneGradientRamp();
648  delete cptCityRamp;
649  }
650  }
651  else
652  {
653  Q_ASSERT( 0 && "invalid ramp type" );
654  }
655 
656  mStyle->addColorRamp( name, ramp, true );
657  mModified = true;
658  return true;
659 }
660 
661 
663 {
664  bool changed = false;
665  if ( currentItemType() < 3 )
666  {
667  changed = removeSymbol();
668  }
669  else if ( currentItemType() == 3 )
670  {
671  changed = removeColorRamp();
672  }
673  else
674  {
675  Q_ASSERT( 0 && "not implemented" );
676  }
677 
678  if ( changed )
679  {
680  populateList();
681  populateTypes();
682  }
683 }
684 
686 {
687  QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
688  foreach ( QModelIndex index, indexes )
689  {
690  QString symbolName = index.data().toString();
691  // delete from style and update list
692  if ( !symbolName.isEmpty() )
693  mStyle->removeSymbol( symbolName );
694  }
695  mModified = true;
696  return true;
697 }
698 
700 {
701  QString rampName = currentItemName();
702  if ( rampName.isEmpty() )
703  return false;
704 
705  mStyle->removeColorRamp( rampName );
706  mModified = true;
707  return true;
708 }
709 
711 {
712  // an item has been edited
713  QString oldName = item->data().toString();
714 
715  bool changed = false;
716  if ( currentItemType() < 3 )
717  {
718  changed = mStyle->renameSymbol( oldName, item->text() );
719  }
720  else if ( currentItemType() == 3 )
721  {
722  changed = mStyle->renameColorRamp( oldName, item->text() );
723  }
724 
725  if ( changed )
726  {
727  populateList();
728  mModified = true;
729  }
730  else
731  {
732  QMessageBox::critical( this, tr( "Cannot rename item" ),
733  tr( "Name is already taken by another item. Choose a different name." ) );
734  item->setText( oldName );
735  }
736 }
737 
739 {
740  QString dir = QFileDialog::getExistingDirectory( this, tr( "Exported selected symbols as PNG" ),
741  QDir::home().absolutePath(),
742  QFileDialog::ShowDirsOnly
743  | QFileDialog::DontResolveSymlinks );
744  exportSelectedItemsImages( dir, "png", QSize( 32, 32 ) );
745 }
746 
748 {
749  QString dir = QFileDialog::getExistingDirectory( this, tr( "Exported selected symbols as SVG" ),
750  QDir::home().absolutePath(),
751  QFileDialog::ShowDirsOnly
752  | QFileDialog::DontResolveSymlinks );
753  exportSelectedItemsImages( dir, "svg", QSize( 32, 32 ) );
754 }
755 
756 
758 {
759  if ( dir.isEmpty() )
760  return;
761 
762  QModelIndexList indexes = listItems->selectionModel()->selection().indexes();
763  foreach ( QModelIndex index, indexes )
764  {
765  QString name = index.data().toString();
766  QString path = dir + "/" + name + "." + format;
767  QgsSymbolV2 *sym = mStyle->symbol( name );
768  sym->exportImage( path, format, size );
769  }
770 }
771 
773 {
775  dlg.exec();
776 }
777 
779 {
781  dlg.exec();
782  populateList();
783  populateGroups();
784 }
785 
787 {
788  QFont font = item->font();
789  font.setBold( true );
790  item->setFont( font );
791 }
792 
794 {
795  QStandardItemModel *model = qobject_cast<QStandardItemModel*>( groupTree->model() );
796  model->clear();
797 
798  QStandardItem *allSymbols = new QStandardItem( tr( "All Symbols" ) );
799  allSymbols->setData( "all" );
800  allSymbols->setEditable( false );
801  setBold( allSymbols );
802  model->appendRow( allSymbols );
803 
804  QStandardItem *group = new QStandardItem( "" ); //require empty name to get first order groups
805  group->setData( "groups" );
806  group->setEditable( false );
807  buildGroupTree( group );
808  group->setText( tr( "Groups" ) );//set title later
809  QStandardItem *ungrouped = new QStandardItem( tr( "Ungrouped" ) );
810  ungrouped->setData( 0 );
811  setBold( ungrouped );
812  setBold( group );
813  group->appendRow( ungrouped );
814  model->appendRow( group );
815 
816  QStandardItem *tag = new QStandardItem( tr( "Smart Groups" ) );
817  tag->setData( "smartgroups" );
818  tag->setEditable( false );
819  setBold( tag );
822  while ( i != sgMap.constEnd() )
823  {
824  QStandardItem *item = new QStandardItem( i.value() );
825  item->setData( i.key() );
826  tag->appendRow( item );
827  ++i;
828  }
829  model->appendRow( tag );
830 
831  // expand things in the grouo tree
832  int rows = model->rowCount( model->indexFromItem( model->invisibleRootItem() ) );
833  for ( int i = 0; i < rows; i++ )
834  {
835  groupTree->setExpanded( model->indexFromItem( model->item( i ) ), true );
836  }
837 }
838 
840 {
841  QgsSymbolGroupMap groups = mStyle->childGroupNames( parent->text() );
843  while ( i != groups.constEnd() )
844  {
845  QStandardItem *item = new QStandardItem( i.value() );
846  item->setData( i.key() );
847  parent->appendRow( item );
848  buildGroupTree( item );
849  ++i;
850  }
851 }
852 
854 {
855  QStringList symbolNames;
856  QStringList groupSymbols;
857 
859  if ( currentItemType() > 3 )
860  {
861  QgsDebugMsg( "Entity not implemented" );
862  return;
863  }
864 
865  QString category = index.data( Qt::UserRole + 1 ).toString();
866  if ( category == "all" || category == "groups" || category == "smartgroups" )
867  {
868  enableGroupInputs( false );
869  if ( category == "groups" || category == "smartgroups" )
870  {
871  btnAddGroup->setEnabled( true );
872  }
873  symbolNames = currentItemType() < 3 ? mStyle->symbolNames() : mStyle->colorRampNames();
874  }
875  else
876  {
877  //determine groups and tags
878  if ( index.parent().data( Qt::UserRole + 1 ) == "smartgroups" )
879  {
880  btnAddGroup->setEnabled( false );
881  btnRemoveGroup->setEnabled( true );
882  btnManageGroups->setEnabled( true );
883  int groupId = index.data( Qt::UserRole + 1 ).toInt();
884  symbolNames = mStyle->symbolsOfSmartgroup( type, groupId );
885  }
886  else // then it must be a group
887  {
888  if (( !index.data( Qt::UserRole + 1 ).toInt() && ( index.data() == "Ungrouped" ) ) || mGrouppingMode )
889  enableGroupInputs( false );
890  else
891  enableGroupInputs( true );
892  int groupId = index.data( Qt::UserRole + 1 ).toInt();
893  symbolNames = mStyle->symbolsOfGroup( type, groupId );
894  if ( mGrouppingMode && groupId )
895  {
896  groupSymbols = symbolNames;
897  symbolNames += mStyle->symbolsOfGroup( type, 0 );
898  }
899  }
900  }
901 
902  if ( currentItemType() < 3 )
903  {
904  populateSymbols( symbolNames, mGrouppingMode );
905  }
906  else if ( currentItemType() == 3 )
907  {
908  populateColorRamps( symbolNames, mGrouppingMode );
909  }
910  if ( mGrouppingMode )
911  setSymbolsChecked( groupSymbols );
912 }
913 
915 {
916  QStandardItemModel *model = qobject_cast<QStandardItemModel*>( groupTree->model() );
917  QModelIndex parentIndex = groupTree->currentIndex();
918 
919  // Violation 1: Creating sub-groups of system defined groups
920  QString parentData = parentIndex.data( Qt::UserRole + 1 ).toString();
921  if ( parentData == "all" || ( parentIndex.data() == "Ungrouped" && parentData == "0" ) )
922  {
923  int err = QMessageBox::critical( this, tr( "Invalid Selection" ),
924  tr( "The parent group you have selected is not user editable.\n"
925  "Kindly select a user defined group." ) );
926  if ( err )
927  return;
928  }
929 
930  // Violation 2: Creating a nested tag
931  if ( parentIndex.parent().data( Qt::UserRole + 1 ).toString() == "smartgroups" )
932  {
933  int err = QMessageBox::critical( this, tr( "Operation Not Allowed" ),
934  tr( "Creation of nested smart groups are not allowed\n"
935  "Select the 'Smart Group' to create a new group." ) );
936  if ( err )
937  return;
938  }
939 
940  QString itemName;
941  QVariant itemData;
942  bool isGroup = true;
943 
944  // create a smart group if that is selected
945  if ( parentIndex.data( Qt::UserRole + 1 ).toString() == "smartgroups" )
946  {
947  QgsSmartGroupEditorDialog dlg( mStyle, this );
948  if ( dlg.exec() == QDialog::Rejected )
949  return;
950  int id = mStyle->addSmartgroup( dlg.smartgroupName(), dlg.conditionOperator(), dlg.conditionMap() );
951  if ( !id )
952  return;
953  itemData = QVariant( id );
954  itemName = dlg.smartgroupName();
955  isGroup = false;
956  }
957  else
958  {
959  itemName = QString( tr( "New Group" ) );
960  itemData = QVariant( "newgroup" );
961  }
962 
963  // Else create a simple child-group to the selected
964  QStandardItem *parentItem = model->itemFromIndex( parentIndex );
965  QStandardItem *childItem = new QStandardItem( itemName );
966  childItem->setData( itemData );
967  parentItem->appendRow( childItem );
968 
969  groupTree->setCurrentIndex( childItem->index() );
970  if ( isGroup )
971  {
972  groupTree->edit( childItem->index() );
973  }
974 }
975 
977 {
978  QStandardItemModel *model = qobject_cast<QStandardItemModel*>( groupTree->model() );
979  QModelIndex index = groupTree->currentIndex();
980 
981  // Violation: removing system groups
982  QString data = index.data( Qt::UserRole + 1 ).toString();
983  if ( data == "all" || data == "groups" || data == "smartgroups" || index.data() == "Ungrouped" )
984  {
985  int err = QMessageBox::critical( this, tr( "Invalid selection" ),
986  tr( "Cannot delete system defined categories.\n"
987  "Kindly select a group or smart group you might want to delete." ) );
988  if ( err )
989  return;
990  }
991 
992  QStandardItem *parentItem = model->itemFromIndex( index.parent() );
993  if ( parentItem->data( Qt::UserRole + 1 ).toString() == "smartgroups" )
994  {
995  mStyle->remove( QgsStyleV2::SmartgroupEntity, index.data( Qt::UserRole + 1 ).toInt() );
996  }
997  else
998  {
999  mStyle->remove( QgsStyleV2::GroupEntity, index.data( Qt::UserRole + 1 ).toInt() );
1000  QStandardItem *item = model->itemFromIndex( index );
1001  if ( item->hasChildren() )
1002  {
1003  QStandardItem *parent = item->parent();
1004  for ( int i = 0; i < item->rowCount(); i++ )
1005  {
1006  parent->appendRow( item->takeChild( i ) );
1007  }
1008  }
1009  }
1010  parentItem->removeRow( index.row() );
1011 }
1012 
1014 {
1015  QString data = item->data( Qt::UserRole + 1 ).toString();
1016  QgsDebugMsg( "Symbol group edited: data=" + data + " text=" + item->text() );
1017  if ( data == "newgroup" )
1018  {
1019  int id;
1020  if ( item->parent()->data( Qt::UserRole + 1 ).toString() == "groups" )
1021  {
1022  id = mStyle->addGroup( item->text() );
1023  }
1024  else
1025  {
1026  int parentid = item->parent()->data( Qt::UserRole + 1 ).toInt();
1027  id = mStyle->addGroup( item->text(), parentid );
1028  }
1029  if ( !id )
1030  {
1031  QMessageBox::critical( this, tr( "Error!" ),
1032  tr( "New group could not be created.\n"
1033  "There was a problem with your symbol database." ) );
1034  item->parent()->removeRow( item->row() );
1035  return;
1036  }
1037  else
1038  {
1039  item->setData( id );
1040  }
1041  }
1042  else
1043  {
1044  int id = item->data( Qt::UserRole + 1 ).toInt();
1045  QString name = item->text();
1046  if ( item->parent()->data( Qt::UserRole + 1 ) == "smartgroups" )
1047  {
1049  }
1050  else
1051  {
1052  mStyle->rename( QgsStyleV2::GroupEntity, id, name );
1053  }
1054  }
1055 }
1056 
1058 {
1059 
1060  QStandardItemModel *treeModel = qobject_cast<QStandardItemModel*>( groupTree->model() );
1061  QStandardItemModel *model = qobject_cast<QStandardItemModel*>( listItems->model() );
1062  QAction *senderAction = qobject_cast<QAction*>( sender() );
1063 
1064  if ( mGrouppingMode )
1065  {
1066  mGrouppingMode = false;
1067  senderAction->setText( tr( "Group Symbols" ) );
1068  // disconnect slot which handles regrouping
1069  disconnect( model, SIGNAL( itemChanged( QStandardItem* ) ),
1070  this, SLOT( regrouped( QStandardItem* ) ) );
1071 
1072  // disabel all items except groups in groupTree
1074  groupChanged( groupTree->currentIndex() );
1075 
1076  // Finally: Reconnect all Symbol editing functionalities
1077  connect( treeModel, SIGNAL( itemChanged( QStandardItem* ) ),
1078  this, SLOT( groupRenamed( QStandardItem* ) ) );
1079  connect( model, SIGNAL( itemChanged( QStandardItem* ) ),
1080  this, SLOT( itemChanged( QStandardItem* ) ) );
1081  // Reset the selection mode
1082  listItems->setSelectionMode( QAbstractItemView::ExtendedSelection );
1083  }
1084  else
1085  {
1086  bool validGroup = false;
1087  // determine whether it is a valid group
1088  QModelIndex present = groupTree->currentIndex();
1089  while ( present.parent().isValid() )
1090  {
1091  if ( present.parent().data() == "Groups" )
1092  {
1093  validGroup = true;
1094  break;
1095  }
1096  else
1097  present = present.parent();
1098  }
1099  if ( !validGroup )
1100  return;
1101 
1102  mGrouppingMode = true;
1103  // Change the text menu
1104  senderAction->setText( tr( "Finish Grouping" ) );
1105  // Remove all Symbol editing functionalities
1106  disconnect( treeModel, SIGNAL( itemChanged( QStandardItem* ) ),
1107  this, SLOT( groupRenamed( QStandardItem* ) ) );
1108  disconnect( model, SIGNAL( itemChanged( QStandardItem* ) ),
1109  this, SLOT( itemChanged( QStandardItem* ) ) );
1110 
1111  // disabel all items except groups in groupTree
1112  enableItemsForGroupingMode( false );
1113  groupChanged( groupTree->currentIndex() );
1114  btnManageGroups->setEnabled( true );
1115 
1116 
1117  // Connect to slot which handles regrouping
1118  connect( model, SIGNAL( itemChanged( QStandardItem* ) ),
1119  this, SLOT( regrouped( QStandardItem* ) ) );
1120 
1121  // No selection should be possible
1122  listItems->setSelectionMode( QAbstractItemView::NoSelection );
1123  }
1124 }
1125 
1127 {
1129  if ( currentItemType() > 3 )
1130  {
1131  QgsDebugMsg( "Unknown style entity" );
1132  return;
1133  }
1134  int groupid = groupTree->currentIndex().data( Qt::UserRole + 1 ).toInt();
1135  QString symbolName = item->text();
1136  bool regrouped;
1137  if ( item->checkState() == Qt::Checked )
1138  regrouped = mStyle->group( type, symbolName, groupid );
1139  else
1140  regrouped = mStyle->group( type, symbolName, 0 );
1141  if ( !regrouped )
1142  {
1143  int er = QMessageBox::critical( this, tr( "Database Error" ),
1144  tr( "There was a problem with the Symbols database while regrouping." ) );
1145  // call the slot again to get back to normal
1146  if ( er )
1148  }
1149 }
1150 
1152 {
1153  QStandardItemModel *model = qobject_cast<QStandardItemModel*>( listItems->model() );
1154  foreach ( const QString symbol, symbols )
1155  {
1156  QList<QStandardItem*> items = model->findItems( symbol );
1157  foreach ( QStandardItem* item, items )
1158  item->setCheckState( Qt::Checked );
1159  }
1160 }
1161 
1163 {
1164  QStringList items;
1165  if ( currentItemType() == 3 )
1166  {
1167  items = mStyle->findSymbols( QgsStyleV2::ColorrampEntity, qword );
1168  populateColorRamps( items );
1169  }
1170  else
1171  {
1172  items = mStyle->findSymbols( QgsStyleV2::SymbolEntity, qword );
1173  populateSymbols( items );
1174  }
1175 }
1176 
1178 {
1179  QModelIndexList indexes = listItems->selectionModel()->selection().indexes();
1180  QStringList addtags;
1181  QStringList removetags;
1182 
1183  QStringList oldtags = mTagList;
1184  QStringList newtags = tagsLineEdit->text().split( ",", QString::SkipEmptyParts );
1185 
1187  if ( currentItemType() < 3 )
1188  {
1189  type = QgsStyleV2::SymbolEntity;
1190  }
1191  else if ( currentItemType() == 3 )
1192  {
1194  }
1195  else
1196  {
1197  QgsDebugMsg( "Unknown Style Entity!" );
1198  return;
1199  }
1200  // compare old with new to find removed tags
1201  foreach ( const QString &tag, oldtags )
1202  {
1203  if ( !newtags.contains( tag ) )
1204  removetags.append( tag );
1205  }
1206  if ( removetags.size() > 0 )
1207  {
1208  foreach ( QModelIndex index, indexes )
1209  {
1210  mStyle->detagSymbol( type, index.data().toString(), removetags );
1211  }
1212  }
1213  // compare new with old to find added tags
1214  foreach ( const QString &tag, newtags )
1215  {
1216  if ( !oldtags.contains( tag ) )
1217  addtags.append( tag );
1218  }
1219  if ( addtags.size() > 0 )
1220  {
1221  foreach ( QModelIndex index, indexes )
1222  {
1223  mStyle->tagSymbol( type, index.data().toString(), addtags );
1224  }
1225  }
1226 }
1227 
1229 {
1230  // Populate the tags for the symbol
1231  tagsLineEdit->clear();
1232  QStandardItem *item = static_cast<QStandardItemModel*>( listItems->model() )->itemFromIndex( index );
1234  mTagList = mStyle->tagsOfSymbol( type, item->data().toString() );
1235  tagsLineEdit->setText( mTagList.join( "," ) );
1236 }
1237 
1239 {
1240  groupTree->setEnabled( enable );
1241  btnAddGroup->setEnabled( enable );
1242  btnRemoveGroup->setEnabled( enable );
1243  btnManageGroups->setEnabled( enable );
1244  searchBox->setEnabled( enable );
1245  tagsLineEdit->setEnabled( enable );
1246 }
1247 
1249 {
1250  btnAddGroup->setEnabled( enable );
1251  btnRemoveGroup->setEnabled( enable );
1252  btnManageGroups->setEnabled( enable );
1253 }
1254 
1256 {
1257  QStandardItemModel *treeModel = qobject_cast<QStandardItemModel*>( groupTree->model() );
1258  for ( int i = 0; i < treeModel->rowCount(); i++ )
1259  {
1260  if ( treeModel->item( i )->data() != "groups" )
1261  {
1262  treeModel->item( i )->setEnabled( enable );
1263  }
1264  if ( treeModel->item( i )->data() == "groups" )
1265  {
1266  treeModel->item( i )->setEnabled( enable );
1267  for ( int k = 0; k < treeModel->item( i )->rowCount(); k++ )
1268  {
1269  if ( !treeModel->item( i )->child( k )->data().toInt() )
1270  treeModel->item( i )->child( k )->setEnabled( enable );
1271  }
1272  }
1273  if ( treeModel->item( i )->data() == "smartgroups" )
1274  {
1275  for ( int j = 0; j < treeModel->item( i )->rowCount(); j++ )
1276  {
1277  treeModel->item( i )->child( j )->setEnabled( enable );
1278  }
1279  }
1280  }
1281 
1282  // The buttons
1283  // NOTE: if you ever change the layout name in the .ui file edit here too
1284  for ( int i = 0; i < symbolBtnsLayout->count(); i++ )
1285  {
1286  QWidget *w = qobject_cast<QWidget*>( symbolBtnsLayout->itemAt( i )->widget() );
1287  if ( w )
1288  w->setEnabled( enable );
1289  }
1290 
1291 }
1292 
1294 {
1295  QPoint globalPos = groupTree->viewport()->mapToGlobal( point );
1296 
1297  QModelIndex index = groupTree->indexAt( point );
1298  QgsDebugMsg( "Now you clicked: " + index.data().toString() );
1299 
1300  QMenu groupMenu;
1301 
1302  if ( index.parent().isValid() && ( index.data().toString() != "Ungrouped" ) )
1303  {
1304  if ( index.parent().data( Qt::UserRole + 1 ).toString() == "smartgroups" )
1305  {
1306  groupMenu.addAction( tr( "Edit Group" ) );
1307  }
1308  else
1309  {
1310  groupMenu.addAction( tr( "Add Group" ) );
1311  }
1312  groupMenu.addAction( tr( "Remove Group" ) );
1313  }
1314  else if ( index.data( Qt::UserRole + 1 ) == "groups" || index.data( Qt::UserRole + 1 ) == "smartgroups" )
1315  {
1316  groupMenu.addAction( tr( "Add Group" ) );
1317  }
1318 
1319 
1320  QAction* selectedItem = groupMenu.exec( globalPos );
1321 
1322  if ( selectedItem )
1323  {
1324  if ( selectedItem->text() == tr( "Add Group" ) )
1325  addGroup();
1326  else if ( selectedItem->text() == tr( "Remove Group" ) )
1327  removeGroup();
1328  else if ( selectedItem->text() == tr( "Edit Group" ) )
1330  }
1331 }
1332 
1334 {
1335  QPoint globalPos = listItems->viewport()->mapToGlobal( point );
1336 
1337  QMenu *groupMenu = new QMenu( this );
1338  QMenu *groupList = new QMenu( this );
1339  groupList->setTitle( tr( "Apply Group" ) );
1340 
1341  QStringList groups = mStyle->groupNames();
1342  foreach ( QString group, groups )
1343  {
1344  groupList->addAction( group );
1345  }
1346  groupMenu->addMenu( groupList );
1347  groupMenu->addAction( tr( "Un-group" ) );
1348 
1349  QAction* selectedItem = groupMenu->exec( globalPos );
1350 
1351  if ( selectedItem )
1352  {
1354  if ( currentItemType() > 3 )
1355  {
1356  QgsDebugMsg( "unknow entity type" );
1357  return;
1358  }
1359  int groupId = 0;
1360  if ( selectedItem->text() != tr( "Un-group" ) )
1361  {
1362  groupId = mStyle->groupId( selectedItem->text() );
1363  }
1364  QModelIndexList indexes = listItems->selectionModel()->selectedIndexes();
1365  foreach ( QModelIndex index, indexes )
1366  {
1367  mStyle->group( type, index.data().toString(), groupId );
1368  }
1369  populateList();
1370 
1371  QgsDebugMsg( "Selected Action: " + selectedItem->text() );
1372  }
1373 }
1374 
1376 {
1377  QStandardItemModel *treeModel = qobject_cast<QStandardItemModel*>( groupTree->model() );
1378 
1379  // determine whether it is a valid group
1380  QModelIndex present = groupTree->currentIndex();
1381  if ( present.parent().data( Qt::UserRole + 1 ) != "smartgroups" )
1382  {
1383  QMessageBox::critical( this, tr( "Invalid Selection" ),
1384  tr( "You have not selected a Smart Group. Kindly select a Smart Group to edit." ) );
1385  return;
1386  }
1387  QStandardItem* item = treeModel->itemFromIndex( present );
1388 
1389  QgsSmartGroupEditorDialog dlg( mStyle, this );
1390  QgsSmartConditionMap map = mStyle->smartgroup( present.data( Qt::UserRole + 1 ).toInt() );
1391  dlg.setSmartgroupName( item->text() );
1392  dlg.setOperator( mStyle->smartgroupOperator( item->data().toInt() ) );
1393  dlg.setConditionMap( map );
1394 
1395  if ( dlg.exec() == QDialog::Rejected )
1396  return;
1397 
1399  int id = mStyle->addSmartgroup( dlg.smartgroupName(), dlg.conditionOperator(), dlg.conditionMap() );
1400  if ( !id )
1401  {
1402  QMessageBox::critical( this, tr( "Database Error!" ),
1403  tr( "There was some error while editing the smart group." ) );
1404  return;
1405  }
1406  item->setText( dlg.smartgroupName() );
1407  item->setData( id );
1408 
1409  groupChanged( present );
1410 }
1411 
1413 {
1414 
1415  if (( obj == tagsLineEdit ) && ( event->type() == QEvent::FocusOut ) )
1416  {
1417  tagsChanged();
1418  return true;
1419  }
1420  return false;
1421 }
1422 
void customContextMenuRequested(const QPoint &pos)
QString smartgroupOperator(int id)
returns the operator for the smartgroup
void setToolTip(const QString &toolTip)
QByteArray toByteArray() const
static unsigned index
void remove(StyleEntity type, int id)
remove the specified entity from the db
Definition: qgsstylev2.cpp:691
QString getExistingDirectory(QWidget *parent, const QString &caption, const QString &dir, QFlags< QFileDialog::Option > options)
Type type() const
QStringList tagsOfSymbol(StyleEntity type, QString symbol)
return the tags associated with the symbol
Definition: qgsstylev2.cpp:895
void setupUi(QWidget *widget)
void setIcon(const QIcon &icon)
int addSmartgroup(QString name, QString op, QgsSmartConditionMap conditions)
adds new smartgroup to the database and returns the id
Definition: qgsstylev2.cpp:977
static QIcon colorRampPreviewIcon(QgsVectorColorRampV2 *ramp, QSize size)
virtual QString type() const =0
void filterSymbols(QString)
filter the symbols based on input search term
QString getItem(QWidget *parent, const QString &title, const QString &label, const QStringList &items, int current, bool editable, bool *ok, QFlags< Qt::WindowType > flags, QFlags< Qt::InputMethodHint > inputMethodHints)
QStandardItem * invisibleRootItem() const
SymbolType type() const
Definition: qgssymbolv2.h:86
QgsSmartConditionMap conditionMap()
returns the condition map
void setWindowModality(Qt::WindowModality windowModality)
void itemChanged(QStandardItem *item)
void groupChanged(const QModelIndex &)
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
bool group(StyleEntity type, QString name, int groupid)
applies the specified group to the symbol or colorramp specified by StyleEntity
Definition: qgsstylev2.cpp:743
static QString iconPath(QString iconFile)
Returns path to the desired icon file.
void enableItemsForGroupingMode(bool)
Enables or diables the groupTree items for grouping mode.
void setSymbolsChecked(QStringList)
to set symbols checked when in editing mode
QObject * sender() const
void exportSelectedItemsImages(QString dir, QString format, QSize size)
void tagsChanged()
Listen to tag changes.
const_iterator constBegin() const
void setIcon(const QIcon &icon)
QStringList symbolsOfGroup(StyleEntity type, int groupid)
returns the symbolnames of a given groupid
Definition: qgsstylev2.cpp:527
void addAction(QAction *action)
bool contains(const QString &str, Qt::CaseSensitivity cs) const
void populateSymbols(QStringList symbolNames, bool checkable=false)
populate list view with symbols of the current type with the given names
void removeRow(int row)
QgsStyleV2ManagerDialog(QgsStyleV2 *style, QWidget *parent=NULL)
int exec()
QgsSymbolV2 * symbol(QString name)
return a NEW copy of symbol
Definition: qgsstylev2.cpp:166
const QPixmap * icon() const
void rename(StyleEntity type, int id, QString newName)
rename the given entity with the specified id
Definition: qgsstylev2.cpp:645
QString join(const QString &separator) const
QString smartgroupName()
returns the value from mNameLineEdit
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QStringList colorRampNames()
return a list of names of color ramps
Definition: qgsstylev2.cpp:276
QString tr(const char *sourceText, const char *disambiguation, int n)
QString text() const
bool renameSymbol(QString oldName, QString newName)
change symbol's name
Definition: qgsstylev2.cpp:406
Qt::CheckState checkState() const
int size() const
virtual void setData(const QVariant &value, int role)
QgsSymbolGroupMap childGroupNames(QString parent="")
return a map of groupid and names for the given parent group
Definition: qgsstylev2.cpp:480
bool addSymbol(QString name, QgsSymbolV2 *symbol, bool update=false)
add symbol to style. takes symbol's ownership
Definition: qgsstylev2.cpp:83
void finished(int result)
bool save(QString filename=QString())
save style into a file (will use current filename if empty string is passed)
Definition: qgsstylev2.cpp:360
void setBold(bool enable)
void setValue(const QString &key, const QVariant &value)
const char * name() const
bool isValid() const
void setConditionMap(QgsSmartConditionMap)
sets up the GUI for the given conditionmap
QString variantName() const
void setEnabled(bool)
QString number(int n, int base)
static QIcon symbolPreviewIcon(QgsSymbolV2 *symbol, QSize size)
int count(const T &value) const
bool addSymbol()
add a new symbol to style
void append(const T &value)
const QgsSymbolV2 * symbolRef(QString name) const
return a const pointer to a symbol (doesn't create new instance)
Definition: qgsstylev2.cpp:172
int toInt(bool *ok) const
int colorRampCount()
return count of color ramps
Definition: qgsstylev2.cpp:271
QModelIndex indexFromItem(const QStandardItem *item) const
const Key & key() const
bool restoreGeometry(const QByteArray &geometry)
void populateGroups()
populate the groups
void appendRow(const QList< QStandardItem * > &items)
bool hasChildren() const
QStringList mTagList
space to store symbol tags
bool isEmpty() const
QStandardItem * parent() const
const_iterator constEnd() const
bool renameColorRamp(QString oldName, QString newName)
change ramp's name
Definition: qgsstylev2.cpp:438
void groupRenamed(QStandardItem *)
QList< QStandardItem * > findItems(const QString &text, QFlags< Qt::MatchFlag > flags, int column) const
const T & value() const
void buildGroupTree(QStandardItem *&parent)
build the groups tree
QStringList symbolsOfSmartgroup(StyleEntity type, int id)
returns the symbols for the smartgroup
virtual QVariant data(const QModelIndex &index, int role) const =0
void setTitle(const QString &title)
void grouptreeContextMenu(const QPoint &)
Context menu for the groupTree.
void setOperator(QString)
sets the operator AND/OR
void populateTypes()
populate combo box with known style items (symbols, color ramps)
QModelIndex parent() const
QStringList symbolNames()
return a list of names of symbols
Definition: qgsstylev2.cpp:182
QAction * exec()
QgsSymbolGroupMap smartgroupsListMap()
returns the smart groups map with id as key and name as value
QStandardItem * child(int row, int column) const
void setFont(const QFont &font)
QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode, const QString &text, bool *ok, QFlags< Qt::WindowType > flags, QFlags< Qt::InputMethodHint > inputMethodHints)
void setEnabled(bool enabled)
QStandardItem * item(int row, int column) const
void setSmartgroupName(QString)
sets the smart group Name
const QFont & font() const
void exportImage(QString path, QString format, QSize size)
export symbol as image format. PNG and SVG supported
bool eventFilter(QObject *, QEvent *) override
Event filter to capture tagsLineEdit out of focus.
bool mGrouppingMode
Mode to display the symbol list.
void setBold(QStandardItem *)
sets the text of the item with bold font
QgsVectorGradientColorRampV2 * cloneGradientRamp() const
void setText(const QString &text)
QFont font() const
QVariant value(const QString &key, const QVariant &defaultValue) const
void symbolSelected(const QModelIndex &)
Perform symbol specific tasks when selected.
const QAbstractItemModel * model() const
void groupSymbolsAction()
carryout symbol grouping using check boxes
QVariant data(int role) const
QByteArray saveGeometry() const
bool detagSymbol(StyleEntity type, QString symbol, QStringList tags)
detags the symbol with the given list
Definition: qgsstylev2.cpp:842
QStandardItem * itemFromIndex(const QModelIndex &index) const
bool removeSymbol(QString name)
remove symbol from style (and delete it)
Definition: qgsstylev2.cpp:138
QAction * addMenu(QMenu *menu)
bool addColorRamp(QString name, QgsVectorColorRampV2 *colorRamp, bool update=false)
add color ramp to style. takes ramp's ownership
Definition: qgsstylev2.cpp:188
void listitemsContextMenu(const QPoint &)
Context menu for the listItems ( symbols list )
StandardButton critical(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
virtual int rowCount(const QModelIndex &parent) const
QStringList split(const QString &sep, const QString &str, bool allowEmptyEntries)
QModelIndex index() const
int rowCount() const
bool tagSymbol(StyleEntity type, QString symbol, QStringList tags)
tags the symbol with the tags in the list
Definition: qgsstylev2.cpp:790
bool removeColorRamp(QString name)
remove color ramp from style (and delete it)
Definition: qgsstylev2.cpp:242
StandardButton warning(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
void editSmartgroupAction()
edit the selected smart group
void populateColorRamps(QStringList colorRamps, bool checkable=false)
populate list view with color ramps
int addGroup(QString groupName, int parent=0)
adds a new group and returns the group's id
Definition: qgsstylev2.cpp:613
static QString addColorRampStatic(QWidget *parent, QgsStyleV2 *style, QString RampType=QString())
open add color ramp dialog, return color ramp's name if the ramp has been added
void setCheckState(Qt::CheckState state)
void enableGroupInputs(bool)
Enables or disables the groupTree specific inputs.
void enableSymbolInputs(bool)
Enables or disbables the symbol specific inputs.
QgsVectorColorRampV2 * colorRamp(QString name)
return a NEW copy of color ramp
Definition: qgsstylev2.cpp:260
void onFinished()
called when the dialog is going to be closed
QStandardItem * takeChild(int row, int column)
StyleEntity
Enum for Entities involved in a style.
Definition: qgsstylev2.h:80
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const
QStringList findSymbols(StyleEntity type, QString qword)
return the names of the symbols which have a matching 'substring' in its defintion ...
Definition: qgsstylev2.cpp:764
QChar * data()
bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
Definition: qgslayertree.h:34
QString toString() const
QDir home()
void setCheckable(bool checkable)
int row() const
void appendRow(const QList< QStandardItem * > &items)
virtual QVariant data(int role) const
void setEditable(bool editable)
void regrouped(QStandardItem *)
symbol changed from one group
QStringList groupNames()
return the all the groups in the style
Definition: qgsstylev2.cpp:466
QgsSmartConditionMap smartgroup(int id)
returns the QgsSmartConditionMap for the given id
QString conditionOperator()
returns the AND/OR condition
bool addColorRamp()
add a new color ramp to style
int groupId(QString group)
return the DB id for the given group name
Definition: qgsstylev2.cpp:962
void populateList()
adds symbols of some type to list