Skip to content

Commit 02d5b93

Browse files
author
wonder
committedJun 5, 2009
Added engine configuration dialog. It's possible to set number of candidate 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

File tree

9 files changed

+325
-2
lines changed

9 files changed

+325
-2
lines changed
 

‎src/plugins/labeling/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ SET (labeling_SRCS
66
labeling.cpp
77
labelinggui.cpp
88
pallabeling.cpp
9+
engineconfigdialog.cpp
910
)
1011

11-
SET (labeling_UIS labelingguibase.ui)
12+
SET (labeling_UIS labelingguibase.ui engineconfigdialog.ui)
1213

1314
SET (labeling_MOC_HDRS
1415
labeling.h
1516
labelinggui.h
17+
engineconfigdialog.h
1618
)
1719

1820
SET (labeling_RCCS labeling.qrc)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "engineconfigdialog.h"
2+
3+
#include "pallabeling.h"
4+
5+
EngineConfigDialog::EngineConfigDialog(PalLabeling* lbl, QWidget* parent)
6+
: QDialog(parent), mLBL(lbl)
7+
{
8+
setupUi(this);
9+
10+
connect(buttonBox, SIGNAL(accepted()), this, SLOT(onOK()) );
11+
12+
// search method
13+
cboSearchMethod->setCurrentIndex( mLBL->searchMethod() );
14+
15+
// candidate numbers
16+
int candPoint, candLine, candPolygon;
17+
mLBL->numCandidatePositions(candPoint, candLine, candPolygon);
18+
spinCandPoint->setValue(candPoint);
19+
spinCandLine->setValue(candLine);
20+
spinCandPolygon->setValue(candPolygon);
21+
}
22+
23+
24+
void EngineConfigDialog::onOK()
25+
{
26+
// save
27+
mLBL->setSearchMethod( (PalLabeling::Search) cboSearchMethod->currentIndex() );
28+
29+
mLBL->setNumCandidatePositions(spinCandPoint->value(),
30+
spinCandLine->value(),
31+
spinCandPolygon->value());
32+
33+
accept();
34+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef ENGINECONFIGDIALOG_H
2+
#define ENGINECONFIGDIALOG_H
3+
4+
#include <QDialog>
5+
6+
#include "ui_engineconfigdialog.h"
7+
8+
class PalLabeling;
9+
10+
class EngineConfigDialog : public QDialog, private Ui::EngineConfigDialog
11+
{
12+
Q_OBJECT
13+
public:
14+
EngineConfigDialog(PalLabeling* lbl, QWidget* parent = NULL);
15+
16+
public slots:
17+
void onOK();
18+
19+
protected:
20+
PalLabeling* mLBL;
21+
};
22+
23+
#endif // ENGINECONFIGDIALOG_H
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>EngineConfigDialog</class>
4+
<widget class="QDialog" name="EngineConfigDialog">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>286</width>
10+
<height>250</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Dialog</string>
15+
</property>
16+
<layout class="QVBoxLayout" name="verticalLayout">
17+
<item>
18+
<layout class="QHBoxLayout" name="horizontalLayout">
19+
<item>
20+
<widget class="QLabel" name="label">
21+
<property name="text">
22+
<string>Search method</string>
23+
</property>
24+
</widget>
25+
</item>
26+
<item>
27+
<widget class="QComboBox" name="cboSearchMethod">
28+
<item>
29+
<property name="text">
30+
<string>Chain (fastest)</string>
31+
</property>
32+
</item>
33+
<item>
34+
<property name="text">
35+
<string>Popmusic Tabu</string>
36+
</property>
37+
</item>
38+
<item>
39+
<property name="text">
40+
<string>Popmusic Chain</string>
41+
</property>
42+
</item>
43+
<item>
44+
<property name="text">
45+
<string>Popmusic Tabu Chain</string>
46+
</property>
47+
</item>
48+
</widget>
49+
</item>
50+
</layout>
51+
</item>
52+
<item>
53+
<layout class="QHBoxLayout" name="horizontalLayout_2">
54+
<item>
55+
<spacer name="horizontalSpacer">
56+
<property name="orientation">
57+
<enum>Qt::Horizontal</enum>
58+
</property>
59+
<property name="sizeType">
60+
<enum>QSizePolicy::Preferred</enum>
61+
</property>
62+
<property name="sizeHint" stdset="0">
63+
<size>
64+
<width>40</width>
65+
<height>20</height>
66+
</size>
67+
</property>
68+
</spacer>
69+
</item>
70+
<item>
71+
<widget class="QGroupBox" name="groupBox">
72+
<property name="title">
73+
<string>Number of candidates</string>
74+
</property>
75+
<layout class="QGridLayout" name="gridLayout">
76+
<item row="0" column="0">
77+
<widget class="QLabel" name="label_2">
78+
<property name="text">
79+
<string>Point</string>
80+
</property>
81+
<property name="alignment">
82+
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
83+
</property>
84+
</widget>
85+
</item>
86+
<item row="0" column="1">
87+
<widget class="QSpinBox" name="spinCandPoint">
88+
<property name="minimum">
89+
<number>1</number>
90+
</property>
91+
</widget>
92+
</item>
93+
<item row="1" column="0">
94+
<widget class="QLabel" name="label_3">
95+
<property name="text">
96+
<string>Line</string>
97+
</property>
98+
<property name="alignment">
99+
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
100+
</property>
101+
</widget>
102+
</item>
103+
<item row="1" column="1">
104+
<widget class="QSpinBox" name="spinCandLine">
105+
<property name="minimum">
106+
<number>1</number>
107+
</property>
108+
</widget>
109+
</item>
110+
<item row="2" column="0">
111+
<widget class="QLabel" name="label_4">
112+
<property name="text">
113+
<string>Polygon</string>
114+
</property>
115+
<property name="alignment">
116+
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
117+
</property>
118+
</widget>
119+
</item>
120+
<item row="2" column="1">
121+
<widget class="QSpinBox" name="spinCandPolygon">
122+
<property name="minimum">
123+
<number>1</number>
124+
</property>
125+
</widget>
126+
</item>
127+
</layout>
128+
</widget>
129+
</item>
130+
<item>
131+
<spacer name="horizontalSpacer_2">
132+
<property name="orientation">
133+
<enum>Qt::Horizontal</enum>
134+
</property>
135+
<property name="sizeType">
136+
<enum>QSizePolicy::Preferred</enum>
137+
</property>
138+
<property name="sizeHint" stdset="0">
139+
<size>
140+
<width>40</width>
141+
<height>20</height>
142+
</size>
143+
</property>
144+
</spacer>
145+
</item>
146+
</layout>
147+
</item>
148+
<item>
149+
<spacer name="verticalSpacer">
150+
<property name="orientation">
151+
<enum>Qt::Vertical</enum>
152+
</property>
153+
<property name="sizeHint" stdset="0">
154+
<size>
155+
<width>20</width>
156+
<height>40</height>
157+
</size>
158+
</property>
159+
</spacer>
160+
</item>
161+
<item>
162+
<widget class="QDialogButtonBox" name="buttonBox">
163+
<property name="orientation">
164+
<enum>Qt::Horizontal</enum>
165+
</property>
166+
<property name="standardButtons">
167+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
168+
</property>
169+
</widget>
170+
</item>
171+
</layout>
172+
</widget>
173+
<resources/>
174+
<connections>
175+
<connection>
176+
<sender>buttonBox</sender>
177+
<signal>rejected()</signal>
178+
<receiver>EngineConfigDialog</receiver>
179+
<slot>reject()</slot>
180+
<hints>
181+
<hint type="sourcelabel">
182+
<x>316</x>
183+
<y>260</y>
184+
</hint>
185+
<hint type="destinationlabel">
186+
<x>286</x>
187+
<y>274</y>
188+
</hint>
189+
</hints>
190+
</connection>
191+
</connections>
192+
</ui>

‎src/plugins/labeling/labelinggui.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <qgsmaplayerregistry.h>
2323

2424
#include "pallabeling.h"
25+
#include "engineconfigdialog.h"
2526

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

3738
connect(btnTextColor, SIGNAL(clicked()), this, SLOT(changeTextColor()) );
3839
connect(btnChangeFont, SIGNAL(clicked()), this, SLOT(changeTextFont()) );
40+
connect(btnEngineSettings, SIGNAL(clicked()), this, SLOT(showEngineConfigDialog()) );
3941

4042
populatePlacementMethods();
4143
populateFieldNames();
@@ -142,3 +144,9 @@ void LabelingGui::updateFontPreview(QFont font)
142144
palette.setBrush(QPalette::Inactive, QPalette::WindowText, brush);
143145
lblFontPreview->setPalette(palette);
144146
}
147+
148+
void LabelingGui::showEngineConfigDialog()
149+
{
150+
EngineConfigDialog dlg(mLBL, this);
151+
dlg.exec();
152+
}

‎src/plugins/labeling/labelinggui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class LabelingGui : public QDialog, private Ui::LabelingGuiBase
4040
public slots:
4141
void changeTextColor();
4242
void changeTextFont();
43+
void showEngineConfigDialog();
4344

4445
protected:
4546
void populatePlacementMethods();

‎src/plugins/labeling/labelingguibase.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@
247247
<item>
248248
<widget class="QPushButton" name="btnEngineSettings">
249249
<property name="enabled">
250-
<bool>false</bool>
250+
<bool>true</bool>
251251
</property>
252252
<property name="text">
253253
<string>Engine settings</string>

‎src/plugins/labeling/pallabeling.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ class MyLabel : public PalGeometry
6666
PalLabeling::PalLabeling(QgsMapCanvas* mapCanvas)
6767
: mMapCanvas(mapCanvas)
6868
{
69+
// find out engine defaults
70+
Pal p;
71+
mCandPoint = p.getPointP();
72+
mCandLine = p.getLineP();
73+
mCandPolygon = p.getPolyP();
74+
75+
switch (p.getSearch())
76+
{
77+
case CHAIN: mSearch = Chain; break;
78+
case POPMUSIC_TABU: mSearch = Popmusic_Tabu; break;
79+
case POPMUSIC_CHAIN: mSearch = Popmusic_Chain; break;
80+
case POPMUSIC_TABU_CHAIN: mSearch = Popmusic_Tabu_Chain; break;
81+
}
6982
}
7083

7184
void PalLabeling::addLayer(LayerSettings layerSettings)
@@ -162,6 +175,22 @@ int PalLabeling::prepareLayer(Pal& pal, const LayerSettings& lyr)
162175
void PalLabeling::doLabeling(QPainter* painter)
163176
{
164177
Pal p;
178+
179+
SearchMethod s;
180+
switch (mSearch)
181+
{
182+
case Chain: s = CHAIN; break;
183+
case Popmusic_Tabu: s = POPMUSIC_TABU; break;
184+
case Popmusic_Chain: s = POPMUSIC_CHAIN; break;
185+
case Popmusic_Tabu_Chain: s = POPMUSIC_TABU_CHAIN; break;
186+
}
187+
p.setSearch(s);
188+
189+
// set number of candidates generated per feature
190+
p.setPointP(mCandPoint);
191+
p.setLineP(mCandLine);
192+
p.setPolyP(mCandPolygon);
193+
165194
//p.setSearch(POPMUSIC_TABU_CHAIN);// this is really slow! // default is CHAIN (worst, fastest)
166195
// TODO: API 0.2 - no mention about changing map units!
167196
// pal map units = METER by default ... change setMapUnit
@@ -234,3 +263,27 @@ void PalLabeling::doLabeling(QPainter* painter)
234263

235264
delete labels;
236265
}
266+
267+
void PalLabeling::numCandidatePositions(int& candPoint, int& candLine, int& candPolygon)
268+
{
269+
candPoint = mCandPoint;
270+
candLine = mCandLine;
271+
candPolygon = mCandPolygon;
272+
}
273+
274+
void PalLabeling::setNumCandidatePositions(int candPoint, int candLine, int candPolygon)
275+
{
276+
mCandPoint = candPoint;
277+
mCandLine = candLine;
278+
mCandPolygon = candPolygon;
279+
}
280+
281+
void PalLabeling::setSearchMethod(PalLabeling::Search s)
282+
{
283+
mSearch = s;
284+
}
285+
286+
PalLabeling::Search PalLabeling::searchMethod() const
287+
{
288+
return mSearch;
289+
}

‎src/plugins/labeling/pallabeling.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,22 @@ class PalLabeling
4646

4747
LayerSettings layer(QString layerId);
4848

49+
void numCandidatePositions(int& candPoint, int& candLine, int& candPolygon);
50+
void setNumCandidatePositions(int candPoint, int candLine, int candPolygon);
51+
52+
enum Search { Chain, Popmusic_Tabu, Popmusic_Chain, Popmusic_Tabu_Chain };
53+
54+
void setSearchMethod(Search s);
55+
Search searchMethod() const;
56+
4957
protected:
5058
int prepareLayer(pal::Pal& pal, const LayerSettings& lyr);
5159

5260
protected:
5361
QList<LayerSettings> mLayers;
5462
QgsMapCanvas* mMapCanvas;
63+
int mCandPoint, mCandLine, mCandPolygon;
64+
Search mSearch;
5565
};
5666

5767
#endif // PALLABELING_H

0 commit comments

Comments
 (0)
Please sign in to comment.