Skip to content

Commit 2a0f364

Browse files
committedMar 12, 2018
Show scheme selector in color section of options
1 parent 21ef2fd commit 2a0f364

File tree

6 files changed

+85
-44
lines changed

6 files changed

+85
-44
lines changed
 

‎resources/palettes/new_layer_colors.gpl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ GIMP Palette
22
Name: New Layer Colors
33
Columns: 4
44
#
5-
213 207 60
6-
249 216 123
7-
114 155 111
8-
91 122 162
9-
243 166 178
10-
141 90 153
11-
232 113 141
12-
106 161 195
5+
213 207 60 #d5cf3c
6+
249 216 123 #f9d87b
7+
114 155 111 #729b6f
8+
91 122 162 #5b7aa2
9+
243 166 178 #f3a6b2
10+
141 90 153 #8d5a99
11+
232 113 141 #e8718d
12+
106 161 195 #6aa1c3

‎src/app/qgsoptions.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,12 +755,27 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
755755
connect( mButtonExportColors, &QAbstractButton::clicked, mTreeCustomColors, &QgsColorSchemeList::showExportColorsDialog );
756756

757757
//find custom color scheme from registry
758+
refreshSchemeComboBox();
758759
QList<QgsCustomColorScheme *> customSchemes;
759760
QgsApplication::colorSchemeRegistry()->schemes( customSchemes );
760761
if ( customSchemes.length() > 0 )
761762
{
762763
mTreeCustomColors->setScheme( customSchemes.at( 0 ) );
764+
mColorSchemesComboBox->setCurrentIndex( mColorSchemesComboBox->findText( customSchemes.at( 0 )->schemeName() ) );
763765
}
766+
connect( mColorSchemesComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, [ = ]( int index )
767+
{
768+
//save changes to scheme
769+
if ( mTreeCustomColors->isDirty() )
770+
{
771+
mTreeCustomColors->saveColorsToScheme();
772+
}
773+
774+
QgsColorScheme *scheme = QgsApplication::colorSchemeRegistry()->schemes().value( index );
775+
if ( scheme )
776+
mTreeCustomColors->setScheme( scheme );
777+
} );
778+
764779

765780
//
766781
// Layout settings
@@ -2244,6 +2259,19 @@ void QgsOptions::addScaleToScaleList( QListWidgetItem *newItem )
22442259
mListGlobalScales->insertItem( i, newItem );
22452260
}
22462261

2262+
void QgsOptions::refreshSchemeComboBox()
2263+
{
2264+
mColorSchemesComboBox->blockSignals( true );
2265+
mColorSchemesComboBox->clear();
2266+
QList<QgsColorScheme *> schemeList = QgsApplication::colorSchemeRegistry()->schemes();
2267+
QList<QgsColorScheme *>::const_iterator schemeIt = schemeList.constBegin();
2268+
for ( ; schemeIt != schemeList.constEnd(); ++schemeIt )
2269+
{
2270+
mColorSchemesComboBox->addItem( ( *schemeIt )->schemeName() );
2271+
}
2272+
mColorSchemesComboBox->blockSignals( false );
2273+
}
2274+
22472275
void QgsOptions::scaleItemChanged( QListWidgetItem *changedScaleItem )
22482276
{
22492277
// Check if the new value is valid, restore the old value if not.

‎src/app/qgsoptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption
250250
QListWidgetItem *addScaleToScaleList( const QString &newScale );
251251
void addScaleToScaleList( QListWidgetItem *newItem );
252252

253+
void refreshSchemeComboBox();
254+
253255
protected:
254256
QgisAppStyleSheet *mStyleSheetBuilder = nullptr;
255257
QMap<QString, QVariant> mStyleSheetNewOpts;

‎src/core/qgscolorscheme.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ QgsUserColorScheme::QgsUserColorScheme( const QString &filename )
303303
: mFilename( filename )
304304
{
305305
QFile sourceFile( gplFilePath() );
306+
QFileInfo sourceFileInfo( gplFilePath() );
307+
mEditable = sourceFileInfo.isWritable();
306308

307309
//read in name
308310
if ( sourceFile.open( QIODevice::ReadOnly ) )

‎src/core/qgscolorscheme.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class CORE_EXPORT QgsUserColorScheme : public QgsGplColorScheme
186186

187187
QgsUserColorScheme *clone() const override SIP_FACTORY;
188188

189-
bool isEditable() const override { return true; }
189+
bool isEditable() const override { return mEditable; }
190190

191191
QgsColorScheme::SchemeFlags flags() const override;
192192

@@ -215,6 +215,8 @@ class CORE_EXPORT QgsUserColorScheme : public QgsGplColorScheme
215215

216216
QString mFilename;
217217

218+
bool mEditable = false;
219+
218220
QString gplFilePath() override;
219221

220222
};

‎src/ui/qgsoptionsbase.ui

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3571,38 +3571,51 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
35713571
<item>
35723572
<widget class="QgsCollapsibleGroupBox" name="groupBox_7">
35733573
<property name="title">
3574-
<string>Standard colors</string>
3574+
<string>Color schemes</string>
35753575
</property>
35763576
<layout class="QGridLayout" name="gridLayout_12">
3577-
<item row="3" column="1">
3578-
<widget class="QToolButton" name="mButtonPasteColors">
3577+
<item row="7" column="1">
3578+
<spacer name="verticalSpacer_12">
3579+
<property name="orientation">
3580+
<enum>Qt::Vertical</enum>
3581+
</property>
3582+
<property name="sizeHint" stdset="0">
3583+
<size>
3584+
<width>20</width>
3585+
<height>40</height>
3586+
</size>
3587+
</property>
3588+
</spacer>
3589+
</item>
3590+
<item row="5" column="1">
3591+
<widget class="QToolButton" name="mButtonImportColors">
35793592
<property name="toolTip">
3580-
<string>Paste colors</string>
3593+
<string>Import colors from file</string>
35813594
</property>
35823595
<property name="text">
35833596
<string/>
35843597
</property>
35853598
<property name="icon">
35863599
<iconset resource="../../images/images.qrc">
3587-
<normaloff>:/images/themes/default/mActionEditPaste.svg</normaloff>:/images/themes/default/mActionEditPaste.svg</iconset>
3600+
<normaloff>:/images/themes/default/mActionFileOpen.svg</normaloff>:/images/themes/default/mActionFileOpen.svg</iconset>
35883601
</property>
35893602
</widget>
35903603
</item>
3591-
<item row="5" column="1">
3592-
<widget class="QToolButton" name="mButtonExportColors">
3604+
<item row="4" column="1">
3605+
<widget class="QToolButton" name="mButtonPasteColors">
35933606
<property name="toolTip">
3594-
<string>Export colors</string>
3607+
<string>Paste colors</string>
35953608
</property>
35963609
<property name="text">
35973610
<string/>
35983611
</property>
35993612
<property name="icon">
36003613
<iconset resource="../../images/images.qrc">
3601-
<normaloff>:/images/themes/default/mActionFileSave.svg</normaloff>:/images/themes/default/mActionFileSave.svg</iconset>
3614+
<normaloff>:/images/themes/default/mActionEditPaste.svg</normaloff>:/images/themes/default/mActionEditPaste.svg</iconset>
36023615
</property>
36033616
</widget>
36043617
</item>
3605-
<item row="0" column="1">
3618+
<item row="1" column="1">
36063619
<widget class="QToolButton" name="mButtonAddColor">
36073620
<property name="toolTip">
36083621
<string>Add color</string>
@@ -3616,7 +3629,14 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
36163629
</property>
36173630
</widget>
36183631
</item>
3619-
<item row="1" column="1">
3632+
<item row="1" column="0" rowspan="8">
3633+
<widget class="QgsColorSchemeList" name="mTreeCustomColors" native="true">
3634+
<property name="focusPolicy">
3635+
<enum>Qt::StrongFocus</enum>
3636+
</property>
3637+
</widget>
3638+
</item>
3639+
<item row="2" column="1">
36203640
<widget class="QToolButton" name="mButtonRemoveColor">
36213641
<property name="toolTip">
36223642
<string>Remove color</string>
@@ -3630,20 +3650,7 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
36303650
</property>
36313651
</widget>
36323652
</item>
3633-
<item row="6" column="1">
3634-
<spacer name="verticalSpacer_12">
3635-
<property name="orientation">
3636-
<enum>Qt::Vertical</enum>
3637-
</property>
3638-
<property name="sizeHint" stdset="0">
3639-
<size>
3640-
<width>20</width>
3641-
<height>40</height>
3642-
</size>
3643-
</property>
3644-
</spacer>
3645-
</item>
3646-
<item row="2" column="1">
3653+
<item row="3" column="1">
36473654
<widget class="QToolButton" name="mButtonCopyColors">
36483655
<property name="toolTip">
36493656
<string>Copy colors</string>
@@ -3657,26 +3664,26 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
36573664
</property>
36583665
</widget>
36593666
</item>
3660-
<item row="4" column="1">
3661-
<widget class="QToolButton" name="mButtonImportColors">
3667+
<item row="6" column="1">
3668+
<widget class="QToolButton" name="mButtonExportColors">
36623669
<property name="toolTip">
3663-
<string>Import colors from file</string>
3670+
<string>Export colors</string>
36643671
</property>
36653672
<property name="text">
36663673
<string/>
36673674
</property>
36683675
<property name="icon">
36693676
<iconset resource="../../images/images.qrc">
3670-
<normaloff>:/images/themes/default/mActionFileOpen.svg</normaloff>:/images/themes/default/mActionFileOpen.svg</iconset>
3677+
<normaloff>:/images/themes/default/mActionFileSave.svg</normaloff>:/images/themes/default/mActionFileSave.svg</iconset>
36713678
</property>
36723679
</widget>
36733680
</item>
3674-
<item row="0" column="0" rowspan="8">
3675-
<widget class="QgsColorSchemeList" name="mTreeCustomColors" native="true">
3676-
<property name="focusPolicy">
3677-
<enum>Qt::StrongFocus</enum>
3678-
</property>
3679-
</widget>
3681+
<item row="0" column="0">
3682+
<layout class="QHBoxLayout" name="horizontalLayout_22">
3683+
<item>
3684+
<widget class="QComboBox" name="mColorSchemesComboBox"/>
3685+
</item>
3686+
</layout>
36803687
</item>
36813688
</layout>
36823689
</widget>

0 commit comments

Comments
 (0)
Please sign in to comment.