Skip to content

Commit 35e747b

Browse files
committedAug 9, 2012
Text diagrams: new label placement method (x-height)
1 parent 3039f93 commit 35e747b

File tree

6 files changed

+822
-722
lines changed

6 files changed

+822
-722
lines changed
 

‎src/app/qgsvectorlayerproperties.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,16 @@ void QgsVectorLayerProperties::apply()
845845
{
846846
ds.sizeType = QgsDiagramSettings::MM;
847847
}
848+
849+
if ( !tr( "Height" ).compare( mLabelPlacementComboBox->currentText() ) )
850+
{
851+
ds.labelPlacementMethod = QgsDiagramSettings::Height;
852+
}
853+
else if ( !tr( "x-height" ).compare( mLabelPlacementComboBox->currentText() ) )
854+
{
855+
ds.labelPlacementMethod = QgsDiagramSettings::XHeight;
856+
}
857+
848858
ds.backgroundColor = mBackgroundColorButton->color();
849859
ds.penColor = mDiagramPenColorButton->color();
850860
ds.penWidth = mPenWidthSpinBox->value();
@@ -1306,6 +1316,19 @@ void QgsVectorLayerProperties::handleDiagramItemDoubleClick( QTreeWidgetItem * i
13061316
}
13071317
}
13081318

1319+
void QgsVectorLayerProperties::handleDiagramTypeChanged( const QString& itemtext )
1320+
{
1321+
if ( tr( "Text diagram" ) == itemtext )
1322+
{
1323+
mLabelPlacementComboBox->show();
1324+
mLabelPlacementLabel->show();
1325+
}
1326+
else {
1327+
mLabelPlacementComboBox->hide();
1328+
mLabelPlacementLabel->hide();
1329+
}
1330+
}
1331+
13091332
void QgsVectorLayerProperties::useNewSymbology()
13101333
{
13111334
int res = QMessageBox::question( this, tr( "Symbology" ),
@@ -1565,6 +1588,9 @@ void QgsVectorLayerProperties::initDiagramTab()
15651588
mDiagramTypeComboBox->addItem( tr( "Pie chart" ) );
15661589
mDiagramTypeComboBox->addItem( tr( "Text diagram" ) );
15671590

1591+
mLabelPlacementComboBox->addItem( tr( "Height" ) );
1592+
mLabelPlacementComboBox->addItem( tr( "x-height" ) );
1593+
15681594
//insert all attributes into the combo boxes
15691595
const QgsFieldMap& layerFields = layer->pendingFields();
15701596
QgsFieldMap::const_iterator fieldIt = layerFields.constBegin();
@@ -1594,6 +1620,7 @@ void QgsVectorLayerProperties::initDiagramTab()
15941620
mDisplayDiagramsCheckBox->setChecked( false );
15951621
mFixedSizeCheckBox->setChecked( true );
15961622
mDiagramUnitComboBox->setCurrentIndex( mDiagramUnitComboBox->findText( tr( "MM" ) ) );
1623+
mLabelPlacementComboBox->setCurrentIndex( mLabelPlacementComboBox->findText( tr( "XHeight" ) ) );
15971624
mDiagramSizeSpinBox->setValue( 30 );
15981625
mScaleDependentDiagramVisibilityCheckBox->setChecked( false );
15991626

@@ -1645,6 +1672,15 @@ void QgsVectorLayerProperties::initDiagramTab()
16451672
mDiagramUnitComboBox->setCurrentIndex( 1 );
16461673
}
16471674

1675+
if ( settingList.at( 0 ).labelPlacementMethod == QgsDiagramSettings::Height )
1676+
{
1677+
mLabelPlacementComboBox->setCurrentIndex( 0 );
1678+
}
1679+
else
1680+
{
1681+
mLabelPlacementComboBox->setCurrentIndex( 1 );
1682+
}
1683+
16481684

16491685

16501686
QList< QColor > categoryColors = settingList.at( 0 ).categoryColors;
@@ -1696,5 +1732,10 @@ void QgsVectorLayerProperties::initDiagramTab()
16961732
}
16971733
}
16981734
}
1735+
1736+
// Hide/Show diagram specific widgets
1737+
handleDiagramTypeChanged( mDiagramTypeComboBox->currentText() );
1738+
16991739
QObject::connect( mDiagramAttributesTreeWidget, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), this, SLOT( handleDiagramItemDoubleClick( QTreeWidgetItem*, int ) ) );
1740+
QObject::connect( mDiagramTypeComboBox, SIGNAL( currentIndexChanged( const QString& ) ), this, SLOT( handleDiagramTypeChanged( const QString& ) ) );
17001741
}

‎src/app/qgsvectorlayerproperties.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope
144144

145145
/**Set color for diagram category*/
146146
void handleDiagramItemDoubleClick( QTreeWidgetItem * item, int column );
147+
void handleDiagramTypeChanged( const QString& itemtext );
147148

148149
signals:
149150

‎src/core/qgsdiagram.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,28 @@ void QgsTextDiagram::renderDiagram( const QgsAttributeMap& att, QgsRenderContext
197197
for ( int i = 0; i < textPositions.size(); ++i )
198198
{
199199
QString val = att[ s.categoryIndices.at( i )].toString();
200-
//find out dimensions
200+
//find out dimesions
201201
double textWidth = fontMetrics.width( val );
202+
double textHeight = fontMetrics.height();
203+
202204
mPen.setColor( s.categoryColors.at( i ) );
203205
p->setPen( mPen );
204206
QPointF position = textPositions.at( i );
205-
p->drawText( QPointF( position.x() - textWidth / 2.0, position.y() + fontMetrics.xHeight() ), val );
207+
208+
// Calculate vertical placement
209+
double xOffset = 0;
210+
211+
switch( s.labelPlacementMethod )
212+
{
213+
case QgsDiagramSettings::Height:
214+
xOffset = textHeight / 2.0;
215+
break;
216+
217+
case QgsDiagramSettings::XHeight:
218+
xOffset = fontMetrics.xHeight();
219+
break;
220+
}
221+
p->drawText( QPointF( position.x() - textWidth / 2.0, position.y() + xOffset ), val );
206222
}
207223
}
208224

‎src/core/qgsdiagramrendererv2.cpp

Lines changed: 380 additions & 359 deletions
Large diffs are not rendered by default.

‎src/core/qgsdiagramrendererv2.h

Lines changed: 254 additions & 247 deletions
Large diffs are not rendered by default.

‎src/ui/qgsvectorlayerpropertiesbase.ui

Lines changed: 128 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<string>Layer Properties</string>
1515
</property>
1616
<property name="windowIcon">
17-
<iconset resource="../../images/images.qrc">
17+
<iconset resource="../../../../Quantum-GIS/images/images.qrc">
1818
<normaloff>:/images/icons/qgis-icon-16x16.png</normaloff>:/images/icons/qgis-icon-16x16.png</iconset>
1919
</property>
2020
<property name="modal">
@@ -76,7 +76,7 @@
7676
</property>
7777
<widget class="QWidget" name="tabWidgetPage1">
7878
<attribute name="icon">
79-
<iconset resource="../../images/images.qrc">
79+
<iconset resource="../../../../Quantum-GIS/images/images.qrc">
8080
<normaloff>:/images/themes/default/propertyicons/symbology.png</normaloff>:/images/themes/default/propertyicons/symbology.png</iconset>
8181
</attribute>
8282
<attribute name="title">
@@ -186,7 +186,7 @@
186186
</widget>
187187
<widget class="QWidget" name="labelingTab">
188188
<attribute name="icon">
189-
<iconset resource="../../images/images.qrc">
189+
<iconset resource="../../../../Quantum-GIS/images/images.qrc">
190190
<normaloff>:/images/themes/default/propertyicons/labels.png</normaloff>:/images/themes/default/propertyicons/labels.png</iconset>
191191
</attribute>
192192
<attribute name="title">
@@ -250,7 +250,7 @@
250250
</widget>
251251
<widget class="QWidget" name="tabWidgetPage3">
252252
<attribute name="icon">
253-
<iconset resource="../../images/images.qrc">
253+
<iconset resource="../../../../Quantum-GIS/images/images.qrc">
254254
<normaloff>:/images/themes/default/propertyicons/attributes.png</normaloff>:/images/themes/default/propertyicons/attributes.png</iconset>
255255
</attribute>
256256
<attribute name="title">
@@ -273,7 +273,7 @@
273273
</property>
274274
<property name="icon">
275275
<iconset>
276-
<normaloff>../../../../../.designer/xpm/new_attribute.png</normaloff>../../../../../.designer/xpm/new_attribute.png</iconset>
276+
<normaloff>../../../../../../.designer/xpm/new_attribute.png</normaloff>../../../../../../.designer/xpm/new_attribute.png</iconset>
277277
</property>
278278
<property name="shortcut">
279279
<string>Ctrl+N</string>
@@ -290,7 +290,7 @@
290290
</property>
291291
<property name="icon">
292292
<iconset>
293-
<normaloff>../../../../../.designer/xpm/delete_attribute.png</normaloff>../../../../../.designer/xpm/delete_attribute.png</iconset>
293+
<normaloff>../../../../../../.designer/xpm/delete_attribute.png</normaloff>../../../../../../.designer/xpm/delete_attribute.png</iconset>
294294
</property>
295295
<property name="shortcut">
296296
<string>Ctrl+X</string>
@@ -365,7 +365,7 @@
365365
</widget>
366366
<widget class="QWidget" name="tabWidgetPage4">
367367
<attribute name="icon">
368-
<iconset resource="../../images/images.qrc">
368+
<iconset resource="../../../../Quantum-GIS/images/images.qrc">
369369
<normaloff>:/images/themes/default/propertyicons/general.png</normaloff>:/images/themes/default/propertyicons/general.png</iconset>
370370
</attribute>
371371
<attribute name="title">
@@ -737,7 +737,7 @@
737737
</widget>
738738
<widget class="QWidget" name="tabWidgetPage5">
739739
<attribute name="icon">
740-
<iconset resource="../../images/images.qrc">
740+
<iconset resource="../../../../Quantum-GIS/images/images.qrc">
741741
<normaloff>:/images/themes/default/propertyicons/metadata.png</normaloff>:/images/themes/default/propertyicons/metadata.png</iconset>
742742
</attribute>
743743
<attribute name="title">
@@ -822,7 +822,7 @@
822822
</widget>
823823
<widget class="QWidget" name="tabWidgetPage6">
824824
<attribute name="icon">
825-
<iconset resource="../../images/images.qrc">
825+
<iconset resource="../../../../Quantum-GIS/images/images.qrc">
826826
<normaloff>:/images/themes/default/propertyicons/action.png</normaloff>:/images/themes/default/propertyicons/action.png</iconset>
827827
</attribute>
828828
<attribute name="title">
@@ -849,7 +849,7 @@
849849
</widget>
850850
<widget class="QWidget" name="mJoinPage">
851851
<attribute name="icon">
852-
<iconset resource="../../images/images.qrc">
852+
<iconset resource="../../../../Quantum-GIS/images/images.qrc">
853853
<normaloff>:/images/themes/default/propertyicons/join.png</normaloff>:/images/themes/default/propertyicons/join.png</iconset>
854854
</attribute>
855855
<attribute name="title">
@@ -883,7 +883,7 @@
883883
<string/>
884884
</property>
885885
<property name="icon">
886-
<iconset resource="../../images/images.qrc">
886+
<iconset resource="../../../../Quantum-GIS/images/images.qrc">
887887
<normaloff>:/images/themes/default/symbologyAdd.png</normaloff>:/images/themes/default/symbologyAdd.png</iconset>
888888
</property>
889889
</widget>
@@ -894,7 +894,7 @@
894894
<string/>
895895
</property>
896896
<property name="icon">
897-
<iconset resource="../../images/images.qrc">
897+
<iconset resource="../../../../Quantum-GIS/images/images.qrc">
898898
<normaloff>:/images/themes/default/symbologyRemove.png</normaloff>:/images/themes/default/symbologyRemove.png</iconset>
899899
</property>
900900
</widget>
@@ -942,7 +942,7 @@
942942
</widget>
943943
<widget class="QWidget" name="mDiagramPage">
944944
<attribute name="icon">
945-
<iconset resource="../../images/images.qrc">
945+
<iconset resource="../../../../Quantum-GIS/images/images.qrc">
946946
<normaloff>:/images/themes/default/propertyicons/diagram.png</normaloff>:/images/themes/default/propertyicons/diagram.png</iconset>
947947
</attribute>
948948
<attribute name="title">
@@ -1182,104 +1182,6 @@
11821182
</layout>
11831183
</widget>
11841184
</item>
1185-
<item row="2" column="0" colspan="6">
1186-
<widget class="QGroupBox" name="mSizeGroupBox">
1187-
<property name="title">
1188-
<string>Size</string>
1189-
</property>
1190-
<layout class="QGridLayout" name="gridLayout_12">
1191-
<item row="0" column="0">
1192-
<widget class="QCheckBox" name="mFixedSizeCheckBox">
1193-
<property name="text">
1194-
<string>Fixed size</string>
1195-
</property>
1196-
</widget>
1197-
</item>
1198-
<item row="0" column="1">
1199-
<widget class="QDoubleSpinBox" name="mDiagramSizeSpinBox">
1200-
<property name="maximum">
1201-
<double>9999999.990000000223517</double>
1202-
</property>
1203-
</widget>
1204-
</item>
1205-
<item row="0" column="3">
1206-
<spacer name="horizontalSpacer_2">
1207-
<property name="orientation">
1208-
<enum>Qt::Horizontal</enum>
1209-
</property>
1210-
<property name="sizeHint" stdset="0">
1211-
<size>
1212-
<width>335</width>
1213-
<height>20</height>
1214-
</size>
1215-
</property>
1216-
</spacer>
1217-
</item>
1218-
<item row="1" column="0" colspan="4">
1219-
<widget class="QLabel" name="mLinearlyScalingLabel">
1220-
<property name="text">
1221-
<string>Scale linearly between 0 and the following attribute value / diagram size:</string>
1222-
</property>
1223-
<property name="wordWrap">
1224-
<bool>true</bool>
1225-
</property>
1226-
</widget>
1227-
</item>
1228-
<item row="2" column="0" colspan="4">
1229-
<layout class="QHBoxLayout" name="mLinearlyScalingLayout">
1230-
<item>
1231-
<widget class="QLabel" name="mSizeAttributeLabel">
1232-
<property name="text">
1233-
<string>Attribute</string>
1234-
</property>
1235-
</widget>
1236-
</item>
1237-
<item>
1238-
<widget class="QComboBox" name="mSizeAttributeComboBox"/>
1239-
</item>
1240-
<item>
1241-
<widget class="QPushButton" name="mFindMaximumValueButton">
1242-
<property name="text">
1243-
<string>Find maximum value</string>
1244-
</property>
1245-
</widget>
1246-
</item>
1247-
<item>
1248-
<widget class="QLineEdit" name="mValueLineEdit"/>
1249-
</item>
1250-
<item>
1251-
<widget class="QLabel" name="mSizeLabel">
1252-
<property name="text">
1253-
<string>Size</string>
1254-
</property>
1255-
</widget>
1256-
</item>
1257-
<item>
1258-
<widget class="QSpinBox" name="mSizeSpinBox">
1259-
<property name="maximum">
1260-
<number>10000000</number>
1261-
</property>
1262-
</widget>
1263-
</item>
1264-
</layout>
1265-
</item>
1266-
<item row="0" column="2">
1267-
<layout class="QHBoxLayout" name="horizontalLayout_12">
1268-
<item>
1269-
<widget class="QLabel" name="mDiagramUnitsLabel">
1270-
<property name="text">
1271-
<string>Size units</string>
1272-
</property>
1273-
</widget>
1274-
</item>
1275-
<item>
1276-
<widget class="QComboBox" name="mDiagramUnitComboBox"/>
1277-
</item>
1278-
</layout>
1279-
</item>
1280-
</layout>
1281-
</widget>
1282-
</item>
12831185
<item row="3" column="0" colspan="6">
12841186
<widget class="QGroupBox" name="mPlacementGroupBox">
12851187
<property name="title">
@@ -1375,6 +1277,20 @@
13751277
</item>
13761278
</layout>
13771279
</item>
1280+
<item row="2" column="0">
1281+
<layout class="QHBoxLayout" name="horizontalLayout_14">
1282+
<item>
1283+
<widget class="QLabel" name="mLabelPlacementLabel">
1284+
<property name="text">
1285+
<string>Label placement:</string>
1286+
</property>
1287+
</widget>
1288+
</item>
1289+
<item>
1290+
<widget class="QComboBox" name="mLabelPlacementComboBox"/>
1291+
</item>
1292+
</layout>
1293+
</item>
13781294
</layout>
13791295
</widget>
13801296
</item>
@@ -1420,7 +1336,7 @@
14201336
<string/>
14211337
</property>
14221338
<property name="icon">
1423-
<iconset resource="../../images/images.qrc">
1339+
<iconset resource="../../../../Quantum-GIS/images/images.qrc">
14241340
<normaloff>:/images/themes/default/symbologyRemove.png</normaloff>:/images/themes/default/symbologyRemove.png</iconset>
14251341
</property>
14261342
</widget>
@@ -1437,7 +1353,7 @@
14371353
<string/>
14381354
</property>
14391355
<property name="icon">
1440-
<iconset resource="../../images/images.qrc">
1356+
<iconset resource="../../../../Quantum-GIS/images/images.qrc">
14411357
<normaloff>:/images/themes/default/symbologyAdd.png</normaloff>:/images/themes/default/symbologyAdd.png</iconset>
14421358
</property>
14431359
</widget>
@@ -1459,6 +1375,104 @@
14591375
</column>
14601376
</widget>
14611377
</item>
1378+
<item row="2" column="0" colspan="6">
1379+
<widget class="QGroupBox" name="mSizeGroupBox">
1380+
<property name="title">
1381+
<string>Size</string>
1382+
</property>
1383+
<layout class="QGridLayout" name="gridLayout_12">
1384+
<item row="0" column="0">
1385+
<widget class="QCheckBox" name="mFixedSizeCheckBox">
1386+
<property name="text">
1387+
<string>Fixed size</string>
1388+
</property>
1389+
</widget>
1390+
</item>
1391+
<item row="0" column="1">
1392+
<widget class="QDoubleSpinBox" name="mDiagramSizeSpinBox">
1393+
<property name="maximum">
1394+
<double>9999999.990000000223517</double>
1395+
</property>
1396+
</widget>
1397+
</item>
1398+
<item row="0" column="3">
1399+
<spacer name="horizontalSpacer_2">
1400+
<property name="orientation">
1401+
<enum>Qt::Horizontal</enum>
1402+
</property>
1403+
<property name="sizeHint" stdset="0">
1404+
<size>
1405+
<width>335</width>
1406+
<height>20</height>
1407+
</size>
1408+
</property>
1409+
</spacer>
1410+
</item>
1411+
<item row="1" column="0" colspan="4">
1412+
<widget class="QLabel" name="mLinearlyScalingLabel">
1413+
<property name="text">
1414+
<string>Scale linearly between 0 and the following attribute value / diagram size:</string>
1415+
</property>
1416+
<property name="wordWrap">
1417+
<bool>true</bool>
1418+
</property>
1419+
</widget>
1420+
</item>
1421+
<item row="2" column="0" colspan="4">
1422+
<layout class="QHBoxLayout" name="mLinearlyScalingLayout">
1423+
<item>
1424+
<widget class="QLabel" name="mSizeAttributeLabel">
1425+
<property name="text">
1426+
<string>Attribute</string>
1427+
</property>
1428+
</widget>
1429+
</item>
1430+
<item>
1431+
<widget class="QComboBox" name="mSizeAttributeComboBox"/>
1432+
</item>
1433+
<item>
1434+
<widget class="QPushButton" name="mFindMaximumValueButton">
1435+
<property name="text">
1436+
<string>Find maximum value</string>
1437+
</property>
1438+
</widget>
1439+
</item>
1440+
<item>
1441+
<widget class="QLineEdit" name="mValueLineEdit"/>
1442+
</item>
1443+
<item>
1444+
<widget class="QLabel" name="mSizeLabel">
1445+
<property name="text">
1446+
<string>Size</string>
1447+
</property>
1448+
</widget>
1449+
</item>
1450+
<item>
1451+
<widget class="QSpinBox" name="mSizeSpinBox">
1452+
<property name="maximum">
1453+
<number>10000000</number>
1454+
</property>
1455+
</widget>
1456+
</item>
1457+
</layout>
1458+
</item>
1459+
<item row="0" column="2">
1460+
<layout class="QHBoxLayout" name="horizontalLayout_12">
1461+
<item>
1462+
<widget class="QLabel" name="mDiagramUnitsLabel">
1463+
<property name="text">
1464+
<string>Size units</string>
1465+
</property>
1466+
</widget>
1467+
</item>
1468+
<item>
1469+
<widget class="QComboBox" name="mDiagramUnitComboBox"/>
1470+
</item>
1471+
</layout>
1472+
</item>
1473+
</layout>
1474+
</widget>
1475+
</item>
14621476
</layout>
14631477
</widget>
14641478
</widget>
@@ -1485,7 +1499,7 @@
14851499
<tabstop>pbnQueryBuilder</tabstop>
14861500
</tabstops>
14871501
<resources>
1488-
<include location="../../images/images.qrc"/>
1502+
<include location="../../../../Quantum-GIS/images/images.qrc"/>
14891503
</resources>
14901504
<connections>
14911505
<connection>

0 commit comments

Comments
 (0)
Please sign in to comment.