Skip to content

Commit bab4395

Browse files
committedNov 20, 2012
Add ability to save PAL engine settings to project file (OFF by default)
- Add 'Save settings with project' checkbox to engine settings dialog - Add Restore Defaults button to engine settings dialog - Unchecking 'save with project' will clear settings in project file on save
1 parent 2613cf6 commit bab4395

File tree

6 files changed

+143
-12
lines changed

6 files changed

+143
-12
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3377,6 +3377,9 @@ bool QgisApp::addProject( QString projectFile )
33773377
}
33783378
}
33793379

3380+
// load PAL engine settings
3381+
mLBL->loadEngineSettings();
3382+
33803383
emit projectRead(); // let plug-ins know that we've read in a new
33813384
// project so that they can check any project
33823385
// specific plug-in state

‎src/app/qgslabelengineconfigdialog.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@
1515
#include "qgslabelengineconfigdialog.h"
1616

1717
#include "qgspallabeling.h"
18+
#include <pal/pal.h>
19+
20+
#include <QPushButton>
1821

1922
QgsLabelEngineConfigDialog::QgsLabelEngineConfigDialog( QgsPalLabeling* lbl, QWidget* parent )
2023
: QDialog( parent ), mLBL( lbl )
2124
{
2225
setupUi( this );
2326

2427
connect( buttonBox, SIGNAL( accepted() ), this, SLOT( onOK() ) );
28+
connect( buttonBox->button( QDialogButtonBox::RestoreDefaults ), SIGNAL( clicked() ),
29+
this, SLOT( setDefaults() ) );
2530

2631
// search method
2732
cboSearchMethod->setCurrentIndex( mLBL->searchMethod() );
@@ -36,6 +41,8 @@ QgsLabelEngineConfigDialog::QgsLabelEngineConfigDialog( QgsPalLabeling* lbl, QWi
3641
chkShowCandidates->setChecked( mLBL->isShowingCandidates() );
3742

3843
chkShowAllLabels->setChecked( mLBL->isShowingAllLabels() );
44+
45+
mSaveWithProjectChkBox->setChecked( mLBL->isStoredWithProject() );
3946
}
4047

4148

@@ -52,5 +59,24 @@ void QgsLabelEngineConfigDialog::onOK()
5259

5360
mLBL->setShowingAllLabels( chkShowAllLabels->isChecked() );
5461

62+
if ( mSaveWithProjectChkBox->isChecked() )
63+
{
64+
mLBL->saveEngineSettings();
65+
}
66+
else if ( mLBL->isStoredWithProject() )
67+
{
68+
mLBL->clearEngineSettings();
69+
}
5570
accept();
5671
}
72+
73+
void QgsLabelEngineConfigDialog::setDefaults()
74+
{
75+
pal::Pal p;
76+
cboSearchMethod->setCurrentIndex(( int )p.getSearch() );
77+
spinCandPoint->setValue( p.getPointP() );
78+
spinCandLine->setValue( p.getLineP() );
79+
spinCandPolygon->setValue( p.getPolyP() );
80+
chkShowCandidates->setChecked( false );
81+
chkShowAllLabels->setChecked( false );
82+
}

‎src/app/qgslabelengineconfigdialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class QgsLabelEngineConfigDialog : public QDialog, private Ui::QgsEngineConfigDi
2929

3030
public slots:
3131
void onOK();
32+
/** @note Added in QGIS 1.9 */
33+
void setDefaults();
3234

3335
protected:
3436
QgsPalLabeling* mLBL;

‎src/core/qgspallabeling.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include <qgsvectordataprovider.h>
5050
#include <qgsgeometry.h>
5151
#include <qgsmaprenderer.h>
52+
#include <qgsproject.h>
5253
#include <QMessageBox>
5354

5455
using namespace pal;
@@ -1929,6 +1930,48 @@ void QgsPalLabeling::drawLabelBuffer( QPainter* p, QString text, const QFont& fo
19291930
p->drawPath( path );
19301931
}
19311932

1933+
void QgsPalLabeling::loadEngineSettings()
1934+
{
1935+
// start with engine defaults for new project, or project that has no saved settings
1936+
Pal p;
1937+
bool saved = false;
1938+
mSearch = ( QgsPalLabeling::Search )( QgsProject::instance()->readNumEntry(
1939+
"PAL", "/SearchMethod", ( int )p.getSearch(), &saved ) );
1940+
mCandPoint = QgsProject::instance()->readNumEntry(
1941+
"PAL", "/CandidatesPoint", p.getPointP(), &saved );
1942+
mCandLine = QgsProject::instance()->readNumEntry(
1943+
"PAL", "/CandidatesLine", p.getLineP(), &saved );
1944+
mCandPolygon = QgsProject::instance()->readNumEntry(
1945+
"PAL", "/CandidatesPolygon", p.getPolyP(), &saved );
1946+
mShowingCandidates = QgsProject::instance()->readBoolEntry(
1947+
"PAL", "/ShowingCandidates", false, &saved );
1948+
mShowingAllLabels = QgsProject::instance()->readBoolEntry(
1949+
"PAL", "/ShowingAllLabels", false, &saved );
1950+
mSavedWithProject = saved;
1951+
}
1952+
1953+
void QgsPalLabeling::saveEngineSettings()
1954+
{
1955+
QgsProject::instance()->writeEntry( "PAL", "/SearchMethod", ( int )mSearch );
1956+
QgsProject::instance()->writeEntry( "PAL", "/CandidatesPoint", mCandPoint );
1957+
QgsProject::instance()->writeEntry( "PAL", "/CandidatesLine", mCandLine );
1958+
QgsProject::instance()->writeEntry( "PAL", "/CandidatesPolygon", mCandPolygon );
1959+
QgsProject::instance()->writeEntry( "PAL", "/ShowingCandidates", mShowingCandidates );
1960+
QgsProject::instance()->writeEntry( "PAL", "/ShowingAllLabels", mShowingAllLabels );
1961+
mSavedWithProject = true;
1962+
}
1963+
1964+
void QgsPalLabeling::clearEngineSettings()
1965+
{
1966+
QgsProject::instance()->removeEntry( "PAL", "/SearchMethod" );
1967+
QgsProject::instance()->removeEntry( "PAL", "/CandidatesPoint" );
1968+
QgsProject::instance()->removeEntry( "PAL", "/CandidatesLine" );
1969+
QgsProject::instance()->removeEntry( "PAL", "/CandidatesPolygon" );
1970+
QgsProject::instance()->removeEntry( "PAL", "/ShowingCandidates" );
1971+
QgsProject::instance()->removeEntry( "PAL", "/ShowingAllLabels" );
1972+
mSavedWithProject = false;
1973+
}
1974+
19321975
QgsLabelingEngineInterface* QgsPalLabeling::clone()
19331976
{
19341977
QgsPalLabeling* lbl = new QgsPalLabeling();

‎src/core/qgspallabeling.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,14 @@ class CORE_EXPORT QgsPalLabeling : public QgsLabelingEngineInterface
314314
const QColor& bufferColor = QColor( 255, 255, 255 ), bool drawBuffer = false );
315315
static void drawLabelBuffer( QPainter* p, QString text, const QFont& font, double size, QColor color , Qt::PenJoinStyle joinstyle = Qt::BevelJoin, bool noFill = false );
316316

317+
//! load/save engine settings to project file
318+
//! @note added in QGIS 1.9
319+
void loadEngineSettings();
320+
void saveEngineSettings();
321+
void clearEngineSettings();
322+
bool isStoredWithProject() const { return mSavedWithProject; }
323+
void setStoredWithProject( bool store ) { mSavedWithProject = store; }
324+
317325
protected:
318326
// hashtable of layer settings, being filled during labeling
319327
QHash<QgsVectorLayer*, QgsPalLayerSettings> mActiveLayers;
@@ -333,6 +341,8 @@ class CORE_EXPORT QgsPalLabeling : public QgsLabelingEngineInterface
333341

334342
bool mShowingAllLabels; // whether to avoid collisions or not
335343

344+
bool mSavedWithProject; // whether engine settings have been read from project file
345+
336346
QgsLabelSearchTree* mLabelSearchTree;
337347
};
338348

‎src/ui/qgsengineconfigdialog.ui

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>316</width>
10-
<height>328</height>
9+
<width>336</width>
10+
<height>352</height>
1111
</rect>
1212
</property>
13+
<property name="minimumSize">
14+
<size>
15+
<width>336</width>
16+
<height>0</height>
17+
</size>
18+
</property>
1319
<property name="windowTitle">
1420
<string>Dialog</string>
1521
</property>
@@ -209,14 +215,49 @@
209215
<property name="verticalSpacing">
210216
<number>6</number>
211217
</property>
212-
<item row="0" column="1">
213-
<widget class="QLabel" name="label_5">
218+
<item row="1" column="0">
219+
<spacer name="horizontalSpacer_3">
220+
<property name="orientation">
221+
<enum>Qt::Horizontal</enum>
222+
</property>
223+
<property name="sizeType">
224+
<enum>QSizePolicy::Fixed</enum>
225+
</property>
226+
<property name="sizeHint" stdset="0">
227+
<size>
228+
<width>8</width>
229+
<height>8</height>
230+
</size>
231+
</property>
232+
</spacer>
233+
</item>
234+
<item row="1" column="1">
235+
<widget class="QLabel" name="label_6">
236+
<property name="sizePolicy">
237+
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
238+
<horstretch>0</horstretch>
239+
<verstretch>0</verstretch>
240+
</sizepolicy>
241+
</property>
214242
<property name="text">
215-
<string>Show all labels and features for all layers</string>
243+
<string>(i.e. including colliding objects)</string>
216244
</property>
217245
</widget>
218246
</item>
219-
<item row="0" column="0">
247+
<item row="1" column="2">
248+
<spacer name="horizontalSpacer_4">
249+
<property name="orientation">
250+
<enum>Qt::Horizontal</enum>
251+
</property>
252+
<property name="sizeHint" stdset="0">
253+
<size>
254+
<width>40</width>
255+
<height>20</height>
256+
</size>
257+
</property>
258+
</spacer>
259+
</item>
260+
<item row="0" column="0" colspan="3">
220261
<widget class="QCheckBox" name="chkShowAllLabels">
221262
<property name="sizePolicy">
222263
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
@@ -225,21 +266,27 @@
225266
</sizepolicy>
226267
</property>
227268
<property name="text">
228-
<string/>
269+
<string>Show all labels and features for all layers</string>
229270
</property>
230271
</widget>
231272
</item>
232-
<item row="2" column="0" colspan="2">
273+
<item row="2" column="0" colspan="3">
233274
<widget class="QCheckBox" name="chkShowCandidates">
234275
<property name="text">
235276
<string>Show candidates (for debugging)</string>
236277
</property>
237278
</widget>
238279
</item>
239-
<item row="1" column="1">
240-
<widget class="QLabel" name="label_6">
280+
<item row="3" column="0" colspan="3">
281+
<widget class="QCheckBox" name="mSaveWithProjectChkBox">
282+
<property name="layoutDirection">
283+
<enum>Qt::LeftToRight</enum>
284+
</property>
241285
<property name="text">
242-
<string>(i.e. including colliding objects)</string>
286+
<string>Save settings with project</string>
287+
</property>
288+
<property name="checked">
289+
<bool>false</bool>
243290
</property>
244291
</widget>
245292
</item>
@@ -264,7 +311,7 @@
264311
<enum>Qt::Horizontal</enum>
265312
</property>
266313
<property name="standardButtons">
267-
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
314+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults</set>
268315
</property>
269316
</widget>
270317
</item>

0 commit comments

Comments
 (0)
Please sign in to comment.