24 #include <QPushButton>
27 #include <QMessageBox>
28 #include <QSortFilterProxyModel>
67 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
71 mSplitter->setSizes(
QList<int>() << 250 << 550 );
72 mSplitter->restoreState( settings.
value(
"/Windows/CptCityColorRampV2Dialog/splitter" ).
toByteArray() );
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" );
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 );
187 cboVariantName->blockSignals(
true );
188 cboVariantName->clear();
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 )
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 );
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 );
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() ) );
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 )
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 );
393 if ( ! copyFile.
isNull() )
395 QFile file( copyFile );
396 if ( file.
open( QIODevice::ReadOnly | QIODevice::Text ) )
403 if ( ! descFile.
isNull() )
405 QFile file( descFile );
406 if ( file.
open( QIODevice::ReadOnly | QIODevice::Text ) )
434 lblSchemeName->setText(
"" );
435 lblSchemePath->setText(
"" );
436 lblLicensePreview->setText(
"" );
438 blankPixmap.
fill( Qt::transparent );
439 lblPreview->setPixmap( blankPixmap );
451 lblPreview->setPixmap( pixmap );
465 if ( authorStr.
length() > 80 )
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 )
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() );
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"
520 return (
result() == Accepted && cboConvertStandard->isChecked() );
525 mListWidget->blockSignals(
true );
526 mListWidget->clear();
534 for (
int i = 0; i < childrenRamps.count(); i++ )
539 QgsDebugMsg(
"invalid item " + childrenRamps[i]->path() );
547 mListWidget->addItem( listItem );
555 mListWidget->blockSignals(
false );
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 );
630 mTreeView->setCurrentIndex( selIndex );
631 mTreeView->setExpanded( selIndex,
true );
632 mTreeView->scrollTo( selIndex, QAbstractItemView::PositionAtCenter );
642 mListWidget->setCurrentItem( listItem );
645 mListWidget->scrollToItem( listItem, QAbstractItemView::EnsureVisible );
647 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
true );
661 mTreeView->setCurrentIndex( selIndex );
662 mTreeView->setExpanded( selIndex,
true );
663 mTreeView->scrollTo( selIndex, QAbstractItemView::PositionAtCenter );
680 void QgsCptCityColorRampV2Dialog::refresh()
void moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode)
QByteArray toByteArray() const
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
void updateListWidget(QgsCptCityDataItem *item)
void setName(QString schemeName, QString variantName="", QStringList variantList=QStringList())
~QgsCptCityColorRampV2Dialog()
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
static QIcon colorRampPreviewIcon(QgsVectorColorRampV2 *ramp, QSize size)
static QPixmap colorRampPreviewPixmap(QgsVectorColorRampV2 *ramp, QSize size)
bool contains(const Key &key) const
static QgsCptCityArchive * defaultArchive()
QgsCptCityBrowserModel * mSelectionsModel
QgsCptCityColorRampV2 * mRamp
void fill(const QColor &color)
void copy(const QgsCptCityColorRampV2 *other)
virtual void setSourceModel(QAbstractItemModel *sourceModel)
void on_pbtnLicenseDetails_pressed()
QString archiveName() const
void on_cboVariantName_currentIndexChanged(int index)
void updatePreview(bool clear=false)
A generic dialog with layout and button box.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Returns the index of the item in the model specified by the given row, column and parent index...
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.
bool saveAsGradientRamp() const
void on_mListWidget_itemSelectionChanged()
QVector< QgsCptCityColorRampItem * > mListRamps
QString & remove(int position, int n)
QgsCptCityBrowserModel * mAuthorsModel
static const QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
QString tr(const char *sourceText, const char *disambiguation, int n)
QgsCptCityBrowserModel::ViewType mArchiveViewType
TreeFilterProxyModel(QObject *parent, QgsCptCityBrowserModel *model)
QgsCptCityArchive * mArchive
void finished(int result)
void setValue(const QString &key, const QVariant &value)
void refresh(QString path)
QModelIndex findPath(QString path)
return index of a path
QString variantName() const
void updateTreeView(QgsCptCityDataItem *item, bool resetRamp=true)
int count(const T &value) const
QStringList variantList() const
QString copyingFileName(const QString &dirName) const
int toInt(bool *ok) const
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const override
Provides the number of rows of data exposed by the model.
QgsCptCityColorRampV2Dialog(QgsCptCityColorRampV2 *ramp, QWidget *parent=NULL)
void setVariantName(QString variantName)
bool hasChildren(const QModelIndex &parent=QModelIndex()) const override
void setText(const QString &text)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
void setOverrideCursor(const QCursor &cursor)
QgsStringMap copyingInfo() const
base class for all items in the model
void restoreOverrideCursor()
static QMap< QString, QString > copyingInfo(const QString &fileName)
virtual bool eventFilter(QObject *watched, QEvent *event)
void on_buttonBox_helpRequested()
A Collection: logical collection of subcollections and color ramps.
QModelIndex parent() const
QString descFileName(const QString &dirName) const
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QString shortInfo() const
static void initDefaultArchive()
void on_mListWidget_itemClicked(QListWidgetItem *item)
void updateCopyingInfo(const QMap< QString, QString > ©ingMap)
QString & replace(int position, int n, QChar after)
const T & at(int i) const
QVariant value(const QString &key, const QVariant &defaultValue) const
virtual int leafCount() const
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const
bool eventFilter(QObject *obj, QEvent *event) override
virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
void setVariantList(QStringList variantList)
QVBoxLayout * layout()
Returns the central layout. Widgets added to it must have this dialog as parent.
int count(const T &value) const
TreeFilterProxyModel * mTreeFilter
void on_tabBar_currentChanged(int index)
void setReadOnly(bool ro)
QVector< QgsCptCityDataItem * > childrenRamps(bool recursive)
QgsCptCityBrowserModel * mModel
void on_mTreeView_clicked(const QModelIndex &)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString schemeName() const
void setText(const QString &text)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
void insertPlainText(const QString &text)
const QgsCptCityColorRampV2 & ramp() const
void setText(const QString &text)
void setTreeModel(QgsCptCityBrowserModel *model)
const T value(const Key &key) const