24 #include <QPushButton> 27 #include <QMessageBox> 28 #include <QSortFilterProxyModel> 44 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
48 mSplitter->setSizes(
QList<int>() << 250 << 550 );
49 mSplitter->restoreState( settings.
value(
"/Windows/CptCityColorRampV2Dialog/splitter" ).
toByteArray() );
65 QString helpText =
tr(
"Error - cpt-city gradient files not found.\n\n" 66 "You have two means of installing them:\n\n" 67 "1) Install the \"Color Ramp Manager\" python plugin " 68 "(you must enable Experimental plugins in the plugin manager) " 69 "and use it to download latest cpt-city package.\n" 70 "You can install the entire cpt-city archive or a selection for QGIS.\n\n" 71 "2) Download the complete archive (in svg format) " 72 "and unzip it to your QGIS settings directory [%1] .\n\n" 73 "This file can be found at [%2]\nand current file is [%3]" 75 "http://soliton.vm.bytemark.co.uk/pub/cpt-city/pkg/",
76 "http://soliton.vm.bytemark.co.uk/pub/cpt-city/pkg/cpt-city-svg-2.07.zip" );
78 mStackedWidget->addWidget( edit );
79 mStackedWidget->setCurrentIndex( 1 );
80 tabBar->setVisible(
false );
112 mTreeView->setSelectionMode( QAbstractItemView::SingleSelection );
113 mTreeView->setColumnHidden( 1,
true );
117 tabBar->blockSignals(
true );
118 tabBar->addTab(
tr(
"Selections by theme" ) );
119 tabBar->addTab(
tr(
"All by author" ) );
120 cboVariantName->setIconSize(
QSize( 100, 15 ) );
121 lblPreview->installEventFilter(
this );
130 tabBar->setCurrentIndex( 1 );
136 tabBar->setCurrentIndex( 0 );
141 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
true );
148 tabBar->blockSignals(
false );
164 cboVariantName->blockSignals(
true );
165 cboVariantName->clear();
169 cboVariantName->setEnabled(
false );
170 cboVariantName->setVisible(
false );
176 QString oldVariant = cboVariantName->currentText();
178 QPixmap blankPixmap( cboVariantName->iconSize() );
179 blankPixmap.
fill( Qt::white );
180 QIcon blankIcon( blankPixmap );
183 Q_FOREACH (
const QString& variant, variantList )
187 variantStr.
remove( 0, 1 );
188 cboVariantName->addItem(
' ' + variantStr );
189 index = cboVariantName->
count() - 1;
190 cboVariantName->setItemData( index, variant, Qt::UserRole );
192 ramp.setVariantName( variant );
193 if ( ramp.loadFile() )
194 cboVariantName->setItemIcon( index,
197 cboVariantName->setItemIcon( index, blankIcon );
198 cboVariantName->setItemData( index, Qt::AlignHCenter, Qt::TextAlignmentRole );
201 cboVariantName->blockSignals(
false );
210 newVariant.
remove( 0, 1 );
211 newVariant =
' ' + newVariant;
212 idx = cboVariantName->findText( newVariant );
215 idx = cboVariantName->findText( oldVariant );
220 idx = cboVariantName->
count() / 2;
222 cboVariantName->setCurrentIndex( idx );
225 cboVariantName->setEnabled(
true );
226 cboVariantName->setVisible(
true );
238 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
255 lblSchemeName->setText(
"" );
259 lblSchemePath->setText( item->
path() );
260 lblCollectionInfo->setText(
QString(
"%1 (%2)" ).arg( item->
info() ).arg( item->
leafCount() ) );
265 lblSchemePath->setText(
"" );
268 lblCollectionInfo->setText(
QString(
"%1 (%2)" ).arg( item->
info() ).arg( item->
leafCount() ) );
272 lblSchemePath->setText(
"" );
275 lblCollectionInfo->setText(
tr(
"All Ramps (%1)" ).arg( item->
leafCount() ) );
288 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
true );
289 lblSchemeName->setText(
QFileInfo( rampItem->
name() ).fileName() );
302 if ( mListWidget->selectedItems().isEmpty() )
316 else if ( index == 1 )
328 mListWidget->blockSignals(
true );
330 mListWidget->blockSignals(
false );
336 QString path, title, copyFile, descFile;
346 title =
tr(
"%1 directory details" ).
arg( item->
path() );
350 title =
tr(
"%1 gradient details" ).
arg( path );
360 QgsDialog dlg(
this,
nullptr, QDialogButtonBox::Close );
369 if ( ! copyFile.
isNull() )
371 QFile file( copyFile );
372 if ( file.
open( QIODevice::ReadOnly | QIODevice::Text ) )
379 if ( ! descFile.
isNull() )
381 QFile file( descFile );
382 if ( file.
open( QIODevice::ReadOnly | QIODevice::Text ) )
410 lblSchemeName->setText(
"" );
411 lblSchemePath->setText(
"" );
412 lblLicensePreview->setText(
"" );
414 blankPixmap.
fill( Qt::transparent );
415 lblPreview->setPixmap( blankPixmap );
427 lblPreview->setPixmap( pixmap );
441 if ( authorStr.
length() > 80 )
443 lblAuthorName->setText( authorStr );
444 QString licenseStr = copyingMap.
value(
"license/informal" );
445 if ( copyingMap.
contains(
"license/year" ) )
446 licenseStr +=
" (" + copyingMap.
value(
"license/year" ) +
')';
447 if ( licenseStr.
length() > 80 )
449 if ( copyingMap.
contains(
"license/url" ) )
450 licenseStr +=
"\n[ " + copyingMap.
value(
"license/url" ) +
" ]";
453 lblLicenseName->setText( licenseStr );
454 licenseStr.
replace(
'\n',
" " );
455 lblLicensePreview->setText( licenseStr );
456 lblLicensePreview->setCursorPosition( 0 );
457 if ( copyingMap.
contains(
"src/link" ) )
458 lblSrcLink->setText( copyingMap.
value(
"src/link" ) );
460 lblSrcLink->setText(
"" );
466 if ( cboVariantName->currentIndex() != -1 )
467 mRamp->
setVariantName( cboVariantName->itemData( cboVariantName->currentIndex(), Qt::UserRole ).toString() );
477 settings.
setValue(
"/Windows/CptCityColorRampV2Dialog/splitter", mSplitter->saveState() );
483 QString helpText =
tr(
"You can download a more complete set of cpt-city gradients " 484 "by installing the \"Color Ramp Manager\" plugin " 485 "(you must enable Experimental plugins in the plugin manager).\n\n" 496 return (
result() == Accepted && cboConvertStandard->isChecked() );
501 mListWidget->blockSignals(
true );
502 mListWidget->clear();
510 for (
int i = 0; i < childrenRamps.count(); i++ )
515 QgsDebugMsg(
"invalid item " + childrenRamps[i]->path() );
523 mListWidget->addItem( listItem );
531 mListWidget->blockSignals(
false );
541 if ( event->
type() == QEvent::MouseButtonPress )
545 if ( ! pixmap.isNull() )
546 lblPreview->setPixmap( pixmap.scaled( size ) );
549 else if ( event->
type() == QEvent::MouseButtonRelease )
553 lblPreview->setPixmap( pixmap );
566 mListWidget->clear();
568 cboVariantName->clear();
570 lblCollectionInfo->clear();
572 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
606 mTreeView->setCurrentIndex( selIndex );
607 mTreeView->setExpanded( selIndex,
true );
608 mTreeView->scrollTo( selIndex, QAbstractItemView::PositionAtCenter );
618 mListWidget->setCurrentItem( listItem );
621 mListWidget->scrollToItem( listItem, QAbstractItemView::EnsureVisible );
623 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
true );
637 mTreeView->setCurrentIndex( selIndex );
638 mTreeView->setExpanded( selIndex,
true );
639 mTreeView->scrollTo( selIndex, QAbstractItemView::PositionAtCenter );
656 void QgsCptCityColorRampV2Dialog::refresh()
699 bool TreeFilterProxyModel::filterAcceptsRow(
int sourceRow,
const QModelIndex& sourceParent )
const
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)
virtual bool event(QEvent *e)
~QgsCptCityColorRampV2Dialog()
static QIcon colorRampPreviewIcon(QgsVectorColorRampV2 *ramp, QSize size)
static QPixmap colorRampPreviewPixmap(QgsVectorColorRampV2 *ramp, QSize size)
bool contains(const Key &key) const
void setName(const QString &schemeName, const QString &variantName="", const QStringList &variantList=QStringList())
static QgsCptCityArchive * defaultArchive()
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
QgsCptCityBrowserModel * mSelectionsModel
QgsCptCityColorRampV2 * mRamp
void fill(const QColor &color)
void copy(const QgsCptCityColorRampV2 *other)
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
QModelIndex findPath(const QString &path)
return index of a path
QString tr(const char *sourceText, const char *disambiguation, int n)
QgsCptCityBrowserModel::ViewType mArchiveViewType
QgsCptCityArchive * mArchive
void finished(int result)
void setValue(const QString &key, const QVariant &value)
QString variantName() const
void updateTreeView(QgsCptCityDataItem *item, bool resetRamp=true)
int count(const T &value) const
void setVariantName(const QString &variantName)
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.
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)
QgsCptCityColorRampV2Dialog(QgsCptCityColorRampV2 *ramp, QWidget *parent=nullptr)
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
void refresh(const QString &path)
bool eventFilter(QObject *obj, QEvent *event) override
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)
void setVariantList(const QStringList &variantList)
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