24 #include <QPushButton>
27 #include <QMessageBox>
28 #include <QSortFilterProxyModel>
42 : QSortFilterProxyModel( parent ), mModel( model )
43 { setSourceModel( mModel ); }
67 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
70 restoreGeometry( settings.value(
"/Windows/CptCityColorRampV2Dialog/geometry" ).toByteArray() );
71 mSplitter->setSizes( QList<int>() << 250 << 550 );
72 mSplitter->restoreState( settings.value(
"/Windows/CptCityColorRampV2Dialog/splitter" ).toByteArray() );
85 QTextEdit *edit =
new QTextEdit( 0 );
86 edit->setReadOnly(
true );
88 QString helpText =
tr(
"Error - cpt-city gradient files not found.\n\n"
89 "You have two means of installing them:\n\n"
90 "1) Install the \"Color Ramp Manager\" python plugin "
91 "(you must enable Experimental plugins in the plugin manager) "
92 "and use it to download latest cpt-city package.\n"
93 "You can install the entire cpt-city archive or a selection for QGIS.\n\n"
94 "2) Download the complete archive (in svg format) "
95 "and unzip it to your QGIS settings directory [%1] .\n\n"
96 "This file can be found at [%2]\nand current file is [%3]"
98 ).arg(
"http://soliton.vm.bytemark.co.uk/pub/cpt-city/pkg/"
99 ).arg(
"http://soliton.vm.bytemark.co.uk/pub/cpt-city/pkg/cpt-city-svg-2.07.zip" );
100 edit->setText( helpText );
101 mStackedWidget->addWidget( edit );
102 mStackedWidget->setCurrentIndex( 1 );
103 tabBar->setVisible(
false );
135 mTreeView->setSelectionMode( QAbstractItemView::SingleSelection );
136 mTreeView->setColumnHidden( 1,
true );
140 tabBar->blockSignals(
true );
141 tabBar->addTab(
tr(
"Selections by theme" ) );
142 tabBar->addTab(
tr(
"All by author" ) );
143 cboVariantName->setIconSize( QSize( 100, 15 ) );
144 lblPreview->installEventFilter(
this );
153 tabBar->setCurrentIndex( 1 );
159 tabBar->setCurrentIndex( 0 );
164 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
true );
171 tabBar->blockSignals(
false );
173 connect(
this, SIGNAL( finished(
int ) ),
this, SLOT(
onFinished() ) );
187 cboVariantName->blockSignals(
true );
188 cboVariantName->clear();
190 if ( variantList.isEmpty() )
192 cboVariantName->setEnabled(
false );
193 cboVariantName->setVisible(
false );
199 QString oldVariant = cboVariantName->currentText();
201 QPixmap blankPixmap( cboVariantName->iconSize() );
202 blankPixmap.fill( Qt::white );
203 QIcon blankIcon( blankPixmap );
206 foreach ( QString variant, variantList )
208 QString variantStr = variant;
209 if ( variantStr.startsWith(
"-" ) || variantStr.startsWith(
"_" ) )
210 variantStr.remove( 0, 1 );
211 cboVariantName->addItem(
" " + variantStr );
212 index = cboVariantName->count() - 1;
213 cboVariantName->setItemData( index, variant, Qt::UserRole );
215 ramp.setVariantName( variant );
216 if ( ramp.loadFile() )
217 cboVariantName->setItemIcon( index,
220 cboVariantName->setItemIcon( index, blankIcon );
221 cboVariantName->setItemData( index, Qt::AlignHCenter, Qt::TextAlignmentRole );
224 cboVariantName->blockSignals(
false );
230 if ( newVariant != QString() )
232 if ( newVariant.startsWith(
"-" ) || newVariant.startsWith(
"_" ) )
233 newVariant.remove( 0, 1 );
234 newVariant =
" " + newVariant;
235 idx = cboVariantName->findText( newVariant );
238 idx = cboVariantName->findText( oldVariant );
243 idx = cboVariantName->count() / 2;
245 cboVariantName->setCurrentIndex( idx );
248 cboVariantName->setEnabled(
true );
249 cboVariantName->setVisible(
true );
256 const QModelIndex &sourceIndex =
mTreeFilter->mapToSource( index );
261 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
278 lblSchemeName->setText(
"" );
282 lblSchemePath->setText( item->
path() );
283 lblCollectionInfo->setText( QString(
"%1 (%2)" ).arg( item->
info() ).arg( item->
leafCount() ) );
288 lblSchemePath->setText(
"" );
291 lblCollectionInfo->setText( QString(
"%1 (%2)" ).arg( item->
info() ).arg( item->
leafCount() ) );
295 lblSchemePath->setText(
"" );
298 lblCollectionInfo->setText(
tr(
"All Ramps (%1)" ).arg( item->
leafCount() ) );
302 QgsDebugMsg( QString(
"item %1 has invalid type %2" ).arg( item->
path() ).arg((
int )item->
type() ) );
311 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
true );
312 lblSchemeName->setText( QFileInfo( rampItem->
name() ).fileName() );
325 if ( mListWidget->selectedItems().count() == 0 )
339 else if ( index == 1 )
346 QgsDebugMsg( QString(
"invalid index %1" ).arg( index ) );
351 mListWidget->blockSignals(
true );
353 mListWidget->blockSignals(
false );
359 QString path, title, copyFile, descFile;
370 title =
tr(
"%1 directory details" ).arg( item->
path() );
374 title =
tr(
"%1 gradient details" ).arg( path );
384 QgsDialog dlg(
this, 0, QDialogButtonBox::Close );
385 QVBoxLayout *layout = dlg.
layout();
386 dlg.setWindowTitle( title );
387 QTextEdit *textEdit =
new QTextEdit( &dlg );
388 textEdit->setReadOnly(
true );
389 layout->addWidget( textEdit );
393 if ( ! copyFile.isNull() )
395 QFile
file( copyFile );
396 if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) )
398 copyText = QString( file.readAll() );
403 if ( ! descFile.isNull() )
405 QFile
file( descFile );
406 if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) )
408 descText = QString( file.readAll() );
412 textEdit->insertPlainText( title +
"\n\n" );
413 textEdit->insertPlainText(
"===================" );
414 textEdit->insertPlainText(
" copying " );
415 textEdit->insertPlainText(
"===================\n" );
416 textEdit->insertPlainText( copyText );
417 textEdit->insertPlainText(
"\n" );
418 textEdit->insertPlainText(
"==================" );
419 textEdit->insertPlainText(
" description " );
420 textEdit->insertPlainText(
"==================\n" );
421 textEdit->insertPlainText( descText );
422 textEdit->moveCursor( QTextCursor::Start );
424 dlg.resize( 600, 600 );
430 QSize
size = lblPreview->size();
434 lblSchemeName->setText(
"" );
435 lblSchemePath->setText(
"" );
436 lblLicensePreview->setText(
"" );
437 QPixmap blankPixmap( size );
438 blankPixmap.fill( Qt::transparent );
439 lblPreview->setPixmap( blankPixmap );
451 lblPreview->setPixmap( pixmap );
464 QString authorStr = copyingMap.value(
"authors" );
465 if ( authorStr.length() > 80 )
466 authorStr.replace( authorStr.indexOf(
" ", 80 ), 1,
"\n" );
467 lblAuthorName->setText( authorStr );
468 QString licenseStr = copyingMap.value(
"license/informal" );
469 if ( copyingMap.contains(
"license/year" ) )
470 licenseStr +=
" (" + copyingMap.value(
"license/year" ) +
")";
471 if ( licenseStr.length() > 80 )
472 licenseStr.replace( licenseStr.indexOf(
" ", 80 ), 1,
"\n" );
473 if ( copyingMap.contains(
"license/url" ) )
474 licenseStr +=
"\n[ " + copyingMap.value(
"license/url" ) +
" ]";
477 lblLicenseName->setText( licenseStr );
478 licenseStr.replace(
"\n",
" " );
479 lblLicensePreview->setText( licenseStr );
480 lblLicensePreview->setCursorPosition( 0 );
481 if ( copyingMap.contains(
"src/link" ) )
482 lblSrcLink->setText( copyingMap.value(
"src/link" ) );
484 lblSrcLink->setText(
"" );
490 if ( cboVariantName->currentIndex() != -1 )
491 mRamp->
setVariantName( cboVariantName->itemData( cboVariantName->currentIndex(), Qt::UserRole ).toString() );
500 settings.setValue(
"/Windows/CptCityColorRampV2Dialog/geometry", saveGeometry() );
501 settings.setValue(
"/Windows/CptCityColorRampV2Dialog/splitter", mSplitter->saveState() );
507 QString helpText =
tr(
"You can download a more complete set of cpt-city gradients "
508 "by installing the \"Color Ramp Manager\" plugin "
509 "(you must enable Experimental plugins in the plugin manager).\n\n"
511 QMessageBox* msg =
new QMessageBox(
this );
512 msg->setText( helpText );
518 QgsDebugMsg( QString(
"result: %1 checked: %2" ).arg( result() ).arg( cboConvertStandard->isChecked() ) );
520 return ( result() == Accepted && cboConvertStandard->isChecked() );
525 mListWidget->blockSignals(
true );
526 mListWidget->clear();
533 QVector<QgsCptCityDataItem*> childrenRamps = colItem->
childrenRamps(
true );
534 for (
int i = 0; i < childrenRamps.count(); i++ )
539 QgsDebugMsg(
"invalid item " + childrenRamps[i]->path() );
542 QListWidgetItem* listItem =
new QListWidgetItem();
543 listItem->setText( rampItem->
shortInfo() );
544 listItem->setIcon( rampItem->
icon( QSize( 75, 50 ) ) );
545 listItem->setToolTip( rampItem->
path() +
"\n" + rampItem->
info() );
546 listItem->setData( Qt::UserRole, QVariant( i ) );
547 mListWidget->addItem( listItem );
555 mListWidget->blockSignals(
false );
563 QSize
size = lblPreview->size();
565 if ( event->type() == QEvent::MouseButtonPress )
569 if ( ! pixmap.isNull() )
570 lblPreview->setPixmap( pixmap.scaled( size ) );
573 else if ( event->type() == QEvent::MouseButtonRelease )
577 lblPreview->setPixmap( pixmap );
590 mListWidget->clear();
592 cboVariantName->clear();
594 lblCollectionInfo->clear();
596 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
608 if ( modelIndex == QModelIndex() )
626 QModelIndex parentIndex = modelIndex.parent();
627 QModelIndex selIndex =
mTreeFilter->mapFromSource( parentIndex );
630 mTreeView->setCurrentIndex( selIndex );
631 mTreeView->setExpanded( selIndex,
true );
632 mTreeView->scrollTo( selIndex, QAbstractItemView::PositionAtCenter );
636 for (
int i = 0; i <
mListRamps.count(); i++ )
641 QListWidgetItem* listItem = mListWidget->item( i );
642 mListWidget->setCurrentItem( listItem );
645 mListWidget->scrollToItem( listItem, QAbstractItemView::EnsureVisible );
647 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
true );
658 if ( modelIndex != QModelIndex() )
660 QModelIndex selIndex =
mTreeFilter->mapFromSource( modelIndex );
661 mTreeView->setCurrentIndex( selIndex );
662 mTreeView->setExpanded( selIndex,
true );
663 mTreeView->scrollTo( selIndex, QAbstractItemView::PositionAtCenter );
680 void QgsCptCityColorRampV2Dialog::refresh()
682 QApplication::setOverrideCursor( Qt::WaitCursor );
683 refreshModel( QModelIndex() );
684 QApplication::restoreOverrideCursor();
687 void QgsCptCityColorRampV2Dialog::refreshModel(
const QModelIndex&
index )
689 if ( index.isValid() )