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() )
315 else if ( index == 1 )
327 mListWidget->blockSignals(
true );
329 mListWidget->blockSignals(
false );
335 QString path, title, copyFile, descFile;
345 title =
tr(
"%1 directory details" ).
arg( item->
path() );
349 title =
tr(
"%1 gradient details" ).
arg( path );
359 QgsDialog dlg(
this,
nullptr, QDialogButtonBox::Close );
368 if ( ! copyFile.
isNull() )
370 QFile file( copyFile );
371 if ( file.
open( QIODevice::ReadOnly | QIODevice::Text ) )
378 if ( ! descFile.
isNull() )
380 QFile file( descFile );
381 if ( file.
open( QIODevice::ReadOnly | QIODevice::Text ) )
409 lblSchemeName->setText(
"" );
410 lblSchemePath->setText(
"" );
411 lblLicensePreview->setText(
"" );
413 blankPixmap.
fill( Qt::transparent );
414 lblPreview->setPixmap( blankPixmap );
426 lblPreview->setPixmap( pixmap );
440 if ( authorStr.
length() > 80 )
442 lblAuthorName->setText( authorStr );
443 QString licenseStr = copyingMap.
value(
"license/informal" );
444 if ( copyingMap.
contains(
"license/year" ) )
445 licenseStr +=
" (" + copyingMap.
value(
"license/year" ) +
')';
446 if ( licenseStr.
length() > 80 )
448 if ( copyingMap.
contains(
"license/url" ) )
449 licenseStr +=
"\n[ " + copyingMap.
value(
"license/url" ) +
" ]";
452 lblLicenseName->setText( licenseStr );
453 licenseStr.
replace(
'\n',
" " );
454 lblLicensePreview->setText( licenseStr );
455 lblLicensePreview->setCursorPosition( 0 );
456 if ( copyingMap.
contains(
"src/link" ) )
457 lblSrcLink->setText( copyingMap.
value(
"src/link" ) );
459 lblSrcLink->setText(
"" );
465 if ( cboVariantName->currentIndex() != -1 )
466 mRamp->
setVariantName( cboVariantName->itemData( cboVariantName->currentIndex(), Qt::UserRole ).toString() );
476 settings.
setValue(
"/Windows/CptCityColorRampV2Dialog/splitter", mSplitter->saveState() );
482 QString helpText =
tr(
"You can download a more complete set of cpt-city gradients " 483 "by installing the \"Color Ramp Manager\" plugin " 484 "(you must enable Experimental plugins in the plugin manager).\n\n" 495 return (
result() == Accepted && cboConvertStandard->isChecked() );
500 mListWidget->blockSignals(
true );
501 mListWidget->clear();
509 for (
int i = 0; i < childrenRamps.count(); i++ )
514 QgsDebugMsg(
"invalid item " + childrenRamps[i]->path() );
522 mListWidget->addItem( listItem );
530 mListWidget->blockSignals(
false );
540 if ( event->
type() == QEvent::MouseButtonPress )
544 if ( ! pixmap.isNull() )
545 lblPreview->setPixmap( pixmap.scaled( size ) );
548 else if ( event->
type() == QEvent::MouseButtonRelease )
552 lblPreview->setPixmap( pixmap );
564 mListWidget->clear();
566 cboVariantName->clear();
568 lblCollectionInfo->clear();
570 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
false );
604 mTreeView->setCurrentIndex( selIndex );
605 mTreeView->setExpanded( selIndex,
true );
606 mTreeView->scrollTo( selIndex, QAbstractItemView::PositionAtCenter );
616 mListWidget->setCurrentItem( listItem );
619 mListWidget->scrollToItem( listItem, QAbstractItemView::EnsureVisible );
621 buttonBox->button( QDialogButtonBox::Ok )->setEnabled(
true );
635 mTreeView->setCurrentIndex( selIndex );
636 mTreeView->setExpanded( selIndex,
true );
637 mTreeView->scrollTo( selIndex, QAbstractItemView::PositionAtCenter );
653 void QgsCptCityColorRampV2Dialog::refresh()
697 bool TreeFilterProxyModel::filterAcceptsRow(
int sourceRow,
const QModelIndex& sourceParent )
const
void moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode)
QString schemeName() const
QgsStringMap copyingInfo() const
QByteArray toByteArray() const
QString descFileName(const QString &dirName) 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)
QgsCptCityDataItem * dataItem(const QModelIndex &idx) const
Returns a list of mime that can describe model indexes.
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()
const QgsCptCityColorRampV2 & ramp() 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.
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)
void updateTreeView(QgsCptCityDataItem *item, bool resetRamp=true)
int count(const T &value) const
void setVariantName(const QString &variantName)
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)
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
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QString shortInfo() const
static void initDefaultArchive()
QString archiveName() const
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
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
bool saveAsGradientRamp() const
QString variantName() const
TreeFilterProxyModel * mTreeFilter
void on_tabBar_currentChanged(int index)
void setReadOnly(bool ro)
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)
void setText(const QString &text)
void setVariantList(const QStringList &variantList)
QVector< QgsCptCityDataItem * > childrenRamps(bool recursive)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
virtual int leafCount() const
void insertPlainText(const QString &text)
QStringList variantList() const
QString copyingFileName(const QString &dirName) const
void setText(const QString &text)
void setTreeModel(QgsCptCityBrowserModel *model)
const T value(const Key &key) const