Skip to content

Commit 24d50e4

Browse files
committedSep 6, 2012
Merge pull request #224 from matthias-kuhn/diagram
Minor diagram improvements
2 parents 4d90320 + 6cd3d77 commit 24d50e4

File tree

5 files changed

+54
-32
lines changed

5 files changed

+54
-32
lines changed
 

‎src/app/qgsdiagramproperties.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,23 @@ void QgsDiagramProperties::on_mDiagramTypeComboBox_currentIndexChanged( int inde
343343
mScaleDependencyLabel->hide();
344344
}
345345
}
346+
void QgsDiagramProperties::addAttribute( QTreeWidgetItem * item )
347+
{
348+
QTreeWidgetItem *newItem = new QTreeWidgetItem( mDiagramAttributesTreeWidget );
349+
350+
newItem->setText( 0, item->text( 0 ) );
351+
newItem->setData( 0, Qt::UserRole, item->data( 0, Qt::UserRole ) );
352+
newItem->setFlags( newItem->flags() & ~Qt::ItemIsDropEnabled );
353+
354+
//set initial color for diagram category
355+
int red = 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) );
356+
int green = 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) );
357+
int blue = 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) );
358+
QColor randomColor( red, green, blue );
359+
newItem->setBackground( 1, QBrush( randomColor ) );
360+
mDiagramAttributesTreeWidget->addTopLevelItem( newItem );
361+
}
362+
346363

347364
void QgsDiagramProperties::on_mTransparencySlider_valueChanged( int value )
348365
{
@@ -353,22 +370,14 @@ void QgsDiagramProperties::on_mAddCategoryPushButton_clicked()
353370
{
354371
foreach ( QTreeWidgetItem *attributeItem, mAttributesTreeWidget->selectedItems() )
355372
{
356-
QTreeWidgetItem *newItem = new QTreeWidgetItem( mDiagramAttributesTreeWidget );
357-
358-
newItem->setText( 0, attributeItem->text( 0 ) );
359-
newItem->setData( 0, Qt::UserRole, attributeItem->data( 0, Qt::UserRole ) );
360-
newItem->setFlags( newItem->flags() & ~Qt::ItemIsDropEnabled );
361-
362-
//set initial color for diagram category
363-
int red = 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) );
364-
int green = 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) );
365-
int blue = 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) );
366-
QColor randomColor( red, green, blue );
367-
newItem->setBackground( 1, QBrush( randomColor ) );
368-
mDiagramAttributesTreeWidget->addTopLevelItem( newItem );
373+
addAttribute( attributeItem );
369374
}
370375
}
371376

377+
void QgsDiagramProperties::on_mAttributesTreeWidget_itemDoubleClicked( QTreeWidgetItem * item, int column )
378+
{
379+
addAttribute( item );
380+
}
372381

373382
void QgsDiagramProperties::on_mRemoveCategoryPushButton_clicked()
374383
{

‎src/app/qgsdiagramproperties.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ class QgsDiagramProperties : public QWidget, private Ui::QgsDiagramPropertiesBas
2929

3030
public:
3131
QgsDiagramProperties( QgsVectorLayer* layer, QWidget* parent );
32-
33-
//void handleAttributeDoubleClicked( QTreeWidgetItem * item, int column );
32+
/**Adds an attribute from the list of available attributes to the assigned attributes with a random color.*/
33+
void addAttribute( QTreeWidgetItem * item );
3434

3535
public slots:
3636
void apply();
3737
void on_mDiagramTypeComboBox_currentIndexChanged( int index );
3838
void on_mTransparencySlider_valueChanged( int value );
3939
void on_mAddCategoryPushButton_clicked();
40+
void on_mAttributesTreeWidget_itemDoubleClicked( QTreeWidgetItem * item, int column );
4041
void on_mBackgroundColorButton_clicked();
4142
void on_mFindMaximumValueButton_clicked();
4243
void on_mDiagramPenColorButton_clicked();

‎src/core/diagram/qgspiediagram.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ QgsPieDiagram::~QgsPieDiagram()
3131

3232
QSizeF QgsPieDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is )
3333
{
34+
Q_UNUSED( c );
3435
QgsAttributeMap::const_iterator attIt = attributes.find( is.classificationAttribute );
3536
if ( attIt == attributes.constEnd() )
3637
{
@@ -74,6 +75,8 @@ QSizeF QgsPieDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsR
7475

7576
QSizeF QgsPieDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s )
7677
{
78+
Q_UNUSED( c );
79+
Q_UNUSED( attributes );
7780
return s.size;
7881
}
7982

‎src/core/diagram/qgstextdiagram.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ QgsTextDiagram::~QgsTextDiagram()
3232

3333
QSizeF QgsTextDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is )
3434
{
35-
QgsAttributeMap::const_iterator attIt = attributes.find( is.classificationAttribute );
35+
Q_UNUSED( c );
36+
37+
QgsAttributeMap::const_iterator attIt = attributes.find( is.classificationAttribute );
38+
3639
if ( attIt == attributes.constEnd() )
3740
{
3841
return QSizeF(); //zero size if attribute is missing
@@ -74,8 +77,11 @@ QSizeF QgsTextDiagram::diagramSize( const QgsAttributeMap& attributes, const Qgs
7477
}
7578

7679
QSizeF QgsTextDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s )
77-
{
78-
return s.size;
80+
{
81+
Q_UNUSED( c );
82+
Q_UNUSED( attributes );
83+
84+
return s.size;
7985
}
8086

8187
void QgsTextDiagram::renderDiagram( const QgsAttributeMap& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position )

‎src/ui/qgsdiagrampropertiesbase.ui

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
</rect>
1212
</property>
1313
<layout class="QVBoxLayout" name="verticalLayout">
14+
<property name="margin">
15+
<number>0</number>
16+
</property>
1417
<item>
1518
<widget class="QGroupBox" name="mDisplayDiagramsGroupBox">
1619
<property name="title">
@@ -36,8 +39,8 @@
3639
<rect>
3740
<x>0</x>
3841
<y>0</y>
39-
<width>742</width>
40-
<height>610</height>
42+
<width>756</width>
43+
<height>627</height>
4144
</rect>
4245
</property>
4346
<layout class="QVBoxLayout" name="scrollAreaLayout">
@@ -121,8 +124,8 @@
121124
<rect>
122125
<x>0</x>
123126
<y>0</y>
124-
<width>708</width>
125-
<height>278</height>
127+
<width>723</width>
128+
<height>356</height>
126129
</rect>
127130
</property>
128131
<attribute name="label">
@@ -331,8 +334,8 @@
331334
<rect>
332335
<x>0</x>
333336
<y>0</y>
334-
<width>708</width>
335-
<height>239</height>
337+
<width>640</width>
338+
<height>289</height>
336339
</rect>
337340
</property>
338341
<attribute name="label">
@@ -520,8 +523,8 @@
520523
<rect>
521524
<x>0</x>
522525
<y>0</y>
523-
<width>165</width>
524-
<height>220</height>
526+
<width>216</width>
527+
<height>284</height>
525528
</rect>
526529
</property>
527530
<attribute name="label">
@@ -682,8 +685,8 @@
682685
<rect>
683686
<x>0</x>
684687
<y>0</y>
685-
<width>109</width>
686-
<height>151</height>
688+
<width>137</width>
689+
<height>191</height>
687690
</rect>
688691
</property>
689692
<attribute name="label">
@@ -747,7 +750,7 @@
747750
<bool>true</bool>
748751
</property>
749752
<attribute name="buttonGroup">
750-
<string>mOrientationButtonGroup</string>
753+
<string notr="true">mOrientationButtonGroup</string>
751754
</attribute>
752755
</widget>
753756
</item>
@@ -757,7 +760,7 @@
757760
<string>Down</string>
758761
</property>
759762
<attribute name="buttonGroup">
760-
<string>mOrientationButtonGroup</string>
763+
<string notr="true">mOrientationButtonGroup</string>
761764
</attribute>
762765
</widget>
763766
</item>
@@ -767,7 +770,7 @@
767770
<string>Right</string>
768771
</property>
769772
<attribute name="buttonGroup">
770-
<string>mOrientationButtonGroup</string>
773+
<string notr="true">mOrientationButtonGroup</string>
771774
</attribute>
772775
</widget>
773776
</item>
@@ -777,7 +780,7 @@
777780
<string>Left</string>
778781
</property>
779782
<attribute name="buttonGroup">
780-
<string>mOrientationButtonGroup</string>
783+
<string notr="true">mOrientationButtonGroup</string>
781784
</attribute>
782785
</widget>
783786
</item>

0 commit comments

Comments
 (0)
Please sign in to comment.