Skip to content

Commit

Permalink
Replace the row of style-related buttons by a button with context menu
Browse files Browse the repository at this point in the history
This saves vertical space and will allow addition of more actions.

This code has been funded by Tuscany Region (Italy) - SITA (CIG: 6002233F59)
and commissioned to Gis3W s.a.s.
  • Loading branch information
wonder-sk committed Jan 19, 2015
1 parent 7e3bef6 commit 15068e5
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 97 deletions.
10 changes: 10 additions & 0 deletions src/app/qgsrasterlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
// and connecting QDialogButtonBox's accepted/rejected signals to dialog's accept/reject slots
initOptionsBase( false );

QPushButton* b = new QPushButton( tr( "Style" ) );
QMenu* m = new QMenu( this );
m->addAction( tr( "Load Style..." ), this, SLOT( on_pbnLoadStyle_clicked() ) );
m->addAction( tr( "Save Style..." ), this, SLOT( on_pbnSaveStyleAs_clicked() ) );
m->addSeparator();
m->addAction( tr( "Save As Default" ), this, SLOT( on_pbnSaveDefaultStyle_clicked() ) );
m->addAction( tr( "Restore Default" ), this, SLOT( on_pbnLoadDefaultStyle_clicked() ) );
b->setMenu( m );
buttonBox->addButton( b, QDialogButtonBox::ResetRole );

connect( this, SIGNAL( accepted() ), this, SLOT( apply() ) );
connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) );

Expand Down
22 changes: 15 additions & 7 deletions src/app/qgsvectorlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
// and connecting QDialogButtonBox's accepted/rejected signals to dialog's accept/reject slots
initOptionsBase( false );


QPushButton* b = new QPushButton( tr( "Style" ) );
QMenu* m = new QMenu( this );
mActionLoadStyle = m->addAction( tr( "Load Style..." ), this, SLOT( on_pbnLoadStyle_clicked() ) );
mActionSaveStyleAs = m->addAction( tr( "Save Style..." ), this, SLOT( on_pbnSaveStyleAs_clicked() ) );
m->addSeparator();
m->addAction( tr( "Save As Default" ), this, SLOT( on_pbnSaveDefaultStyle_clicked() ) );
m->addAction( tr( "Restore Default" ), this, SLOT( on_pbnLoadDefaultStyle_clicked() ) );
b->setMenu( m );
buttonBox->addButton( b, QDialogButtonBox::ResetRole );

connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) );
connect( this, SIGNAL( accepted() ), this, SLOT( apply() ) );
Expand Down Expand Up @@ -136,7 +144,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
actionLayout->addWidget( actionDialog );

// Create the menu for the save style button to choose the output format
mSaveAsMenu = new QMenu( pbnSaveStyleAs );
mSaveAsMenu = new QMenu( this );
mSaveAsMenu->addAction( tr( "QGIS Layer Style File" ) );
mSaveAsMenu->addAction( tr( "SLD File" ) );

Expand All @@ -147,8 +155,8 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
mLoadStyleMenu = new QMenu();
mLoadStyleMenu->addAction( tr( "Load from file" ) );
mLoadStyleMenu->addAction( tr( "Load from database" ) );
pbnLoadStyle->setContextMenuPolicy( Qt::PreventContextMenu );
pbnLoadStyle->setMenu( mLoadStyleMenu );
//mActionLoadStyle->setContextMenuPolicy( Qt::PreventContextMenu );
mActionLoadStyle->setMenu( mLoadStyleMenu );

QObject::connect( mLoadStyleMenu, SIGNAL( triggered( QAction * ) ),
this, SLOT( loadStyleMenuTriggered( QAction * ) ) );
Expand Down Expand Up @@ -1066,9 +1074,9 @@ void QgsVectorLayerProperties::updateSymbologyPage()
mRendererDialog = new QgsRendererV2PropertiesDialog( layer, QgsStyleV2::defaultStyle(), true );

// display the menu to choose the output format (fix #5136)
pbnSaveStyleAs->setText( tr( "Save Style" ) );
pbnSaveStyleAs->setMenu( mSaveAsMenu );
QObject::disconnect( pbnSaveStyleAs, SIGNAL( clicked() ), this, SLOT( on_pbnSaveStyleAs_clicked() ) );
mActionSaveStyleAs->setText( tr( "Save Style" ) );
mActionSaveStyleAs->setMenu( mSaveAsMenu );
QObject::disconnect( mActionSaveStyleAs, SIGNAL( triggered() ), this, SLOT( on_pbnSaveStyleAs_clicked() ) );
}
else
{
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsvectorlayerproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
QMenu *mSaveAsMenu;
QMenu *mLoadStyleMenu;

QAction* mActionLoadStyle;
QAction* mActionSaveStyleAs;

/**Renderer dialog which is shown*/
QDialog* mRendererDialog;
/**Labeling dialog. If apply is pressed, options are applied to vector's QgsLabel */
Expand Down
68 changes: 18 additions & 50 deletions src/ui/qgsrasterlayerpropertiesbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>615</width>
<height>509</height>
<width>628</width>
<height>551</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
Expand Down Expand Up @@ -353,12 +353,12 @@
<string notr="true">rastergeneral</string>
</property>
<layout class="QGridLayout" name="_5">
<property name="margin">
<number>11</number>
</property>
<property name="verticalSpacing">
<number>6</number>
</property>
<property name="margin">
<number>11</number>
</property>
<item row="0" column="0" colspan="2">
<widget class="QgsScaleRangeWidget" name="mScaleRangeWidget" native="true">
<property name="toolTip">
Expand Down Expand Up @@ -409,8 +409,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>615</width>
<height>509</height>
<width>540</width>
<height>516</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_10">
Expand Down Expand Up @@ -1031,8 +1031,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>472</width>
<height>395</height>
<width>500</width>
<height>401</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
Expand Down Expand Up @@ -1438,8 +1438,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>205</height>
<width>658</width>
<height>185</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
Expand Down Expand Up @@ -1502,8 +1502,8 @@
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Cantarell';&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:13pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Cantarell'; font-size:11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -1599,8 +1599,8 @@ p, li { white-space: pre-wrap; }
<rect>
<x>0</x>
<y>0</y>
<width>84</width>
<height>36</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_16">
Expand Down Expand Up @@ -1649,8 +1649,8 @@ p, li { white-space: pre-wrap; }
<rect>
<x>0</x>
<y>0</y>
<width>393</width>
<height>608</height>
<width>411</width>
<height>630</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_12">
Expand Down Expand Up @@ -1994,35 +1994,7 @@ p, li { white-space: pre-wrap; }
<property name="margin">
<number>0</number>
</property>
<item row="0" column="1">
<widget class="QPushButton" name="pbnSaveDefaultStyle">
<property name="text">
<string>Save As Default</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="pbnLoadStyle">
<property name="text">
<string>Load Style...</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="pbnLoadDefaultStyle">
<property name="text">
<string>Restore Default Style</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="pbnSaveStyleAs">
<property name="text">
<string>Save Style...</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<item row="0" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand Down Expand Up @@ -2067,10 +2039,6 @@ p, li { white-space: pre-wrap; }
</customwidget>
</customwidgets>
<tabstops>
<tabstop>pbnSaveDefaultStyle</tabstop>
<tabstop>pbnLoadStyle</tabstop>
<tabstop>pbnLoadDefaultStyle</tabstop>
<tabstop>pbnSaveStyleAs</tabstop>
<tabstop>buttonBox</tabstop>
<tabstop>mOptionsListWidget</tabstop>
<tabstop>scrollArea_3</tabstop>
Expand Down
48 changes: 8 additions & 40 deletions src/ui/qgsvectorlayerpropertiesbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>730</width>
<height>502</height>
<width>743</width>
<height>546</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_13">
Expand Down Expand Up @@ -618,8 +618,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>121</width>
<height>38</height>
<width>129</width>
<height>35</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_28">
Expand Down Expand Up @@ -867,8 +867,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>476</width>
<height>182</height>
<width>530</width>
<height>189</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_26">
Expand Down Expand Up @@ -1216,8 +1216,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>393</width>
<height>608</height>
<width>411</width>
<height>630</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_3">
Expand Down Expand Up @@ -1546,38 +1546,6 @@
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QPushButton" name="pbnLoadStyle">
<property name="text">
<string>Load Style...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbnSaveDefaultStyle">
<property name="text">
<string>Save As Default</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbnLoadDefaultStyle">
<property name="text">
<string>Restore Default Style</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbnSaveStyleAs">
<property name="text">
<string>Save Style...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
Expand Down

0 comments on commit 15068e5

Please sign in to comment.