Skip to content

Commit bb947b4

Browse files
committedNov 11, 2012
Add custom line direction symbols to labeling
- Options to place symbol above or below label text - Option to reverse symbol direction - Add character selector dialog for single font to src/gui
1 parent badeeae commit bb947b4

12 files changed

+639
-54
lines changed
 

‎python/core/qgspallabeling.sip

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ class QgsPalLayerSettings
3434
ShowAll // show upside down for all labels, including dynamic ones
3535
};
3636

37+
enum DirectionSymbols
38+
{
39+
SymbolLeftRight, // place direction symbols on left/right of label
40+
SymbolAbove, // place direction symbols on above label
41+
SymbolBelow // place direction symbols on below label
42+
};
43+
3744
enum MultiLineAlign
3845
{
3946
MultiLeft = 0,
@@ -117,9 +124,14 @@ class QgsPalLayerSettings
117124
bool displayAll; // if true, all features will be labelled even though overlaps occur
118125
bool mergeLines;
119126
double minFeatureSize; // minimum feature size to be labelled (in mm)
120-
// Adds '<' or '>' to the label string pointing to the direction of the line / polygon ring
127+
// Adds '<' or '>', or user-defined symbol to the label string pointing to the
128+
// direction of the line / polygon ring
121129
// Works only if Placement == Line
122130
bool addDirectionSymbol;
131+
QString leftDirectionSymbol;
132+
QString rightDirectionSymbol;
133+
bool reverseDirectionSymbol;
134+
DirectionSymbols placeDirectionSymbol; // whether to place left/right, above or below label
123135
unsigned int upsidedownLabels; // whether, or how, to show upsidedown labels
124136
bool fontSizeInMapUnits; //true if font size is in map units (otherwise in points)
125137
bool fontLimitPixelSize; // true is label should be limited by fontMinPixelSize/fontMaxPixelSize

‎src/app/qgslabelinggui.cpp

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "qgsexpressionbuilderdialog.h"
2727
#include "qgsexpression.h"
2828
#include "qgsmapcanvas.h"
29+
#include "qgscharacterselectdialog.h"
2930

3031
#include <QColorDialog>
3132
#include <QFontDialog>
@@ -41,6 +42,7 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
4142
if ( !layer ) return;
4243

4344
setupUi( this );
45+
mCharDlg = new QgsCharacterSelectorDialog( this );
4446

4547
mRefFont = lblFontPreview->font();
4648
mPreviewSize = 24;
@@ -77,7 +79,7 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
7779

7880
//mTabWidget->setEnabled( chkEnableLabeling->isChecked() );
7981
chkMergeLines->setEnabled( layer->geometryType() == QGis::Line );
80-
chkAddDirectionSymbol->setEnabled( layer->geometryType() == QGis::Line );
82+
mDirectSymbGroupBox->setEnabled( layer->geometryType() == QGis::Line );
8183
label_19->setEnabled( layer->geometryType() != QGis::Point );
8284
mMinSizeSpinBox->setEnabled( layer->geometryType() != QGis::Point );
8385

@@ -172,7 +174,25 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
172174
mPalShowAllLabelsForLayerChkBx->setChecked( lyr.displayAll );
173175
chkMergeLines->setChecked( lyr.mergeLines );
174176
mMinSizeSpinBox->setValue( lyr.minFeatureSize );
175-
chkAddDirectionSymbol->setChecked( lyr.addDirectionSymbol );
177+
mDirectSymbGroupBox->setChecked( lyr.addDirectionSymbol );
178+
mDirectSymbLeftLineEdit->setText( lyr.leftDirectionSymbol );
179+
mDirectSymbRightLineEdit->setText( lyr.rightDirectionSymbol );
180+
mDirectSymbRevChkBx->setChecked( lyr.reverseDirectionSymbol );
181+
switch ( lyr.placeDirectionSymbol )
182+
{
183+
case QgsPalLayerSettings::SymbolLeftRight:
184+
mDirectSymbRadioBtnLR->setChecked( true );
185+
break;
186+
case QgsPalLayerSettings::SymbolAbove:
187+
mDirectSymbRadioBtnAbove->setChecked( true );
188+
break;
189+
case QgsPalLayerSettings::SymbolBelow:
190+
mDirectSymbRadioBtnBelow->setChecked( true );
191+
break;
192+
default:
193+
mDirectSymbRadioBtnLR->setChecked( true );
194+
break;
195+
}
176196

177197
// upside-down labels
178198
switch ( lyr.upsidedownLabels )
@@ -449,14 +469,24 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
449469
lyr.decimals = spinDecimals->value();
450470
lyr.plusSign = true;
451471
}
452-
if ( chkAddDirectionSymbol->isChecked() )
472+
473+
lyr.addDirectionSymbol = mDirectSymbGroupBox->isChecked();
474+
lyr.leftDirectionSymbol = mDirectSymbLeftLineEdit->text();
475+
lyr.rightDirectionSymbol = mDirectSymbRightLineEdit->text();
476+
lyr.reverseDirectionSymbol = mDirectSymbRevChkBx->isChecked();
477+
if ( mDirectSymbRadioBtnLR->isChecked() )
453478
{
454-
lyr.addDirectionSymbol = true;
479+
lyr.placeDirectionSymbol = QgsPalLayerSettings::SymbolLeftRight;
455480
}
456-
else
481+
else if ( mDirectSymbRadioBtnAbove->isChecked() )
482+
{
483+
lyr.placeDirectionSymbol = QgsPalLayerSettings::SymbolAbove;
484+
}
485+
else if ( mDirectSymbRadioBtnBelow->isChecked() )
457486
{
458-
lyr.addDirectionSymbol = false;
487+
lyr.placeDirectionSymbol = QgsPalLayerSettings::SymbolBelow;
459488
}
489+
460490
if ( mUpsidedownRadioOff->isChecked() )
461491
{
462492
lyr.upsidedownLabels = QgsPalLayerSettings::Upright;
@@ -736,6 +766,8 @@ void QgsLabelingGui::updateFont( QFont font )
736766
}
737767

738768
lblFontName->setText( QString( "%1%2" ).arg( mRefFont.family() ).arg( missingtxt ) );
769+
mDirectSymbLeftLineEdit->setFont( mRefFont );
770+
mDirectSymbRightLineEdit->setFont( mRefFont );
739771

740772
blockFontChangeSignals( true );
741773
populateFontStyleComboBox();
@@ -1101,6 +1133,34 @@ void QgsLabelingGui::on_mPreviewBackgroundBtn_clicked()
11011133
setPreviewBackground( color );
11021134
}
11031135

1136+
void QgsLabelingGui::on_mDirectSymbLeftToolBtn_clicked()
1137+
{
1138+
bool gotChar = false;
1139+
QChar dirSymb = QChar();
1140+
1141+
dirSymb = mCharDlg->selectCharacter( &gotChar, mRefFont, mFontDB.styleString( mRefFont ) );
1142+
1143+
if ( !gotChar )
1144+
return;
1145+
1146+
if ( !dirSymb.isNull() )
1147+
mDirectSymbLeftLineEdit->setText( QString( dirSymb ) );
1148+
}
1149+
1150+
void QgsLabelingGui::on_mDirectSymbRightToolBtn_clicked()
1151+
{
1152+
bool gotChar = false;
1153+
QChar dirSymb = QChar();
1154+
1155+
dirSymb = mCharDlg->selectCharacter( &gotChar, mRefFont, mFontDB.styleString( mRefFont ) );
1156+
1157+
if ( !gotChar )
1158+
return;
1159+
1160+
if ( !dirSymb.isNull() )
1161+
mDirectSymbRightLineEdit->setText( QString( dirSymb ) );
1162+
}
1163+
11041164
void QgsLabelingGui::disableDataDefinedAlignment()
11051165
{
11061166
mHorizontalAlignmentComboBox->setCurrentIndex( mHorizontalAlignmentComboBox->findText( "" ) );

‎src/app/qgslabelinggui.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
class QgsVectorLayer;
2626
class QgsMapCanvas;
27+
class QgsCharacterSelectorDialog;
2728

2829
#include "qgspallabeling.h"
2930

@@ -70,6 +71,8 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
7071
void on_mPreviewTextEdit_textChanged( const QString & text );
7172
void on_mPreviewTextBtn_clicked();
7273
void on_mPreviewBackgroundBtn_clicked();
74+
void on_mDirectSymbLeftToolBtn_clicked();
75+
void on_mDirectSymbRightToolBtn_clicked();
7376

7477
protected:
7578
void blockFontChangeSignals( bool blk );
@@ -90,6 +93,7 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
9093
QgsVectorLayer* mLayer;
9194
QgsMapCanvas* mMapCanvas;
9295
QFontDatabase mFontDB;
96+
QgsCharacterSelectorDialog* mCharDlg;
9397

9498
// background reference font
9599
QFont mRefFont;

‎src/core/qgspallabeling.cpp

Lines changed: 74 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ QgsPalLayerSettings::QgsPalLayerSettings()
213213
vectorScaleFactor = 1.0;
214214
rasterCompressFactor = 1.0;
215215
addDirectionSymbol = false;
216+
leftDirectionSymbol = QString( "<" );
217+
rightDirectionSymbol = QString( ">" );
218+
reverseDirectionSymbol = false;
219+
placeDirectionSymbol = SymbolLeftRight;
216220
upsidedownLabels = Upright;
217221
fontSizeInMapUnits = false;
218222
fontLimitPixelSize = false;
@@ -266,6 +270,10 @@ QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
266270
vectorScaleFactor = s.vectorScaleFactor;
267271
rasterCompressFactor = s.rasterCompressFactor;
268272
addDirectionSymbol = s.addDirectionSymbol;
273+
leftDirectionSymbol = s.leftDirectionSymbol;
274+
rightDirectionSymbol = s.rightDirectionSymbol;
275+
reverseDirectionSymbol = s.reverseDirectionSymbol;
276+
placeDirectionSymbol = s.placeDirectionSymbol;
269277
upsidedownLabels = s.upsidedownLabels;
270278
fontSizeInMapUnits = s.fontSizeInMapUnits;
271279
fontLimitPixelSize = s.fontLimitPixelSize;
@@ -433,7 +441,7 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
433441
textFont.setWordSpacing( layer->customProperty( "labeling/fontWordSpacing", QVariant( 0.0 ) ).toDouble() );
434442
textColor = _readColor( layer, "labeling/textColor" );
435443
textTransp = layer->customProperty( "labeling/textTransp" ).toInt();
436-
previewBkgrdColor = QColor( layer->customProperty( "labeling/previewBkgrdColor", "#ffffff" ).toString() );
444+
previewBkgrdColor = QColor( layer->customProperty( "labeling/previewBkgrdColor", QVariant( "#ffffff" ) ).toString() );
437445
enabled = layer->customProperty( "labeling/enabled" ).toBool();
438446
priority = layer->customProperty( "labeling/priority" ).toInt();
439447
obstacle = layer->customProperty( "labeling/obstacle" ).toBool();
@@ -452,6 +460,10 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
452460
displayAll = layer->customProperty( "labeling/displayAll", QVariant( false ) ).toBool();
453461
mergeLines = layer->customProperty( "labeling/mergeLines" ).toBool();
454462
addDirectionSymbol = layer->customProperty( "labeling/addDirectionSymbol" ).toBool();
463+
leftDirectionSymbol = layer->customProperty( "labeling/leftDirectionSymbol", QVariant( "<" ) ).toString();
464+
rightDirectionSymbol = layer->customProperty( "labeling/rightDirectionSymbol", QVariant( ">" ) ).toString();
465+
reverseDirectionSymbol = layer->customProperty( "labeling/reverseDirectionSymbol" ).toBool();
466+
placeDirectionSymbol = ( DirectionSymbols ) layer->customProperty( "labeling/placeDirectionSymbol", QVariant( SymbolLeftRight ) ).toUInt();
455467
upsidedownLabels = ( UpsideDownLabels ) layer->customProperty( "labeling/upsidedownLabels", QVariant( Upright ) ).toUInt();
456468
minFeatureSize = layer->customProperty( "labeling/minFeatureSize" ).toDouble();
457469
fontSizeInMapUnits = layer->customProperty( "labeling/fontSizeInMapUnits" ).toBool();
@@ -516,6 +528,10 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer* layer )
516528
layer->setCustomProperty( "labeling/displayAll", displayAll );
517529
layer->setCustomProperty( "labeling/mergeLines", mergeLines );
518530
layer->setCustomProperty( "labeling/addDirectionSymbol", addDirectionSymbol );
531+
layer->setCustomProperty( "labeling/leftDirectionSymbol", leftDirectionSymbol );
532+
layer->setCustomProperty( "labeling/rightDirectionSymbol", rightDirectionSymbol );
533+
layer->setCustomProperty( "labeling/reverseDirectionSymbol", reverseDirectionSymbol );
534+
layer->setCustomProperty( "labeling/placeDirectionSymbol", ( unsigned int )placeDirectionSymbol );
519535
layer->setCustomProperty( "labeling/upsidedownLabels", ( unsigned int )upsidedownLabels );
520536
layer->setCustomProperty( "labeling/minFeatureSize", minFeatureSize );
521537
layer->setCustomProperty( "labeling/fontSizeInMapUnits", fontSizeInMapUnits );
@@ -587,18 +603,29 @@ void QgsPalLayerSettings::calculateLabelSize( const QFontMetricsF* fm, QString t
587603
return;
588604
}
589605

606+
QString wrapchr = !wrapChar.isEmpty() ? wrapChar : QString( "\n" );
607+
590608
//consider the space needed for the direction symbol
591-
if ( addDirectionSymbol && placement == QgsPalLayerSettings::Line )
609+
if ( addDirectionSymbol && placement == QgsPalLayerSettings::Line
610+
&& ( !leftDirectionSymbol.isEmpty() || !rightDirectionSymbol.isEmpty() ) )
592611
{
593-
text.append( ">" );
612+
QString dirSym = leftDirectionSymbol;
613+
614+
if ( fm->width( rightDirectionSymbol ) > fm->width( dirSym ) )
615+
dirSym = rightDirectionSymbol;
616+
617+
if ( placeDirectionSymbol == QgsPalLayerSettings::SymbolLeftRight )
618+
{
619+
text.append( dirSym );
620+
}
621+
else
622+
{
623+
text.append( dirSym + wrapchr ); // SymbolAbove or SymbolBelow
624+
}
594625
}
595626

596627
double w = 0.0, h = 0.0;
597-
QStringList multiLineSplit;
598-
if ( !wrapChar.isEmpty() )
599-
multiLineSplit = text.split( wrapChar );
600-
else
601-
multiLineSplit = text.split( "\n" );
628+
QStringList multiLineSplit = text.split( wrapchr );
602629
int lines = multiLineSplit.size();
603630

604631
double labelHeight = fm->ascent() + fm->descent(); // ignore +1 for baseline
@@ -1722,28 +1749,59 @@ void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QPainter* painter, co
17221749
QString txt = ( label->getPartId() == -1 ? text : QString( text[label->getPartId()] ) );
17231750
QFontMetricsF* labelfm = (( QgsPalGeometry* )label->getFeaturePart()->getUserGeometry() )->getLabelFontMetrics();
17241751

1752+
QString wrapchr = !lyr.wrapChar.isEmpty() ? lyr.wrapChar : QString( "\n" );
1753+
17251754
//add the direction symbol if needed
17261755
if ( !txt.isEmpty() && lyr.placement == QgsPalLayerSettings::Line &&
17271756
lyr.addDirectionSymbol )
17281757
{
1758+
bool prependSymb = false;
1759+
QString symb = lyr.rightDirectionSymbol;
1760+
17291761
if ( label->getReversed() )
17301762
{
1731-
txt.prepend( "<" );
1763+
prependSymb = true;
1764+
symb = lyr.leftDirectionSymbol;
1765+
}
1766+
1767+
if ( lyr.reverseDirectionSymbol )
1768+
{
1769+
if ( symb == lyr.rightDirectionSymbol )
1770+
{
1771+
prependSymb = true;
1772+
symb = lyr.leftDirectionSymbol;
1773+
}
1774+
else
1775+
{
1776+
prependSymb = false;
1777+
symb = lyr.rightDirectionSymbol;
1778+
}
1779+
}
1780+
1781+
if ( lyr.placeDirectionSymbol == QgsPalLayerSettings::SymbolAbove )
1782+
{
1783+
prependSymb = true;
1784+
symb = symb + wrapchr;
1785+
}
1786+
else if ( lyr.placeDirectionSymbol == QgsPalLayerSettings::SymbolBelow )
1787+
{
1788+
prependSymb = false;
1789+
symb = wrapchr + symb;
1790+
}
1791+
1792+
if ( prependSymb )
1793+
{
1794+
txt.prepend( symb );
17321795
}
17331796
else
17341797
{
1735-
txt.append( ">" );
1798+
txt.append( symb );
17361799
}
17371800
}
17381801

17391802
//QgsDebugMsg( "drawLabel " + QString::number( drawBuffer ) + " " + txt );
17401803

1741-
QStringList multiLineList;
1742-
if ( !lyr.wrapChar.isEmpty() )
1743-
multiLineList = txt.split( lyr.wrapChar );
1744-
else
1745-
multiLineList = txt.split( "\n" );
1746-
1804+
QStringList multiLineList = txt.split( wrapchr );
17471805
int lines = multiLineList.size();
17481806

17491807
double labelWidest = 0.0;

‎src/core/qgspallabeling.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ class CORE_EXPORT QgsPalLayerSettings
8888
ShowAll // show upside down for all labels, including dynamic ones
8989
};
9090

91+
enum DirectionSymbols
92+
{
93+
SymbolLeftRight, // place direction symbols on left/right of label
94+
SymbolAbove, // place direction symbols on above label
95+
SymbolBelow // place direction symbols on below label
96+
};
97+
9198
enum MultiLineAlign
9299
{
93100
MultiLeft = 0,
@@ -171,9 +178,14 @@ class CORE_EXPORT QgsPalLayerSettings
171178
bool displayAll; // if true, all features will be labelled even though overlaps occur
172179
bool mergeLines;
173180
double minFeatureSize; // minimum feature size to be labelled (in mm)
174-
// Adds '<' or '>' to the label string pointing to the direction of the line / polygon ring
181+
// Adds '<' or '>', or user-defined symbol to the label string pointing to the
182+
// direction of the line / polygon ring
175183
// Works only if Placement == Line
176184
bool addDirectionSymbol;
185+
QString leftDirectionSymbol;
186+
QString rightDirectionSymbol;
187+
bool reverseDirectionSymbol;
188+
DirectionSymbols placeDirectionSymbol; // whether to place left/right, above or below label
177189
unsigned int upsidedownLabels; // whether, or how, to show upsidedown labels
178190
bool fontSizeInMapUnits; //true if font size is in map units (otherwise in points)
179191
bool fontLimitPixelSize; // true is label should be limited by fontMinPixelSize/fontMaxPixelSize

‎src/gui/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ qgisinterface.cpp
4848
qgsannotationitem.cpp
4949
qgsattributeeditor.cpp
5050
qgslegendinterface.cpp
51+
qgscharacterselectdialog.cpp
5152
qgscolorbutton.cpp
5253
qgscomposerview.cpp
5354
qgscursors.cpp
@@ -151,6 +152,7 @@ attributetable/qgsattributetablememorymodel.h
151152
attributetable/qgsattributetabledelegate.h
152153

153154
qgsattributeeditor.h
155+
qgscharacterselectdialog.h
154156
qgscomposerview.h
155157
qgsdetaileditemdelegate.h
156158
qgsdetaileditemwidget.h
@@ -198,6 +200,7 @@ QT4_WRAP_CPP(QGIS_GUI_MOC_SRCS ${QGIS_GUI_MOC_HDRS})
198200
SET(QGIS_GUI_HDRS
199201
qgisgui.h
200202
qgisinterface.h
203+
qgscharacterselectdialog.h
201204
qgscolorbutton.h
202205
qgscursors.h
203206
qgsencodingfiledialog.h

‎src/gui/qgscharacterselectdialog.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/***************************************************************************
2+
qgscharacterselectdialog.cpp - single font character selector dialog
3+
4+
---------------------
5+
begin : November 2012
6+
copyright : (C) 2012 by Larry Shaffer
7+
email : larrys at dakcarto dot com
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#include "characterwidget.h"
18+
#include "qgscharacterselectdialog.h"
19+
20+
21+
QgsCharacterSelectorDialog::QgsCharacterSelectorDialog( QWidget *parent, Qt::WFlags fl )
22+
: QDialog( parent, fl ), mChar( QChar::Null )
23+
{
24+
setupUi( this );
25+
mCharWidget = new CharacterWidget( this );
26+
mCharSelectScrollArea->setWidget( mCharWidget );
27+
connect( mCharWidget, SIGNAL( characterSelected( const QChar & ) ), this, SLOT( setCharacter( const QChar & ) ) );
28+
}
29+
30+
QgsCharacterSelectorDialog::~QgsCharacterSelectorDialog()
31+
{
32+
}
33+
34+
const QChar& QgsCharacterSelectorDialog::selectCharacter( bool* gotChar, const QFont& font, const QString& style )
35+
{
36+
mCharSelectLabelFont->setText( QString( "%1 %2" ).arg( font.family() ).arg( style ) );
37+
mCharWidget->updateFont( font );
38+
mCharWidget->updateStyle( style );
39+
mCharWidget->updateSize( 22.0 );
40+
mCharSelectScrollArea->viewport()->update();
41+
42+
QApplication::setOverrideCursor( Qt::ArrowCursor );
43+
int res = exec();
44+
QApplication::restoreOverrideCursor();
45+
46+
if ( res == QDialog::Accepted )
47+
{
48+
if ( !mChar.isNull() && gotChar )
49+
{
50+
*gotChar = true;
51+
}
52+
}
53+
return mChar;
54+
}
55+
56+
void QgsCharacterSelectorDialog::setCharacter( const QChar & chr )
57+
{
58+
mChar = chr;
59+
}

‎src/gui/qgscharacterselectdialog.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/***************************************************************************
2+
qgscharacterselectdialog.h - single font character selector dialog
3+
4+
---------------------
5+
begin : November 2012
6+
copyright : (C) 2012 by Larry Shaffer
7+
email : larrys at dakcarto dot com
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#ifndef QGSCHARACTERSELECTDIALOG_H
18+
#define QGSCHARACTERSELECTDIALOG_H
19+
20+
#include <QDialog>
21+
#include <QChar>
22+
#include "qgisgui.h"
23+
#include "ui_qgscharacterselectdialogbase.h"
24+
25+
class CharacterWidget;
26+
27+
/** A dialog for selecting a single character from a single font
28+
*/
29+
30+
class GUI_EXPORT QgsCharacterSelectorDialog : public QDialog, private Ui::QgsCharacterSelectorBase
31+
{
32+
Q_OBJECT
33+
34+
public:
35+
QgsCharacterSelectorDialog( QWidget* parent = 0, Qt::WFlags fl = QgisGui::ModalDialogFlags );
36+
~QgsCharacterSelectorDialog();
37+
38+
public slots:
39+
const QChar& selectCharacter( bool* gotChar, const QFont& font, const QString& style );
40+
41+
private slots:
42+
void setCharacter( const QChar& chr );
43+
44+
protected:
45+
QChar mChar;
46+
CharacterWidget* mCharWidget;
47+
};
48+
49+
#endif

‎src/gui/symbology-ng/characterwidget.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ void CharacterWidget::updateFontMerging( bool enable )
9595
update();
9696
}
9797

98+
void CharacterWidget::updateColumns( int cols )
99+
{
100+
if ( columns == cols || cols < 1 )
101+
return;
102+
columns = cols;
103+
adjustSize();
104+
update();
105+
}
106+
98107
//! [3]
99108
QSize CharacterWidget::sizeHint() const
100109
{
@@ -108,7 +117,7 @@ void CharacterWidget::mouseMoveEvent( QMouseEvent *event )
108117
QPoint widgetPosition = mapFromGlobal( event->globalPos() );
109118
uint key = ( widgetPosition.y() / squareSize ) * columns + widgetPosition.x() / squareSize;
110119

111-
QString text = tr( "<p>Character: <span style=\"font-size: 24pt; font-family: %1%2</span><p>Value: 0x%3\">" )
120+
QString text = tr( "<p>Character: <span style=\"font-size: 24pt; font-family: %1\">%2</span><p>Value: 0x%3" )
112121
.arg( displayFont.family() )
113122
.arg( QChar( key ) )
114123
.arg( key, 16 );

‎src/gui/symbology-ng/characterwidget.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,15 @@ class CharacterWidget : public QWidget
6262
CharacterWidget( QWidget *parent = 0 );
6363
QSize sizeHint() const;
6464

65+
int getColumns() const { return columns; }
66+
int getSquareSize() const { return squareSize; }
67+
6568
public slots:
6669
void updateFont( const QFont &font );
6770
void updateSize( double fontSize );
6871
void updateStyle( const QString &fontStyle );
6972
void updateFontMerging( bool enable );
73+
void updateColumns( int cols );
7074

7175
signals:
7276
void characterSelected( const QChar &character );
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>QgsCharacterSelectorBase</class>
4+
<widget class="QDialog" name="QgsCharacterSelectorBase">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>640</width>
10+
<height>480</height>
11+
</rect>
12+
</property>
13+
<property name="minimumSize">
14+
<size>
15+
<width>640</width>
16+
<height>480</height>
17+
</size>
18+
</property>
19+
<property name="windowTitle">
20+
<string>Character Selector</string>
21+
</property>
22+
<layout class="QVBoxLayout" name="verticalLayout">
23+
<item>
24+
<layout class="QHBoxLayout" name="horizontalLayout">
25+
<item>
26+
<widget class="QLabel" name="mCharSelectLabel">
27+
<property name="sizePolicy">
28+
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
29+
<horstretch>0</horstretch>
30+
<verstretch>0</verstretch>
31+
</sizepolicy>
32+
</property>
33+
<property name="text">
34+
<string>Font:</string>
35+
</property>
36+
</widget>
37+
</item>
38+
<item>
39+
<widget class="QLabel" name="mCharSelectLabelFont">
40+
<property name="text">
41+
<string>Current font family and style</string>
42+
</property>
43+
</widget>
44+
</item>
45+
</layout>
46+
</item>
47+
<item>
48+
<widget class="QScrollArea" name="mCharSelectScrollArea">
49+
<property name="minimumSize">
50+
<size>
51+
<width>0</width>
52+
<height>0</height>
53+
</size>
54+
</property>
55+
<property name="verticalScrollBarPolicy">
56+
<enum>Qt::ScrollBarAsNeeded</enum>
57+
</property>
58+
<property name="horizontalScrollBarPolicy">
59+
<enum>Qt::ScrollBarAsNeeded</enum>
60+
</property>
61+
<property name="widgetResizable">
62+
<bool>false</bool>
63+
</property>
64+
<widget class="QWidget" name="scrollAreaWidgetContents">
65+
<property name="geometry">
66+
<rect>
67+
<x>0</x>
68+
<y>0</y>
69+
<width>359</width>
70+
<height>371</height>
71+
</rect>
72+
</property>
73+
</widget>
74+
</widget>
75+
</item>
76+
<item>
77+
<widget class="QDialogButtonBox" name="mCharSelectButtonBox">
78+
<property name="orientation">
79+
<enum>Qt::Horizontal</enum>
80+
</property>
81+
<property name="standardButtons">
82+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
83+
</property>
84+
</widget>
85+
</item>
86+
</layout>
87+
</widget>
88+
<resources/>
89+
<connections>
90+
<connection>
91+
<sender>mCharSelectButtonBox</sender>
92+
<signal>accepted()</signal>
93+
<receiver>QgsCharacterSelectorBase</receiver>
94+
<slot>accept()</slot>
95+
<hints>
96+
<hint type="sourcelabel">
97+
<x>248</x>
98+
<y>254</y>
99+
</hint>
100+
<hint type="destinationlabel">
101+
<x>157</x>
102+
<y>274</y>
103+
</hint>
104+
</hints>
105+
</connection>
106+
<connection>
107+
<sender>mCharSelectButtonBox</sender>
108+
<signal>rejected()</signal>
109+
<receiver>QgsCharacterSelectorBase</receiver>
110+
<slot>reject()</slot>
111+
<hints>
112+
<hint type="sourcelabel">
113+
<x>316</x>
114+
<y>260</y>
115+
</hint>
116+
<hint type="destinationlabel">
117+
<x>286</x>
118+
<y>274</y>
119+
</hint>
120+
</hints>
121+
</connection>
122+
</connections>
123+
</ui>

‎src/ui/qgslabelingguibase.ui

Lines changed: 221 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,9 @@
449449
<property name="geometry">
450450
<rect>
451451
<x>0</x>
452-
<y>0</y>
452+
<y>-448</y>
453453
<width>686</width>
454-
<height>714</height>
454+
<height>834</height>
455455
</rect>
456456
</property>
457457
<layout class="QGridLayout" name="gridLayout_17">
@@ -461,7 +461,7 @@
461461
<property name="verticalSpacing">
462462
<number>20</number>
463463
</property>
464-
<item row="8" column="0">
464+
<item row="9" column="0">
465465
<widget class="QgsCollapsibleGroupBox" name="chkFormattedNumbers">
466466
<property name="sizePolicy">
467467
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
@@ -1398,7 +1398,7 @@
13981398
</layout>
13991399
</widget>
14001400
</item>
1401-
<item row="11" column="0">
1401+
<item row="12" column="0">
14021402
<spacer name="verticalSpacer">
14031403
<property name="orientation">
14041404
<enum>Qt::Vertical</enum>
@@ -1495,31 +1495,6 @@
14951495
</property>
14961496
</widget>
14971497
</item>
1498-
<item row="0" column="2" colspan="2">
1499-
<widget class="QLabel" name="mFontLimitPixelLabel">
1500-
<property name="sizePolicy">
1501-
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
1502-
<horstretch>0</horstretch>
1503-
<verstretch>0</verstretch>
1504-
</sizepolicy>
1505-
</property>
1506-
<property name="styleSheet">
1507-
<string notr="true">background-color: rgb(243, 243, 243);</string>
1508-
</property>
1509-
<property name="frameShape">
1510-
<enum>QFrame::StyledPanel</enum>
1511-
</property>
1512-
<property name="text">
1513-
<string> Label in Map Units </string>
1514-
</property>
1515-
<property name="alignment">
1516-
<set>Qt::AlignCenter</set>
1517-
</property>
1518-
<property name="margin">
1519-
<number>1</number>
1520-
</property>
1521-
</widget>
1522-
</item>
15231498
<item row="0" column="1">
15241499
<widget class="QLabel" name="mFontLimitPixelLabel_2">
15251500
<property name="sizePolicy">
@@ -1546,6 +1521,31 @@
15461521
</property>
15471522
</spacer>
15481523
</item>
1524+
<item row="0" column="2" colspan="2">
1525+
<widget class="QLabel" name="mFontLimitPixelLabel">
1526+
<property name="sizePolicy">
1527+
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
1528+
<horstretch>0</horstretch>
1529+
<verstretch>0</verstretch>
1530+
</sizepolicy>
1531+
</property>
1532+
<property name="styleSheet">
1533+
<string notr="true">background-color: rgb(243, 243, 243);</string>
1534+
</property>
1535+
<property name="frameShape">
1536+
<enum>QFrame::StyledPanel</enum>
1537+
</property>
1538+
<property name="text">
1539+
<string> Label in Map Units </string>
1540+
</property>
1541+
<property name="alignment">
1542+
<set>Qt::AlignCenter</set>
1543+
</property>
1544+
<property name="margin">
1545+
<number>1</number>
1546+
</property>
1547+
</widget>
1548+
</item>
15491549
</layout>
15501550
</widget>
15511551
</item>
@@ -1690,6 +1690,198 @@
16901690
</layout>
16911691
</widget>
16921692
</item>
1693+
<item row="8" column="0">
1694+
<widget class="QgsCollapsibleGroupBox" name="mDirectSymbGroupBox">
1695+
<property name="title">
1696+
<string>Line direction symbols</string>
1697+
</property>
1698+
<property name="checkable">
1699+
<bool>true</bool>
1700+
</property>
1701+
<property name="checked">
1702+
<bool>true</bool>
1703+
</property>
1704+
<layout class="QVBoxLayout" name="verticalLayout_10">
1705+
<item>
1706+
<layout class="QHBoxLayout" name="horizontalLayout_19">
1707+
<item>
1708+
<widget class="QLabel" name="mDirectSymbLabel">
1709+
<property name="sizePolicy">
1710+
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
1711+
<horstretch>0</horstretch>
1712+
<verstretch>0</verstretch>
1713+
</sizepolicy>
1714+
</property>
1715+
<property name="text">
1716+
<string>Symbol(s)</string>
1717+
</property>
1718+
</widget>
1719+
</item>
1720+
<item>
1721+
<layout class="QHBoxLayout" name="horizontalLayout_21">
1722+
<property name="spacing">
1723+
<number>0</number>
1724+
</property>
1725+
<item>
1726+
<widget class="QToolButton" name="mDirectSymbLeftToolBtn">
1727+
<property name="maximumSize">
1728+
<size>
1729+
<width>16777215</width>
1730+
<height>22</height>
1731+
</size>
1732+
</property>
1733+
<property name="text">
1734+
<string>...</string>
1735+
</property>
1736+
</widget>
1737+
</item>
1738+
<item>
1739+
<widget class="QLineEdit" name="mDirectSymbLeftLineEdit">
1740+
<property name="sizePolicy">
1741+
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
1742+
<horstretch>0</horstretch>
1743+
<verstretch>0</verstretch>
1744+
</sizepolicy>
1745+
</property>
1746+
<property name="text">
1747+
<string>&lt;</string>
1748+
</property>
1749+
<property name="alignment">
1750+
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
1751+
</property>
1752+
</widget>
1753+
</item>
1754+
<item>
1755+
<widget class="QLabel" name="mDirectSymbLabel_2">
1756+
<property name="sizePolicy">
1757+
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
1758+
<horstretch>0</horstretch>
1759+
<verstretch>0</verstretch>
1760+
</sizepolicy>
1761+
</property>
1762+
<property name="styleSheet">
1763+
<string notr="true">background-color: rgb(243, 243, 243);</string>
1764+
</property>
1765+
<property name="frameShape">
1766+
<enum>QFrame::StyledPanel</enum>
1767+
</property>
1768+
<property name="text">
1769+
<string> Label </string>
1770+
</property>
1771+
<property name="alignment">
1772+
<set>Qt::AlignCenter</set>
1773+
</property>
1774+
<property name="margin">
1775+
<number>1</number>
1776+
</property>
1777+
</widget>
1778+
</item>
1779+
<item>
1780+
<widget class="QLineEdit" name="mDirectSymbRightLineEdit">
1781+
<property name="sizePolicy">
1782+
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
1783+
<horstretch>0</horstretch>
1784+
<verstretch>0</verstretch>
1785+
</sizepolicy>
1786+
</property>
1787+
<property name="text">
1788+
<string>&gt;</string>
1789+
</property>
1790+
</widget>
1791+
</item>
1792+
<item>
1793+
<widget class="QToolButton" name="mDirectSymbRightToolBtn">
1794+
<property name="maximumSize">
1795+
<size>
1796+
<width>16777215</width>
1797+
<height>22</height>
1798+
</size>
1799+
</property>
1800+
<property name="text">
1801+
<string>...</string>
1802+
</property>
1803+
</widget>
1804+
</item>
1805+
</layout>
1806+
</item>
1807+
<item>
1808+
<spacer name="horizontalSpacer_9">
1809+
<property name="orientation">
1810+
<enum>Qt::Horizontal</enum>
1811+
</property>
1812+
<property name="sizeHint" stdset="0">
1813+
<size>
1814+
<width>40</width>
1815+
<height>20</height>
1816+
</size>
1817+
</property>
1818+
</spacer>
1819+
</item>
1820+
</layout>
1821+
</item>
1822+
<item>
1823+
<layout class="QHBoxLayout" name="horizontalLayout_17">
1824+
<item>
1825+
<widget class="QLabel" name="mDirectSymbLabel_3">
1826+
<property name="sizePolicy">
1827+
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
1828+
<horstretch>0</horstretch>
1829+
<verstretch>0</verstretch>
1830+
</sizepolicy>
1831+
</property>
1832+
<property name="text">
1833+
<string>Placement</string>
1834+
</property>
1835+
</widget>
1836+
</item>
1837+
<item>
1838+
<widget class="QRadioButton" name="mDirectSymbRadioBtnLR">
1839+
<property name="sizePolicy">
1840+
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
1841+
<horstretch>0</horstretch>
1842+
<verstretch>0</verstretch>
1843+
</sizepolicy>
1844+
</property>
1845+
<property name="text">
1846+
<string>left/right</string>
1847+
</property>
1848+
<property name="checked">
1849+
<bool>true</bool>
1850+
</property>
1851+
</widget>
1852+
</item>
1853+
<item>
1854+
<widget class="QRadioButton" name="mDirectSymbRadioBtnAbove">
1855+
<property name="sizePolicy">
1856+
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
1857+
<horstretch>0</horstretch>
1858+
<verstretch>0</verstretch>
1859+
</sizepolicy>
1860+
</property>
1861+
<property name="text">
1862+
<string>above</string>
1863+
</property>
1864+
</widget>
1865+
</item>
1866+
<item>
1867+
<widget class="QRadioButton" name="mDirectSymbRadioBtnBelow">
1868+
<property name="text">
1869+
<string>below</string>
1870+
</property>
1871+
</widget>
1872+
</item>
1873+
<item>
1874+
<widget class="QCheckBox" name="mDirectSymbRevChkBx">
1875+
<property name="text">
1876+
<string>Reverse direction</string>
1877+
</property>
1878+
</widget>
1879+
</item>
1880+
</layout>
1881+
</item>
1882+
</layout>
1883+
</widget>
1884+
</item>
16931885
</layout>
16941886
</widget>
16951887
</widget>

0 commit comments

Comments
 (0)
Please sign in to comment.