Skip to content

Commit

Permalink
Show scheme selector in color section of options
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 12, 2018
1 parent 21ef2fd commit 2a0f364
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 44 deletions.
16 changes: 8 additions & 8 deletions resources/palettes/new_layer_colors.gpl
Expand Up @@ -2,11 +2,11 @@ GIMP Palette
Name: New Layer Colors
Columns: 4
#
213 207 60
249 216 123
114 155 111
91 122 162
243 166 178
141 90 153
232 113 141
106 161 195
213 207 60 #d5cf3c
249 216 123 #f9d87b
114 155 111 #729b6f
91 122 162 #5b7aa2
243 166 178 #f3a6b2
141 90 153 #8d5a99
232 113 141 #e8718d
106 161 195 #6aa1c3
28 changes: 28 additions & 0 deletions src/app/qgsoptions.cpp
Expand Up @@ -755,12 +755,27 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
connect( mButtonExportColors, &QAbstractButton::clicked, mTreeCustomColors, &QgsColorSchemeList::showExportColorsDialog );

//find custom color scheme from registry
refreshSchemeComboBox();
QList<QgsCustomColorScheme *> customSchemes;
QgsApplication::colorSchemeRegistry()->schemes( customSchemes );
if ( customSchemes.length() > 0 )
{
mTreeCustomColors->setScheme( customSchemes.at( 0 ) );
mColorSchemesComboBox->setCurrentIndex( mColorSchemesComboBox->findText( customSchemes.at( 0 )->schemeName() ) );
}
connect( mColorSchemesComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, [ = ]( int index )
{
//save changes to scheme
if ( mTreeCustomColors->isDirty() )
{
mTreeCustomColors->saveColorsToScheme();
}

QgsColorScheme *scheme = QgsApplication::colorSchemeRegistry()->schemes().value( index );
if ( scheme )
mTreeCustomColors->setScheme( scheme );
} );


//
// Layout settings
Expand Down Expand Up @@ -2244,6 +2259,19 @@ void QgsOptions::addScaleToScaleList( QListWidgetItem *newItem )
mListGlobalScales->insertItem( i, newItem );
}

void QgsOptions::refreshSchemeComboBox()
{
mColorSchemesComboBox->blockSignals( true );
mColorSchemesComboBox->clear();
QList<QgsColorScheme *> schemeList = QgsApplication::colorSchemeRegistry()->schemes();
QList<QgsColorScheme *>::const_iterator schemeIt = schemeList.constBegin();
for ( ; schemeIt != schemeList.constEnd(); ++schemeIt )
{
mColorSchemesComboBox->addItem( ( *schemeIt )->schemeName() );
}
mColorSchemesComboBox->blockSignals( false );
}

void QgsOptions::scaleItemChanged( QListWidgetItem *changedScaleItem )
{
// Check if the new value is valid, restore the old value if not.
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsoptions.h
Expand Up @@ -250,6 +250,8 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption
QListWidgetItem *addScaleToScaleList( const QString &newScale );
void addScaleToScaleList( QListWidgetItem *newItem );

void refreshSchemeComboBox();

protected:
QgisAppStyleSheet *mStyleSheetBuilder = nullptr;
QMap<QString, QVariant> mStyleSheetNewOpts;
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgscolorscheme.cpp
Expand Up @@ -303,6 +303,8 @@ QgsUserColorScheme::QgsUserColorScheme( const QString &filename )
: mFilename( filename )
{
QFile sourceFile( gplFilePath() );
QFileInfo sourceFileInfo( gplFilePath() );
mEditable = sourceFileInfo.isWritable();

//read in name
if ( sourceFile.open( QIODevice::ReadOnly ) )
Expand Down
4 changes: 3 additions & 1 deletion src/core/qgscolorscheme.h
Expand Up @@ -186,7 +186,7 @@ class CORE_EXPORT QgsUserColorScheme : public QgsGplColorScheme

QgsUserColorScheme *clone() const override SIP_FACTORY;

bool isEditable() const override { return true; }
bool isEditable() const override { return mEditable; }

QgsColorScheme::SchemeFlags flags() const override;

Expand Down Expand Up @@ -215,6 +215,8 @@ class CORE_EXPORT QgsUserColorScheme : public QgsGplColorScheme

QString mFilename;

bool mEditable = false;

QString gplFilePath() override;

};
Expand Down
77 changes: 42 additions & 35 deletions src/ui/qgsoptionsbase.ui
Expand Up @@ -3571,38 +3571,51 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<item>
<widget class="QgsCollapsibleGroupBox" name="groupBox_7">
<property name="title">
<string>Standard colors</string>
<string>Color schemes</string>
</property>
<layout class="QGridLayout" name="gridLayout_12">
<item row="3" column="1">
<widget class="QToolButton" name="mButtonPasteColors">
<item row="7" column="1">
<spacer name="verticalSpacer_12">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="1">
<widget class="QToolButton" name="mButtonImportColors">
<property name="toolTip">
<string>Paste colors</string>
<string>Import colors from file</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionEditPaste.svg</normaloff>:/images/themes/default/mActionEditPaste.svg</iconset>
<normaloff>:/images/themes/default/mActionFileOpen.svg</normaloff>:/images/themes/default/mActionFileOpen.svg</iconset>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QToolButton" name="mButtonExportColors">
<item row="4" column="1">
<widget class="QToolButton" name="mButtonPasteColors">
<property name="toolTip">
<string>Export colors</string>
<string>Paste colors</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionFileSave.svg</normaloff>:/images/themes/default/mActionFileSave.svg</iconset>
<normaloff>:/images/themes/default/mActionEditPaste.svg</normaloff>:/images/themes/default/mActionEditPaste.svg</iconset>
</property>
</widget>
</item>
<item row="0" column="1">
<item row="1" column="1">
<widget class="QToolButton" name="mButtonAddColor">
<property name="toolTip">
<string>Add color</string>
Expand All @@ -3616,7 +3629,14 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="1" column="0" rowspan="8">
<widget class="QgsColorSchemeList" name="mTreeCustomColors" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QToolButton" name="mButtonRemoveColor">
<property name="toolTip">
<string>Remove color</string>
Expand All @@ -3630,20 +3650,7 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
</property>
</widget>
</item>
<item row="6" column="1">
<spacer name="verticalSpacer_12">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QToolButton" name="mButtonCopyColors">
<property name="toolTip">
<string>Copy colors</string>
Expand All @@ -3657,26 +3664,26 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QToolButton" name="mButtonImportColors">
<item row="6" column="1">
<widget class="QToolButton" name="mButtonExportColors">
<property name="toolTip">
<string>Import colors from file</string>
<string>Export colors</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionFileOpen.svg</normaloff>:/images/themes/default/mActionFileOpen.svg</iconset>
<normaloff>:/images/themes/default/mActionFileSave.svg</normaloff>:/images/themes/default/mActionFileSave.svg</iconset>
</property>
</widget>
</item>
<item row="0" column="0" rowspan="8">
<widget class="QgsColorSchemeList" name="mTreeCustomColors" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_22">
<item>
<widget class="QComboBox" name="mColorSchemesComboBox"/>
</item>
</layout>
</item>
</layout>
</widget>
Expand Down

0 comments on commit 2a0f364

Please sign in to comment.