Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dakcarto committed Nov 20, 2012
1 parent 2613cf6 commit bab4395
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -3377,6 +3377,9 @@ bool QgisApp::addProject( QString projectFile )
}
}

// load PAL engine settings
mLBL->loadEngineSettings();

emit projectRead(); // let plug-ins know that we've read in a new
// project so that they can check any project
// specific plug-in state
Expand Down
26 changes: 26 additions & 0 deletions src/app/qgslabelengineconfigdialog.cpp
Expand Up @@ -15,13 +15,18 @@
#include "qgslabelengineconfigdialog.h"

#include "qgspallabeling.h"
#include <pal/pal.h>

#include <QPushButton>

QgsLabelEngineConfigDialog::QgsLabelEngineConfigDialog( QgsPalLabeling* lbl, QWidget* parent )
: QDialog( parent ), mLBL( lbl )
{
setupUi( this );

connect( buttonBox, SIGNAL( accepted() ), this, SLOT( onOK() ) );
connect( buttonBox->button( QDialogButtonBox::RestoreDefaults ), SIGNAL( clicked() ),
this, SLOT( setDefaults() ) );

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

chkShowAllLabels->setChecked( mLBL->isShowingAllLabels() );

mSaveWithProjectChkBox->setChecked( mLBL->isStoredWithProject() );
}


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

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

if ( mSaveWithProjectChkBox->isChecked() )
{
mLBL->saveEngineSettings();
}
else if ( mLBL->isStoredWithProject() )
{
mLBL->clearEngineSettings();
}
accept();
}

void QgsLabelEngineConfigDialog::setDefaults()
{
pal::Pal p;
cboSearchMethod->setCurrentIndex(( int )p.getSearch() );
spinCandPoint->setValue( p.getPointP() );
spinCandLine->setValue( p.getLineP() );
spinCandPolygon->setValue( p.getPolyP() );
chkShowCandidates->setChecked( false );
chkShowAllLabels->setChecked( false );
}
2 changes: 2 additions & 0 deletions src/app/qgslabelengineconfigdialog.h
Expand Up @@ -29,6 +29,8 @@ class QgsLabelEngineConfigDialog : public QDialog, private Ui::QgsEngineConfigDi

public slots:
void onOK();
/** @note Added in QGIS 1.9 */
void setDefaults();

protected:
QgsPalLabeling* mLBL;
Expand Down
43 changes: 43 additions & 0 deletions src/core/qgspallabeling.cpp
Expand Up @@ -49,6 +49,7 @@
#include <qgsvectordataprovider.h>
#include <qgsgeometry.h>
#include <qgsmaprenderer.h>
#include <qgsproject.h>
#include <QMessageBox>

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

void QgsPalLabeling::loadEngineSettings()
{
// start with engine defaults for new project, or project that has no saved settings
Pal p;
bool saved = false;
mSearch = ( QgsPalLabeling::Search )( QgsProject::instance()->readNumEntry(
"PAL", "/SearchMethod", ( int )p.getSearch(), &saved ) );
mCandPoint = QgsProject::instance()->readNumEntry(
"PAL", "/CandidatesPoint", p.getPointP(), &saved );
mCandLine = QgsProject::instance()->readNumEntry(
"PAL", "/CandidatesLine", p.getLineP(), &saved );
mCandPolygon = QgsProject::instance()->readNumEntry(
"PAL", "/CandidatesPolygon", p.getPolyP(), &saved );
mShowingCandidates = QgsProject::instance()->readBoolEntry(
"PAL", "/ShowingCandidates", false, &saved );
mShowingAllLabels = QgsProject::instance()->readBoolEntry(
"PAL", "/ShowingAllLabels", false, &saved );
mSavedWithProject = saved;
}

void QgsPalLabeling::saveEngineSettings()
{
QgsProject::instance()->writeEntry( "PAL", "/SearchMethod", ( int )mSearch );
QgsProject::instance()->writeEntry( "PAL", "/CandidatesPoint", mCandPoint );
QgsProject::instance()->writeEntry( "PAL", "/CandidatesLine", mCandLine );
QgsProject::instance()->writeEntry( "PAL", "/CandidatesPolygon", mCandPolygon );
QgsProject::instance()->writeEntry( "PAL", "/ShowingCandidates", mShowingCandidates );
QgsProject::instance()->writeEntry( "PAL", "/ShowingAllLabels", mShowingAllLabels );
mSavedWithProject = true;
}

void QgsPalLabeling::clearEngineSettings()
{
QgsProject::instance()->removeEntry( "PAL", "/SearchMethod" );
QgsProject::instance()->removeEntry( "PAL", "/CandidatesPoint" );
QgsProject::instance()->removeEntry( "PAL", "/CandidatesLine" );
QgsProject::instance()->removeEntry( "PAL", "/CandidatesPolygon" );
QgsProject::instance()->removeEntry( "PAL", "/ShowingCandidates" );
QgsProject::instance()->removeEntry( "PAL", "/ShowingAllLabels" );
mSavedWithProject = false;
}

QgsLabelingEngineInterface* QgsPalLabeling::clone()
{
QgsPalLabeling* lbl = new QgsPalLabeling();
Expand Down
10 changes: 10 additions & 0 deletions src/core/qgspallabeling.h
Expand Up @@ -314,6 +314,14 @@ class CORE_EXPORT QgsPalLabeling : public QgsLabelingEngineInterface
const QColor& bufferColor = QColor( 255, 255, 255 ), bool drawBuffer = false );
static void drawLabelBuffer( QPainter* p, QString text, const QFont& font, double size, QColor color , Qt::PenJoinStyle joinstyle = Qt::BevelJoin, bool noFill = false );

//! load/save engine settings to project file
//! @note added in QGIS 1.9
void loadEngineSettings();
void saveEngineSettings();
void clearEngineSettings();
bool isStoredWithProject() const { return mSavedWithProject; }
void setStoredWithProject( bool store ) { mSavedWithProject = store; }

protected:
// hashtable of layer settings, being filled during labeling
QHash<QgsVectorLayer*, QgsPalLayerSettings> mActiveLayers;
Expand All @@ -333,6 +341,8 @@ class CORE_EXPORT QgsPalLabeling : public QgsLabelingEngineInterface

bool mShowingAllLabels; // whether to avoid collisions or not

bool mSavedWithProject; // whether engine settings have been read from project file

QgsLabelSearchTree* mLabelSearchTree;
};

Expand Down
71 changes: 59 additions & 12 deletions src/ui/qgsengineconfigdialog.ui
Expand Up @@ -6,10 +6,16 @@
<rect>
<x>0</x>
<y>0</y>
<width>316</width>
<height>328</height>
<width>336</width>
<height>352</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>336</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
Expand Down Expand Up @@ -209,14 +215,49 @@
<property name="verticalSpacing">
<number>6</number>
</property>
<item row="0" column="1">
<widget class="QLabel" name="label_5">
<item row="1" column="0">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>8</width>
<height>8</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Show all labels and features for all layers</string>
<string>(i.e. including colliding objects)</string>
</property>
</widget>
</item>
<item row="0" column="0">
<item row="1" column="2">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="3">
<widget class="QCheckBox" name="chkShowAllLabels">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
Expand All @@ -225,21 +266,27 @@
</sizepolicy>
</property>
<property name="text">
<string/>
<string>Show all labels and features for all layers</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<item row="2" column="0" colspan="3">
<widget class="QCheckBox" name="chkShowCandidates">
<property name="text">
<string>Show candidates (for debugging)</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_6">
<item row="3" column="0" colspan="3">
<widget class="QCheckBox" name="mSaveWithProjectChkBox">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>(i.e. including colliding objects)</string>
<string>Save settings with project</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
Expand All @@ -264,7 +311,7 @@
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults</set>
</property>
</widget>
</item>
Expand Down

0 comments on commit bab4395

Please sign in to comment.