Skip to content

Commit a033d47

Browse files
committed
[FEATURE] add new labeling to vector layer properties
- add 'deprecated' label to old labeling in vector layer properties
1 parent 511e89c commit a033d47

8 files changed

+91
-75
lines changed

src/app/qgisapp.cpp

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,12 @@ QgsMapCanvas *QgisApp::mapCanvas()
18841884
return mMapCanvas;
18851885
}
18861886

1887+
QgsPalLabeling *QgisApp::palLabeling()
1888+
{
1889+
Q_ASSERT( mLBL );
1890+
return mLBL;
1891+
}
1892+
18871893
void QgisApp::initLegend()
18881894
{
18891895
mMapLegend->setWhatsThis( tr( "Map legend that displays all the layers currently on the map canvas. Click on the check box to turn a layer on or off. Double click on a layer in the legend to customize its appearance and set other properties." ) );
@@ -3842,14 +3848,36 @@ void QgisApp::labeling()
38423848
QMessageBox::warning( this, tr( "Labeling" ), tr( "Please select a vector layer first." ) );
38433849
return;
38443850
}
3851+
38453852
QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( layer );
38463853

3847-
QgsLabelingGui labelGui( mLBL, vlayer, mMapCanvas, this );
3854+
QDialog *dlg = new QDialog( this );
3855+
dlg->setWindowTitle( tr( "Layer labeling settings" ) );
3856+
QgsLabelingGui *labelingGui = new QgsLabelingGui( mLBL, vlayer, mMapCanvas, dlg );
3857+
3858+
QVBoxLayout *layout = new QVBoxLayout( dlg );
3859+
layout->addWidget( labelingGui );
3860+
3861+
QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply, Qt::Horizontal, dlg );
3862+
layout->addWidget( buttonBox );
3863+
3864+
dlg->setLayout( layout );
38483865

3849-
if ( labelGui.exec() )
3866+
QSettings settings;
3867+
dlg->restoreGeometry( settings.value( "/Windows/Labeling/geometry" ).toByteArray() );
3868+
3869+
connect( buttonBox->button( QDialogButtonBox::Ok ), SIGNAL( clicked() ), dlg, SLOT( accept() ) );
3870+
connect( buttonBox->button( QDialogButtonBox::Cancel ), SIGNAL( clicked() ), dlg, SLOT( reject() ) );
3871+
connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), labelingGui, SLOT( apply() ) );
3872+
3873+
if ( dlg->exec() )
38503874
{
3875+
labelingGui->apply();
3876+
3877+
settings.setValue( "/Windows/Labeling/geometry", dlg->saveGeometry() );
3878+
38513879
// alter labeling - save the changes
3852-
labelGui.layerSettings().writeToLayer( vlayer );
3880+
labelingGui->layerSettings().writeToLayer( vlayer );
38533881

38543882
// trigger refresh
38553883
if ( mMapCanvas )
@@ -3858,6 +3886,8 @@ void QgisApp::labeling()
38583886
}
38593887
}
38603888

3889+
delete dlg;
3890+
38613891
activateDeactivateLayerRelatedActions( layer );
38623892
}
38633893

src/app/qgisapp.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,12 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
161161
void openFile( const QString & fileName );
162162
//!Overloaded version of the private function with same name that takes the imagename as a parameter
163163
void saveMapAsImage( QString, QPixmap * );
164+
165+
/** Get the mapcanvas object from the app */
166+
QgsMapCanvas *mapCanvas();
167+
164168
/** Get the mapcanvas object from the app */
165-
QgsMapCanvas * mapCanvas();
169+
QgsPalLabeling *palLabeling();
166170

167171
//! Set theme (icons)
168172
void setTheme( QString themeName = "default" );

src/app/qgslabelinggui.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
#include <qgsvectordataprovider.h>
2323
#include <qgsmaplayerregistry.h>
2424

25-
#include "qgspallabeling.h"
2625
#include "qgslabelengineconfigdialog.h"
2726
#include "qgsexpressionbuilderdialog.h"
2827
#include "qgsexpression.h"
28+
#include "qgsmapcanvas.h"
2929

3030
#include <QColorDialog>
3131
#include <QFontDialog>
@@ -34,16 +34,14 @@
3434
#include <QMessageBox>
3535
#include <QSettings>
3636

37+
3738
QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, QWidget* parent )
38-
: QDialog( parent ), mLBL( lbl ), mLayer( layer ), mMapCanvas( mapCanvas )
39+
: QWidget( parent ), mLBL( lbl ), mLayer( layer ), mMapCanvas( mapCanvas )
3940
{
4041
if ( !layer ) return;
4142

4243
setupUi( this );
4344

44-
QSettings settings;
45-
restoreGeometry( settings.value( "/Windows/Labeling/geometry" ).toByteArray() );
46-
4745
connect( btnTextColor, SIGNAL( clicked() ), this, SLOT( changeTextColor() ) );
4846
connect( btnChangeFont, SIGNAL( clicked() ), this, SLOT( changeTextFont() ) );
4947
connect( chkBuffer, SIGNAL( toggled( bool ) ), this, SLOT( updatePreview() ) );
@@ -206,13 +204,10 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
206204
{
207205
connect( placementRadios[i], SIGNAL( toggled( bool ) ), this, SLOT( updateOptions() ) );
208206
}
209-
connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) );
210207
}
211208

212209
QgsLabelingGui::~QgsLabelingGui()
213210
{
214-
QSettings settings;
215-
settings.setValue( "/Windows/Labeling/geometry", saveGeometry() );
216211
}
217212

218213
void QgsLabelingGui::apply()

src/app/qgslabelinggui.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ class QgsMapCanvas;
2626

2727
#include "qgspallabeling.h"
2828

29-
class QgsLabelingGui : public QDialog, private Ui::QgsLabelingGuiBase
29+
class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
3030
{
3131
Q_OBJECT
3232

3333
public:
34-
QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, QWidget* parent );
34+
QgsLabelingGui( QgsPalLabeling *lbl, QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, QWidget* parent );
3535
~QgsLabelingGui();
3636

3737
QgsPalLayerSettings layerSettings();

src/app/qgsvectorlayerproperties.cpp

100644100755
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "qgsfieldcalculator.h"
3333
#include "qgsgraduatedsymboldialog.h"
3434
#include "qgslabeldialog.h"
35+
#include "qgslabelinggui.h"
3536
#include "qgslabel.h"
3637
#include "qgsgenericprojectionselector.h"
3738
#include "qgslogger.h"
@@ -98,16 +99,21 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
9899
connect( insertFieldButton, SIGNAL( clicked() ), this, SLOT( insertField() ) );
99100
connect( insertExpressionButton, SIGNAL( clicked() ), this, SLOT( insertExpression() ) );
100101

101-
102102
mAddAttributeButton->setIcon( QgsApplication::getThemeIcon( "/mActionNewAttribute.png" ) );
103103
mDeleteAttributeButton->setIcon( QgsApplication::getThemeIcon( "/mActionDeleteAttribute.png" ) );
104104
mToggleEditingButton->setIcon( QgsApplication::getThemeIcon( "/mActionToggleEditing.png" ) );
105105
mCalculateFieldButton->setIcon( QgsApplication::getThemeIcon( "/mActionCalculateField.png" ) );
106106

107107
connect( btnUseNewSymbology, SIGNAL( clicked() ), this, SLOT( useNewSymbology() ) );
108108

109+
QVBoxLayout *layout = new QVBoxLayout( labelingFrame );
110+
layout->setMargin( 0 );
111+
labelingDialog = new QgsLabelingGui( QgisApp::instance()->palLabeling(), layer, QgisApp::instance()->mapCanvas(), labelingFrame );
112+
layout->addWidget( labelingDialog );
113+
labelingFrame->setLayout( layout );
114+
109115
// Create the Label dialog tab
110-
QVBoxLayout *layout = new QVBoxLayout( labelOptionsFrame );
116+
layout = new QVBoxLayout( labelOptionsFrame );
111117
layout->setMargin( 0 );
112118
labelDialog = new QgsLabelDialog( layer->label(), labelOptionsFrame );
113119
layout->addWidget( labelDialog );
@@ -657,6 +663,8 @@ QgsVectorLayer::EditType QgsVectorLayerProperties::editTypeFromButtonText( QStri
657663

658664
void QgsVectorLayerProperties::apply()
659665
{
666+
labelingDialog->apply();
667+
660668
//
661669
// Set up sql subset query if applicable
662670
//

src/app/qgsvectorlayerproperties.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class QgsApplyDialog;
3737
class QgsLabelDialog;
3838
class QgsVectorLayer;
3939
class QgsVectorOverlayPlugin;
40+
class QgsLabelingGui;
4041

4142
class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPropertiesBase
4243
{
@@ -185,6 +186,8 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope
185186
QDialog* mRendererDialog;
186187
/**Buffer renderer, which is assigned to the vector layer when apply is pressed*/
187188
//QgsRenderer* bufferRenderer;
189+
/**Labeling dialog. If apply is pressed, options are applied to vector's QgsLabel */
190+
QgsLabelingGui *labelingDialog;
188191
/**Label dialog. If apply is pressed, options are applied to vector's QgsLabel */
189192
QgsLabelDialog* labelDialog;
190193
/**Actions dialog. If apply is pressed, the actions are stored for later use */

src/ui/qgslabelingguibase.ui

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<ui version="4.0">
33
<class>QgsLabelingGuiBase</class>
4-
<widget class="QDialog" name="QgsLabelingGuiBase">
4+
<widget class="QWidget" name="QgsLabelingGuiBase">
55
<property name="geometry">
66
<rect>
77
<x>0</x>
@@ -63,16 +63,6 @@
6363
</item>
6464
</layout>
6565
</item>
66-
<item row="3" column="0">
67-
<widget class="QDialogButtonBox" name="buttonBox">
68-
<property name="orientation">
69-
<enum>Qt::Horizontal</enum>
70-
</property>
71-
<property name="standardButtons">
72-
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
73-
</property>
74-
</widget>
75-
</item>
7666
<item row="0" column="0">
7767
<layout class="QHBoxLayout" name="horizontalLayout_3">
7868
<item>
@@ -473,8 +463,8 @@
473463
<rect>
474464
<x>0</x>
475465
<y>0</y>
476-
<width>658</width>
477-
<height>451</height>
466+
<width>647</width>
467+
<height>435</height>
478468
</rect>
479469
</property>
480470
<layout class="QGridLayout" name="gridLayout_13">
@@ -935,8 +925,8 @@
935925
<rect>
936926
<x>0</x>
937927
<y>0</y>
938-
<width>658</width>
939-
<height>567</height>
928+
<width>647</width>
929+
<height>507</height>
940930
</rect>
941931
</property>
942932
<layout class="QGridLayout" name="gridLayout_11">
@@ -1146,45 +1136,10 @@
11461136
<header>qgslabelpreview.h</header>
11471137
</customwidget>
11481138
</customwidgets>
1149-
<tabstops>
1150-
<tabstop>buttonBox</tabstop>
1151-
</tabstops>
11521139
<resources>
11531140
<include location="../../images/images.qrc"/>
11541141
</resources>
11551142
<connections>
1156-
<connection>
1157-
<sender>buttonBox</sender>
1158-
<signal>accepted()</signal>
1159-
<receiver>QgsLabelingGuiBase</receiver>
1160-
<slot>accept()</slot>
1161-
<hints>
1162-
<hint type="sourcelabel">
1163-
<x>353</x>
1164-
<y>459</y>
1165-
</hint>
1166-
<hint type="destinationlabel">
1167-
<x>309</x>
1168-
<y>430</y>
1169-
</hint>
1170-
</hints>
1171-
</connection>
1172-
<connection>
1173-
<sender>buttonBox</sender>
1174-
<signal>rejected()</signal>
1175-
<receiver>QgsLabelingGuiBase</receiver>
1176-
<slot>reject()</slot>
1177-
<hints>
1178-
<hint type="sourcelabel">
1179-
<x>353</x>
1180-
<y>459</y>
1181-
</hint>
1182-
<hint type="destinationlabel">
1183-
<x>353</x>
1184-
<y>430</y>
1185-
</hint>
1186-
</hints>
1187-
</connection>
11881143
<connection>
11891144
<sender>chkEnableLabeling</sender>
11901145
<signal>clicked(bool)</signal>

src/ui/qgsvectorlayerpropertiesbase.ui

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
<item row="1" column="0">
6767
<widget class="QTabWidget" name="tabWidget">
6868
<property name="currentIndex">
69-
<number>3</number>
69+
<number>2</number>
7070
</property>
7171
<property name="iconSize">
7272
<size>
@@ -184,14 +184,35 @@
184184
</item>
185185
</layout>
186186
</widget>
187-
<widget class="QWidget" name="tabWidgetPage2">
187+
<widget class="QWidget" name="labelingTab">
188188
<attribute name="icon">
189189
<iconset resource="../../images/images.qrc">
190190
<normaloff>:/images/themes/default/propertyicons/labels.png</normaloff>:/images/themes/default/propertyicons/labels.png</iconset>
191191
</attribute>
192192
<attribute name="title">
193193
<string>Labels</string>
194194
</attribute>
195+
<layout class="QGridLayout" name="gridLayout_47">
196+
<item row="0" column="0">
197+
<widget class="QFrame" name="labelingFrame">
198+
<property name="frameShape">
199+
<enum>QFrame::NoFrame</enum>
200+
</property>
201+
<property name="frameShadow">
202+
<enum>QFrame::Plain</enum>
203+
</property>
204+
</widget>
205+
</item>
206+
</layout>
207+
</widget>
208+
<widget class="QWidget" name="tabWidgetPage2">
209+
<attribute name="icon">
210+
<iconset resource="../../images/images.qrc">
211+
<normaloff>:/images/themes/default/propertyicons/labels.png</normaloff>:/images/themes/default/propertyicons/labels.png</iconset>
212+
</attribute>
213+
<attribute name="title">
214+
<string>Labels (deprecated)</string>
215+
</attribute>
195216
<layout class="QGridLayout" name="gridLayout_5">
196217
<item row="0" column="0">
197218
<widget class="QCheckBox" name="labelCheckBox">
@@ -371,7 +392,7 @@
371392
<x>0</x>
372393
<y>0</y>
373394
<width>740</width>
374-
<height>548</height>
395+
<height>558</height>
375396
</rect>
376397
</property>
377398
<layout class="QGridLayout" name="gridLayout_3">
@@ -739,8 +760,8 @@
739760
<rect>
740761
<x>0</x>
741762
<y>0</y>
742-
<width>98</width>
743-
<height>231</height>
763+
<width>722</width>
764+
<height>540</height>
744765
</rect>
745766
</property>
746767
<layout class="QVBoxLayout" name="verticalLayout">
@@ -851,8 +872,8 @@
851872
<rect>
852873
<x>0</x>
853874
<y>0</y>
854-
<width>106</width>
855-
<height>129</height>
875+
<width>722</width>
876+
<height>540</height>
856877
</rect>
857878
</property>
858879
<layout class="QGridLayout" name="gridLayout_17">
@@ -944,8 +965,8 @@
944965
<rect>
945966
<x>0</x>
946967
<y>0</y>
947-
<width>590</width>
948-
<height>626</height>
968+
<width>706</width>
969+
<height>574</height>
949970
</rect>
950971
</property>
951972
<layout class="QGridLayout" name="gridLayout_16">

0 commit comments

Comments
 (0)