QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscptcitycolorrampv2dialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscptcitycolorrampv2dialog.cpp
3  ---------------------
4  begin : July 2012
5  copyright : (C) 2012 by Etienne Tourigny
6  email : etourigny dot dev at gmail.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 "qgscptcityarchive.h"
19 #include "qgsvectorcolorrampv2.h"
20 #include "qgslogger.h"
21 #include "qgsapplication.h"
22 #include "qgsdialog.h"
23 
24 #include <QPushButton>
25 #include <QTextEdit>
26 #include <QTime>
27 #include <QMessageBox>
28 #include <QSortFilterProxyModel>
29 
31 
32 // TODO
33 // - fix Diverging children when first show Selections
34 // - fix crash on Diverging?
35 
36 class TreeFilterProxyModel : public QSortFilterProxyModel
37 {
38  // Q_OBJECT
39 
40  public:
41  TreeFilterProxyModel( QObject *parent, QgsCptCityBrowserModel* model )
42  : QSortFilterProxyModel( parent ), mModel( model )
43  { setSourceModel( mModel ); }
44 
45  protected:
46  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
47  {
48  QgsCptCityDataItem* item = mModel->dataItem( mModel->index( sourceRow, 0, sourceParent ) );
49  return ( item && !( item->type() == QgsCptCityDataItem::ColorRamp ) );
50  }
51  // bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
52 
53  private:
55 };
56 
57 
58 // ----------------------
59 
61  : QDialog( parent ), mRamp( 0 )
62 {
63  setupUi( this );
64 
65  buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
66 
67  QSettings settings;
68  restoreGeometry( settings.value( "/Windows/CptCityColorRampV2Dialog/geometry" ).toByteArray() );
69  mSplitter->setSizes( QList<int>() << 250 << 550 );
70  mSplitter->restoreState( settings.value( "/Windows/CptCityColorRampV2Dialog/splitter" ).toByteArray() );
71 
72  mModel = mAuthorsModel = mSelectionsModel = 0; //mListModel = 0;
73  mTreeFilter = 0;
74 
77 
78  // show information on how to install cpt-city files if none are found
79  if ( ! mArchive || mArchive->isEmpty() )
80  {
81  // QgsDialog dlg( this );
82  // dlg.setWindowTitle( tr( "cpt-city gradient files not found" ) );
83  QTextEdit *edit = new QTextEdit( 0 );
84  edit->setReadOnly( true );
85  // not sure if we want this long string to be translated
86  QString helpText = tr( "Error - cpt-city gradient files not found.\n\n"
87  "You have two means of installing them:\n\n"
88  "1) Install the \"Color Ramp Manager\" python plugin "
89  "(you must enable Experimental plugins in the plugin manager) "
90  "and use it to download latest cpt-city package.\n"
91  "You can install the entire cpt-city archive or a selection for QGIS.\n\n"
92  "2) Download the complete archive (in svg format) "
93  "and unzip it to your QGIS settings directory [%1] .\n\n"
94  "This file can be found at [%2]\nand current file is [%3]"
96  ).arg( "http://soliton.vm.bytemark.co.uk/pub/cpt-city/pkg/"
97  ).arg( "http://soliton.vm.bytemark.co.uk/pub/cpt-city/pkg/cpt-city-svg-2.07.zip" );
98  edit->setText( helpText );
99  mStackedWidget->addWidget( edit );
100  mStackedWidget->setCurrentIndex( 1 );
101  tabBar->setVisible( false );
102  // dlg.layout()->addWidget( edit );
103  // dlg.resize(500,400);
104  // dlg.exec();
105  return;
106  }
107 
108  if ( ! mArchive )
109  return;
110  QgsDebugMsg( "archive: " + mArchive->archiveName() );
111 
112  if ( ramp )
113  {
114  mRamp = ramp;
115  }
116  else
117  {
118  mRamp = new QgsCptCityColorRampV2( "", "", false );
119  ramp = mRamp;
120  }
121  QgsDebugMsg( QString( "ramp name= %1 variant= %2 - %3 variants" ).arg( ramp->schemeName() ).arg( ramp->variantName() ).arg( ramp->variantList().count() ) );
122 
123  // model / view
124  QgsDebugMsg( "loading model/view objects" );
125  if ( mAuthorsModel )
126  delete mAuthorsModel;
128  if ( mSelectionsModel )
129  delete mSelectionsModel;
132 
133  mTreeView->setSelectionMode( QAbstractItemView::SingleSelection );
134  mTreeView->setColumnHidden( 1, true );
135  QgsDebugMsg( "done loading model/view objects" );
136 
137  // setup ui
138  tabBar->blockSignals( true );
139  tabBar->addTab( tr( "Selections by theme" ) );
140  tabBar->addTab( tr( "All by author" ) );
141  cboVariantName->setIconSize( QSize( 100, 15 ) );
142  lblPreview->installEventFilter( this ); // mouse click on preview label shows svg render
143 
144  // look for item, if not found in selections archive, look for in authors
145  QgsDebugMsg( "looking for ramp " + mRamp->schemeName() );
146  if ( mRamp->schemeName() != "" )
147  {
148  bool found = updateRamp();
149  if ( ! found )
150  {
151  tabBar->setCurrentIndex( 1 );
153  found = updateRamp();
154  // if not found, go back to selections model
155  if ( ! found )
156  {
157  tabBar->setCurrentIndex( 0 );
159  }
160  }
161  if ( found )
162  buttonBox->button( QDialogButtonBox::Ok )->setEnabled( true );
163  }
164  else
165  {
166  updateRamp();
167  }
168 
169  tabBar->blockSignals( false );
170 
171  connect( this, SIGNAL( finished( int ) ), this, SLOT( onFinished() ) );
172 
173 }
174 
176 {
177 }
178 
180 {
181  QStringList variantList = mRamp->variantList();
182 
183  QgsDebugMsg( QString( "ramp %1%2 has %3 variants" ).arg( mRamp->schemeName() ).arg( mRamp->variantName() ).arg( variantList.count() ) );
184 
185  cboVariantName->blockSignals( true );
186  cboVariantName->clear();
187 
188  if ( variantList.isEmpty() )
189  {
190  cboVariantName->setEnabled( false );
191  cboVariantName->setVisible( false );
193  }
194  else
195  {
196  // populate variant combobox
197  QString oldVariant = cboVariantName->currentText();
198  QgsCptCityColorRampV2 ramp( mRamp->schemeName(), mRamp->variantList(), QString() );
199  QPixmap blankPixmap( cboVariantName->iconSize() );
200  blankPixmap.fill( Qt::white );
201  QIcon blankIcon( blankPixmap );
202  int index;
203 
204  foreach ( QString variant, variantList )
205  {
206  QString variantStr = variant;
207  if ( variantStr.startsWith( "-" ) || variantStr.startsWith( "_" ) )
208  variantStr.remove( 0, 1 );
209  cboVariantName->addItem( " " + variantStr );
210  index = cboVariantName->count() - 1;
211  cboVariantName->setItemData( index, variant, Qt::UserRole );
212 
213  ramp.setVariantName( variant );
214  if ( ramp.loadFile() )
215  cboVariantName->setItemIcon( index,
216  QgsSymbolLayerV2Utils::colorRampPreviewIcon( &ramp, cboVariantName->iconSize() ) );
217  else
218  cboVariantName->setItemIcon( index, blankIcon );
219  cboVariantName->setItemData( index, Qt::AlignHCenter, Qt::TextAlignmentRole );
220  }
221 
222  cboVariantName->blockSignals( false );
223 
224  // try to set the original variant again (if exists)
225  int idx = -1;
226  QString newVariant = mRamp->variantName();
227  QgsDebugMsg( QString( "variant= %1 - %2 variants" ).arg( mRamp->variantName() ).arg( mRamp->variantList().count() ) );
228  if ( newVariant != QString() )
229  {
230  if ( newVariant.startsWith( "-" ) || newVariant.startsWith( "_" ) )
231  newVariant.remove( 0, 1 );
232  newVariant = " " + newVariant;
233  idx = cboVariantName->findText( newVariant );
234  }
235  else
236  idx = cboVariantName->findText( oldVariant );
237 
238  // if not found use the item in the middle
239  if ( idx == -1 )
240  {
241  idx = cboVariantName->count() / 2;
242  }
243  cboVariantName->setCurrentIndex( idx );
244  // updatePreview();
245 
246  cboVariantName->setEnabled( true );
247  cboVariantName->setVisible( true );
248  }
249 
250 }
251 
253 {
254  const QModelIndex &sourceIndex = mTreeFilter->mapToSource( index );
255  QgsCptCityDataItem *item = mModel->dataItem( sourceIndex );
256  if ( ! item )
257  return;
258  QgsDebugMsg( QString( "item %1 clicked" ).arg( item->name() ) );
259  buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
260  updateTreeView( item );
261 }
262 
264 {
265  if ( ! item )
266  {
267  QgsDebugMsg( "invalid item" );
268  return;
269  }
270  if ( item->type() == QgsCptCityDataItem::Directory )
271  {
272  if ( resetRamp )
273  {
274  mRamp->setName( "", "" );
275  QgsDebugMsg( QString( "variant= %1 - %2 variants" ).arg( mRamp->variantName() ).arg( mRamp->variantList().count() ) );
276  lblSchemeName->setText( "" );
278  }
279  updateListWidget( item );
280  lblSchemePath->setText( item->path() );
281  lblCollectionInfo->setText( QString( "%1 (%2)" ).arg( item->info() ).arg( item->leafCount() ) );
283  }
284  else if ( item->type() == QgsCptCityDataItem::Selection )
285  {
286  lblSchemePath->setText( "" );
287  clearCopyingInfo( );
288  updateListWidget( item );
289  lblCollectionInfo->setText( QString( "%1 (%2)" ).arg( item->info() ).arg( item->leafCount() ) );
290  }
291  else if ( item->type() == QgsCptCityDataItem::AllRamps )
292  {
293  lblSchemePath->setText( "" );
294  clearCopyingInfo( );
295  updateListWidget( item );
296  lblCollectionInfo->setText( tr( "All Ramps (%1)" ).arg( item->leafCount() ) );
297  }
298  else
299  {
300  QgsDebugMsg( QString( "item %1 has invalid type %2" ).arg( item->path() ).arg(( int )item->type() ) );
301  }
302 }
303 
305 {
306  QgsCptCityColorRampItem *rampItem = mListRamps.at( item->data( Qt::UserRole ).toInt() );
307  if ( rampItem )
308  {
309  buttonBox->button( QDialogButtonBox::Ok )->setEnabled( true );
310  lblSchemeName->setText( QFileInfo( rampItem->name() ).fileName() );
311  mRamp->copy( &rampItem->ramp() );
312  QgsDebugMsg( QString( "variant= %1 - %2 variants" ).arg( mRamp->variantName() ).arg( mRamp->variantList().count() ) );
314  }
315  else
316  {
317  QgsDebugMsg( QString( "item %1 has invalid type %2" ).arg( rampItem->path() ).arg(( int )rampItem->type() ) );
318  }
319 }
320 
322 {
323  if ( mListWidget->selectedItems().count() == 0 )
324  {
325  mRamp->setName( "", "" );
326  }
327 }
328 
330 {
331  QgsDebugMsg( "Entered" );
332  if ( index == 0 )
333  {
336  }
337  else if ( index == 1 )
338  {
341  }
342  else
343  {
344  QgsDebugMsg( QString( "invalid index %1" ).arg( index ) );
347  }
348 
349  mListWidget->blockSignals( true );
350  updateRamp();
351  mListWidget->blockSignals( false );
352 }
353 
354 
356 {
357  QString path, title, copyFile, descFile;
358 
359  // get basic information, depending on if is color ramp or directory
360  QgsCptCityDataItem *item =
361  dynamic_cast< QgsCptCityDataItem* >( mModel->dataItem( mTreeFilter->mapToSource( mTreeView->currentIndex() ) ) );
362  if ( ! item )
363  return;
364 
365  path = item->path();
366  if ( item->type() == QgsCptCityDataItem::Directory )
367  {
368  title = tr( "%1 directory details" ).arg( item->path() );
369  }
370  else if ( item->type() == QgsCptCityColorRampItem::Directory )
371  {
372  title = tr( "%1 gradient details" ).arg( path );
373  }
374  else
375  {
376  return;
377  }
378  copyFile = mArchive->copyingFileName( path );
379  descFile = mArchive->descFileName( path );
380 
381  // prepare dialog
382  QgsDialog dlg( this, 0, QDialogButtonBox::Close );
383  QVBoxLayout *layout = dlg.layout();
384  dlg.setWindowTitle( title );
385  QTextEdit *textEdit = new QTextEdit( &dlg );
386  textEdit->setReadOnly( true );
387  layout->addWidget( textEdit );
388 
389  // add contents of DESC.xml and COPYING.xml
390  QString copyText;
391  if ( ! copyFile.isNull() )
392  {
393  QFile file( copyFile );
394  if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) )
395  {
396  copyText = QString( file.readAll() );
397  file.close();
398  }
399  }
400  QString descText;
401  if ( ! descFile.isNull() )
402  {
403  QFile file( descFile );
404  if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) )
405  {
406  descText = QString( file.readAll() );
407  file.close();
408  }
409  }
410  textEdit->insertPlainText( title + "\n\n" );
411  textEdit->insertPlainText( "===================" );
412  textEdit->insertPlainText( " copying " );
413  textEdit->insertPlainText( "===================\n" );
414  textEdit->insertPlainText( copyText );
415  textEdit->insertPlainText( "\n" );
416  textEdit->insertPlainText( "==================" );
417  textEdit->insertPlainText( " description " );
418  textEdit->insertPlainText( "==================\n" );
419  textEdit->insertPlainText( descText );
420  textEdit->moveCursor( QTextCursor::Start );
421 
422  dlg.resize( 600, 600 );
423  dlg.exec();
424 }
425 
427 {
428  QSize size = lblPreview->size();
429 
430  if ( clear || mRamp->schemeName() == "" )
431  {
432  lblSchemeName->setText( "" );
433  lblSchemePath->setText( "" );
434  lblLicensePreview->setText( "" );
435  QPixmap blankPixmap( size );
436  blankPixmap.fill( Qt::transparent );
437  lblPreview->setPixmap( blankPixmap );
438  return;
439  }
440 
441  mRamp->loadFile();
442 
443  lblSchemePath->setText( mRamp->schemeName() + mRamp->variantName() );
444 
445  // update pixmap
446  // TODO draw checker-board/transparent background
447  // for transparent, add [ pixmap.fill( Qt::transparent ); ] to QgsSymbolLayerV2Utils::colorRampPreviewPixmap
448  QPixmap pixmap = QgsSymbolLayerV2Utils::colorRampPreviewPixmap( mRamp, size );
449  lblPreview->setPixmap( pixmap );
450 
451  // add copyright information from COPYING.xml file
453 }
454 
456 {
457  updateCopyingInfo( QMap< QString, QString >() );
458 }
459 
460 void QgsCptCityColorRampV2Dialog::updateCopyingInfo( const QMap< QString, QString >& copyingMap )
461 {
462  QString authorStr = copyingMap.value( "authors" );
463  if ( authorStr.length() > 80 )
464  authorStr.replace( authorStr.indexOf( " ", 80 ), 1, "\n" );
465  lblAuthorName->setText( authorStr );
466  QString licenseStr = copyingMap.value( "license/informal" );
467  if ( copyingMap.contains( "license/year" ) )
468  licenseStr += " (" + copyingMap.value( "license/year" ) + ")";
469  if ( licenseStr.length() > 80 )
470  licenseStr.replace( licenseStr.indexOf( " ", 80 ), 1, "\n" );
471  if ( copyingMap.contains( "license/url" ) )
472  licenseStr += "\n[ " + copyingMap.value( "license/url" ) + " ]";
473  else
474  licenseStr += "\n";
475  lblLicenseName->setText( licenseStr );
476  licenseStr.replace( "\n", " " );
477  lblLicensePreview->setText( licenseStr );
478  lblLicensePreview->setCursorPosition( 0 );
479  if ( copyingMap.contains( "src/link" ) )
480  lblSrcLink->setText( copyingMap.value( "src/link" ) );
481  else
482  lblSrcLink->setText( "" );
483 }
484 
486 {
487  Q_UNUSED( index );
488  if ( cboVariantName->currentIndex() != -1 )
489  mRamp->setVariantName( cboVariantName->itemData( cboVariantName->currentIndex(), Qt::UserRole ).toString() );
490  QgsDebugMsg( QString( "variant= %1 - %2 variants" ).arg( mRamp->variantName() ).arg( mRamp->variantList().count() ) );
491  updatePreview();
492 }
493 
495 {
496  // save settings
497  QSettings settings;
498  settings.setValue( "/Windows/CptCityColorRampV2Dialog/geometry", saveGeometry() );
499  settings.setValue( "/Windows/CptCityColorRampV2Dialog/splitter", mSplitter->saveState() );
500 }
501 
503 {
504  // show error message to use color ramp manager to get more gradients
505  QString helpText = tr( "You can download a more complete set of cpt-city gradients "
506  "by installing the \"Color Ramp Manager\" plugin "
507  "(you must enable Experimental plugins in the plugin manager).\n\n"
508  );
509  QMessageBox* msg = new QMessageBox( this );
510  msg->setText( helpText );
511  msg->exec();
512 }
513 
515 {
516  QgsDebugMsg( QString( "result: %1 checked: %2" ).arg( result() ).arg( cboConvertStandard->isChecked() ) );
517  // if "save as standard gradient" is checked, convert to QgsVectorGradientColorRampV2
518  return ( result() == Accepted && cboConvertStandard->isChecked() );
519 }
520 
522 {
523  mListWidget->blockSignals( true );
524  mListWidget->clear();
525  mListRamps.clear();
526  QgsCptCityCollectionItem* colItem = dynamic_cast<QgsCptCityCollectionItem*>( item );
527  if ( colItem )
528  {
529  QgsDebugMsg( "path= " + item->path() );
530  // recursively get children ramps
531  QVector<QgsCptCityDataItem*> childrenRamps = colItem->childrenRamps( true );
532  for ( int i = 0; i < childrenRamps.count(); i++ )
533  {
534  QgsCptCityColorRampItem* rampItem = dynamic_cast<QgsCptCityColorRampItem*>( childrenRamps[i] );
535  if ( ! rampItem )
536  {
537  QgsDebugMsg( "invalid item " + childrenRamps[i]->path() );
538  continue;
539  }
540  QListWidgetItem* listItem = new QListWidgetItem();
541  listItem->setText( rampItem->shortInfo() );
542  listItem->setIcon( rampItem->icon( QSize( 75, 50 ) ) );
543  listItem->setToolTip( rampItem->path() + "\n" + rampItem->info() );
544  listItem->setData( Qt::UserRole, QVariant( i ) );
545  mListWidget->addItem( listItem );
546  mListRamps << rampItem;
547  }
548  }
549  else
550  {
551  QgsDebugMsg( "invalid item" );
552  }
553  mListWidget->blockSignals( false );
554 }
555 
556 // this function is for a svg preview, available if the svg files have been processed with svgx
557 // e.g. for f in `ls */*/*/*/*.svg`; do echo $f ; svgx -p -t svg $f > tmp1.svg; mv tmp1.svg $f; done
558 // perhaps a future version of the cpt-city svg gradients will have them by default
559 bool QgsCptCityColorRampV2Dialog::eventFilter( QObject *obj, QEvent *event )
560 {
561  QSize size = lblPreview->size();
562 
563  if ( event->type() == QEvent::MouseButtonPress )
564  {
565  // create preview from svg file if supported - depends on file versions
566  QPixmap pixmap( mRamp->fileName() );
567  if ( ! pixmap.isNull() )
568  lblPreview->setPixmap( pixmap.scaled( size ) );
569  return true;
570  }
571  else if ( event->type() == QEvent::MouseButtonRelease )
572  {
573  // restore preview
574  QPixmap pixmap = QgsSymbolLayerV2Utils::colorRampPreviewPixmap( mRamp, size );
575  lblPreview->setPixmap( pixmap );
576  return true;
577  }
578  else
579  {
580  // standard event processing
581  return QObject::eventFilter( obj, event );
582  }
583 }
584 
586 {
587  QgsDebugMsg( "Entered" );
588  mListWidget->clear();
589  mListRamps.clear();
590  cboVariantName->clear();
591  clearCopyingInfo( );
592  lblCollectionInfo->clear();
593 
594  buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
595  updatePreview( true );
596 
597  QgsDebugMsg( "schemeName= " + mRamp->schemeName() );
598  if ( mRamp->schemeName() == "" )
599  {
600  showAll();
601  return false;
602  }
603 
604  // search for item in model
605  QModelIndex modelIndex = mModel->findPath( mRamp->schemeName() );
606  if ( modelIndex == QModelIndex() )
607  {
608  return false;
609  }
610  QgsCptCityColorRampItem* childItem =
611  dynamic_cast<QgsCptCityColorRampItem*>( mModel->dataItem( modelIndex ) );
612  if ( ! childItem )
613  return false;
614  if ( mRamp->schemeName() != childItem->ramp().schemeName() )
615  return false;
616 
617  // found child, set mRamp variantList
618  // mRamp->copy( &childItem->ramp() );
619  mRamp->setVariantList( childItem->ramp().variantList() );
620 
621  // found child, update tree
622  QgsDebugMsg( QString( "found item %1" ).arg( mRamp->schemeName() ) );
623  lblSchemeName->setText( QFileInfo( mRamp->schemeName() ).fileName() );
624  QModelIndex parentIndex = modelIndex.parent();
625  QModelIndex selIndex = mTreeFilter->mapFromSource( parentIndex );
626 
627  // QgsDebugMsg(QString("parent row=%1 path=%2 parentRow=%3").arg(parentIndex.row()).arg(mModel->dataItem( parentIndex )->path()).arg(parentIndex.parent().row()));
628  mTreeView->setCurrentIndex( selIndex );
629  mTreeView->setExpanded( selIndex, true );
630  mTreeView->scrollTo( selIndex, QAbstractItemView::PositionAtCenter );
631  updateTreeView( mModel->dataItem( parentIndex ), false );
632 
633  // update listWidget, find appropriate item in mListRamps
634  for ( int i = 0; i < mListRamps.count(); i++ )
635  {
636  if ( mListRamps[i] == childItem )
637  {
638  QgsDebugMsg( QString( "found matching item %1 target=%2" ).arg( mListRamps[i]->path() ).arg( childItem->path() ) );
639  QListWidgetItem* listItem = mListWidget->item( i );
640  mListWidget->setCurrentItem( listItem );
641  // on_mListWidget_itemClicked( listItem );
643  mListWidget->scrollToItem( listItem, QAbstractItemView::EnsureVisible );
644  // mListView->selectionModel()->select( childIndex, QItemSelectionModel::Select );
645  buttonBox->button( QDialogButtonBox::Ok )->setEnabled( true );
646  return true;
647  }
648  }
649 
650  return false;
651 }
652 
654 {
655  QModelIndex modelIndex = mModel->findPath( "" );
656  if ( modelIndex != QModelIndex() )
657  {
658  QModelIndex selIndex = mTreeFilter->mapFromSource( modelIndex );
659  mTreeView->setCurrentIndex( selIndex );
660  mTreeView->setExpanded( selIndex, true );
661  mTreeView->scrollTo( selIndex, QAbstractItemView::PositionAtCenter );
662  updateTreeView( mModel->dataItem( modelIndex ), false );
663  }
664 }
665 
667 {
668  QgsDebugMsg( "Entered" );
669  mModel = model;
670 
671  if ( mTreeFilter )
672  delete mTreeFilter;
673  mTreeFilter = new TreeFilterProxyModel( this, mModel );
674  mTreeView->setModel( mTreeFilter );
675 }
676 
677 #if 0
678 void QgsCptCityColorRampV2Dialog::refresh()
679 {
680  QApplication::setOverrideCursor( Qt::WaitCursor );
681  refreshModel( QModelIndex() );
682  QApplication::restoreOverrideCursor();
683 }
684 
685 void QgsCptCityColorRampV2Dialog::refreshModel( const QModelIndex& index )
686 {
687  if ( index.isValid() )
688  {
689  QgsCptCityDataItem *item = mModel->dataItem( index );
690  if ( item )
691  {
692  QgsDebugMsg( "path = " + item->path() );
693  }
694  else
695  {
696  QgsDebugMsg( "invalid item" );
697  }
698  }
699 
700  mModel->refresh( index );
701 
702  for ( int i = 0 ; i < mModel->rowCount( index ); i++ )
703  {
704  QModelIndex idx = mModel->index( i, 0, index );
705  if ( mTreeView->isExpanded( idx ) || !mModel->hasChildren( idx ) )
706  {
707  refreshModel( idx );
708  }
709  }
710 }
711 #endif
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
static unsigned index
bool hasChildren(const QModelIndex &parent=QModelIndex()) const
void updateListWidget(QgsCptCityDataItem *item)
void setName(QString schemeName, QString variantName="", QStringList variantList=QStringList())
static QIcon colorRampPreviewIcon(QgsVectorColorRampV2 *ramp, QSize size)
static QPixmap colorRampPreviewPixmap(QgsVectorColorRampV2 *ramp, QSize size)
bool eventFilter(QObject *obj, QEvent *event)
static QgsCptCityArchive * defaultArchive()
QgsCptCityBrowserModel * mSelectionsModel
QgsCptCityBrowserModel * mModel
void copy(const QgsCptCityColorRampV2 *other)
#define QgsDebugMsg(str)
Definition: qgslogger.h:36
QString archiveName() const
A generic dialog with layout and button box.
Definition: qgsdialog.h:30
Item that represents a layer that can be opened with one of the providers.
QgsCptCityDataItem * dataItem(const QModelIndex &idx) const
Returns a list of mime that can describe model indexes.
QVector< QgsCptCityColorRampItem * > mListRamps
QgsCptCityBrowserModel * mAuthorsModel
static const QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
QgsCptCityBrowserModel::ViewType mArchiveViewType
TreeFilterProxyModel(QObject *parent, QgsCptCityBrowserModel *model)
void refresh(QString path)
QModelIndex findPath(QString path)
return index of a path
QString variantName() const
void updateTreeView(QgsCptCityDataItem *item, bool resetRamp=true)
QStringList variantList() const
QString copyingFileName(const QString &dirName) const
QgsCptCityColorRampV2Dialog(QgsCptCityColorRampV2 *ramp, QWidget *parent=NULL)
void setVariantName(QString variantName)
QgsStringMap copyingInfo() const
base class for all items in the model
static QMap< QString, QString > copyingInfo(const QString &fileName)
A Collection: logical collection of subcollections and color ramps.
QString descFileName(const QString &dirName) const
QString shortInfo() const
QString path() const
static void initDefaultArchive()
void on_mListWidget_itemClicked(QListWidgetItem *item)
void updateCopyingInfo(const QMap< QString, QString > &copyingMap)
QString file
Definition: qgssvgcache.cpp:76
virtual int leafCount() const
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Returns the index of the item in the model specified by the given row, column and parent index...
void setVariantList(QStringList variantList)
QVBoxLayout * layout()
Returns the central layout. Widgets added to it must have this dialog as parent.
Definition: qgsdialog.h:40
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Provides the number of rows of data exposed by the model.
QVector< QgsCptCityDataItem * > childrenRamps(bool recursive)
void on_mTreeView_clicked(const QModelIndex &)
double size
Definition: qgssvgcache.cpp:77
QString info() const
QString name() const
const QgsCptCityColorRampV2 & ramp() const
void setTreeModel(QgsCptCityBrowserModel *model)
#define tr(sourceText)