Skip to content
Permalink
Browse files
Added engine configuration dialog. It's possible to set number of can…
…didate labels that will be generated for every feature and the search method.

git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@10888 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jun 5, 2009
1 parent 9e111fb commit 02d5b93
Show file tree
Hide file tree
Showing 9 changed files with 325 additions and 2 deletions.
@@ -6,13 +6,15 @@ SET (labeling_SRCS
labeling.cpp
labelinggui.cpp
pallabeling.cpp
engineconfigdialog.cpp
)

SET (labeling_UIS labelingguibase.ui)
SET (labeling_UIS labelingguibase.ui engineconfigdialog.ui)

SET (labeling_MOC_HDRS
labeling.h
labelinggui.h
engineconfigdialog.h
)

SET (labeling_RCCS labeling.qrc)
@@ -0,0 +1,34 @@
#include "engineconfigdialog.h"

#include "pallabeling.h"

EngineConfigDialog::EngineConfigDialog(PalLabeling* lbl, QWidget* parent)
: QDialog(parent), mLBL(lbl)
{
setupUi(this);

connect(buttonBox, SIGNAL(accepted()), this, SLOT(onOK()) );

// search method
cboSearchMethod->setCurrentIndex( mLBL->searchMethod() );

// candidate numbers
int candPoint, candLine, candPolygon;
mLBL->numCandidatePositions(candPoint, candLine, candPolygon);
spinCandPoint->setValue(candPoint);
spinCandLine->setValue(candLine);
spinCandPolygon->setValue(candPolygon);
}


void EngineConfigDialog::onOK()
{
// save
mLBL->setSearchMethod( (PalLabeling::Search) cboSearchMethod->currentIndex() );

mLBL->setNumCandidatePositions(spinCandPoint->value(),
spinCandLine->value(),
spinCandPolygon->value());

accept();
}
@@ -0,0 +1,23 @@
#ifndef ENGINECONFIGDIALOG_H
#define ENGINECONFIGDIALOG_H

#include <QDialog>

#include "ui_engineconfigdialog.h"

class PalLabeling;

class EngineConfigDialog : public QDialog, private Ui::EngineConfigDialog
{
Q_OBJECT
public:
EngineConfigDialog(PalLabeling* lbl, QWidget* parent = NULL);

public slots:
void onOK();

protected:
PalLabeling* mLBL;
};

#endif // ENGINECONFIGDIALOG_H
@@ -0,0 +1,192 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EngineConfigDialog</class>
<widget class="QDialog" name="EngineConfigDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>286</width>
<height>250</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Search method</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cboSearchMethod">
<item>
<property name="text">
<string>Chain (fastest)</string>
</property>
</item>
<item>
<property name="text">
<string>Popmusic Tabu</string>
</property>
</item>
<item>
<property name="text">
<string>Popmusic Chain</string>
</property>
</item>
<item>
<property name="text">
<string>Popmusic Tabu Chain</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Number of candidates</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Point</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinCandPoint">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Line</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinCandLine">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Polygon</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="spinCandPolygon">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>EngineConfigDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
@@ -22,6 +22,7 @@
#include <qgsmaplayerregistry.h>

#include "pallabeling.h"
#include "engineconfigdialog.h"

#include <QColorDialog>
#include <QFontDialog>
@@ -36,6 +37,7 @@ LabelingGui::LabelingGui( PalLabeling* lbl, QString layerId, QWidget* parent )

connect(btnTextColor, SIGNAL(clicked()), this, SLOT(changeTextColor()) );
connect(btnChangeFont, SIGNAL(clicked()), this, SLOT(changeTextFont()) );
connect(btnEngineSettings, SIGNAL(clicked()), this, SLOT(showEngineConfigDialog()) );

populatePlacementMethods();
populateFieldNames();
@@ -142,3 +144,9 @@ void LabelingGui::updateFontPreview(QFont font)
palette.setBrush(QPalette::Inactive, QPalette::WindowText, brush);
lblFontPreview->setPalette(palette);
}

void LabelingGui::showEngineConfigDialog()
{
EngineConfigDialog dlg(mLBL, this);
dlg.exec();
}
@@ -40,6 +40,7 @@ class LabelingGui : public QDialog, private Ui::LabelingGuiBase
public slots:
void changeTextColor();
void changeTextFont();
void showEngineConfigDialog();

protected:
void populatePlacementMethods();
@@ -247,7 +247,7 @@
<item>
<widget class="QPushButton" name="btnEngineSettings">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="text">
<string>Engine settings</string>
@@ -66,6 +66,19 @@ class MyLabel : public PalGeometry
PalLabeling::PalLabeling(QgsMapCanvas* mapCanvas)
: mMapCanvas(mapCanvas)
{
// find out engine defaults
Pal p;
mCandPoint = p.getPointP();
mCandLine = p.getLineP();
mCandPolygon = p.getPolyP();

switch (p.getSearch())
{
case CHAIN: mSearch = Chain; break;
case POPMUSIC_TABU: mSearch = Popmusic_Tabu; break;
case POPMUSIC_CHAIN: mSearch = Popmusic_Chain; break;
case POPMUSIC_TABU_CHAIN: mSearch = Popmusic_Tabu_Chain; break;
}
}

void PalLabeling::addLayer(LayerSettings layerSettings)
@@ -162,6 +175,22 @@ int PalLabeling::prepareLayer(Pal& pal, const LayerSettings& lyr)
void PalLabeling::doLabeling(QPainter* painter)
{
Pal p;

SearchMethod s;
switch (mSearch)
{
case Chain: s = CHAIN; break;
case Popmusic_Tabu: s = POPMUSIC_TABU; break;
case Popmusic_Chain: s = POPMUSIC_CHAIN; break;
case Popmusic_Tabu_Chain: s = POPMUSIC_TABU_CHAIN; break;
}
p.setSearch(s);

// set number of candidates generated per feature
p.setPointP(mCandPoint);
p.setLineP(mCandLine);
p.setPolyP(mCandPolygon);

//p.setSearch(POPMUSIC_TABU_CHAIN);// this is really slow! // default is CHAIN (worst, fastest)
// TODO: API 0.2 - no mention about changing map units!
// pal map units = METER by default ... change setMapUnit
@@ -234,3 +263,27 @@ void PalLabeling::doLabeling(QPainter* painter)

delete labels;
}

void PalLabeling::numCandidatePositions(int& candPoint, int& candLine, int& candPolygon)
{
candPoint = mCandPoint;
candLine = mCandLine;
candPolygon = mCandPolygon;
}

void PalLabeling::setNumCandidatePositions(int candPoint, int candLine, int candPolygon)
{
mCandPoint = candPoint;
mCandLine = candLine;
mCandPolygon = candPolygon;
}

void PalLabeling::setSearchMethod(PalLabeling::Search s)
{
mSearch = s;
}

PalLabeling::Search PalLabeling::searchMethod() const
{
return mSearch;
}

0 comments on commit 02d5b93

Please sign in to comment.