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