Skip to content

Commit

Permalink
Merge pull request #224 from matthias-kuhn/diagram
Browse files Browse the repository at this point in the history
Minor diagram improvements
  • Loading branch information
mhugent committed Sep 6, 2012
2 parents 4d90320 + 6cd3d77 commit 24d50e4
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 32 deletions.
35 changes: 22 additions & 13 deletions src/app/qgsdiagramproperties.cpp
Expand Up @@ -343,6 +343,23 @@ void QgsDiagramProperties::on_mDiagramTypeComboBox_currentIndexChanged( int inde
mScaleDependencyLabel->hide();
}
}
void QgsDiagramProperties::addAttribute( QTreeWidgetItem * item )
{
QTreeWidgetItem *newItem = new QTreeWidgetItem( mDiagramAttributesTreeWidget );

newItem->setText( 0, item->text( 0 ) );
newItem->setData( 0, Qt::UserRole, item->data( 0, Qt::UserRole ) );
newItem->setFlags( newItem->flags() & ~Qt::ItemIsDropEnabled );

//set initial color for diagram category
int red = 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) );
int green = 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) );
int blue = 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) );
QColor randomColor( red, green, blue );
newItem->setBackground( 1, QBrush( randomColor ) );
mDiagramAttributesTreeWidget->addTopLevelItem( newItem );
}


void QgsDiagramProperties::on_mTransparencySlider_valueChanged( int value )
{
Expand All @@ -353,22 +370,14 @@ void QgsDiagramProperties::on_mAddCategoryPushButton_clicked()
{
foreach ( QTreeWidgetItem *attributeItem, mAttributesTreeWidget->selectedItems() )
{
QTreeWidgetItem *newItem = new QTreeWidgetItem( mDiagramAttributesTreeWidget );

newItem->setText( 0, attributeItem->text( 0 ) );
newItem->setData( 0, Qt::UserRole, attributeItem->data( 0, Qt::UserRole ) );
newItem->setFlags( newItem->flags() & ~Qt::ItemIsDropEnabled );

//set initial color for diagram category
int red = 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) );
int green = 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) );
int blue = 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) );
QColor randomColor( red, green, blue );
newItem->setBackground( 1, QBrush( randomColor ) );
mDiagramAttributesTreeWidget->addTopLevelItem( newItem );
addAttribute( attributeItem );
}
}

void QgsDiagramProperties::on_mAttributesTreeWidget_itemDoubleClicked( QTreeWidgetItem * item, int column )
{
addAttribute( item );
}

void QgsDiagramProperties::on_mRemoveCategoryPushButton_clicked()
{
Expand Down
5 changes: 3 additions & 2 deletions src/app/qgsdiagramproperties.h
Expand Up @@ -29,14 +29,15 @@ class QgsDiagramProperties : public QWidget, private Ui::QgsDiagramPropertiesBas

public:
QgsDiagramProperties( QgsVectorLayer* layer, QWidget* parent );

//void handleAttributeDoubleClicked( QTreeWidgetItem * item, int column );
/**Adds an attribute from the list of available attributes to the assigned attributes with a random color.*/
void addAttribute( QTreeWidgetItem * item );

public slots:
void apply();
void on_mDiagramTypeComboBox_currentIndexChanged( int index );
void on_mTransparencySlider_valueChanged( int value );
void on_mAddCategoryPushButton_clicked();
void on_mAttributesTreeWidget_itemDoubleClicked( QTreeWidgetItem * item, int column );
void on_mBackgroundColorButton_clicked();
void on_mFindMaximumValueButton_clicked();
void on_mDiagramPenColorButton_clicked();
Expand Down
3 changes: 3 additions & 0 deletions src/core/diagram/qgspiediagram.cpp
Expand Up @@ -31,6 +31,7 @@ QgsPieDiagram::~QgsPieDiagram()

QSizeF QgsPieDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is )
{
Q_UNUSED( c );
QgsAttributeMap::const_iterator attIt = attributes.find( is.classificationAttribute );
if ( attIt == attributes.constEnd() )
{
Expand Down Expand Up @@ -74,6 +75,8 @@ QSizeF QgsPieDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsR

QSizeF QgsPieDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s )
{
Q_UNUSED( c );
Q_UNUSED( attributes );
return s.size;
}

Expand Down
12 changes: 9 additions & 3 deletions src/core/diagram/qgstextdiagram.cpp
Expand Up @@ -32,7 +32,10 @@ QgsTextDiagram::~QgsTextDiagram()

QSizeF QgsTextDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is )
{
QgsAttributeMap::const_iterator attIt = attributes.find( is.classificationAttribute );
Q_UNUSED( c );

QgsAttributeMap::const_iterator attIt = attributes.find( is.classificationAttribute );

if ( attIt == attributes.constEnd() )
{
return QSizeF(); //zero size if attribute is missing
Expand Down Expand Up @@ -74,8 +77,11 @@ QSizeF QgsTextDiagram::diagramSize( const QgsAttributeMap& attributes, const Qgs
}

QSizeF QgsTextDiagram::diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s )
{
return s.size;
{
Q_UNUSED( c );
Q_UNUSED( attributes );

return s.size;
}

void QgsTextDiagram::renderDiagram( const QgsAttributeMap& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position )
Expand Down
31 changes: 17 additions & 14 deletions src/ui/qgsdiagrampropertiesbase.ui
Expand Up @@ -11,6 +11,9 @@
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QGroupBox" name="mDisplayDiagramsGroupBox">
<property name="title">
Expand All @@ -36,8 +39,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>742</width>
<height>610</height>
<width>756</width>
<height>627</height>
</rect>
</property>
<layout class="QVBoxLayout" name="scrollAreaLayout">
Expand Down Expand Up @@ -121,8 +124,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>708</width>
<height>278</height>
<width>723</width>
<height>356</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -331,8 +334,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>708</width>
<height>239</height>
<width>640</width>
<height>289</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -520,8 +523,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>165</width>
<height>220</height>
<width>216</width>
<height>284</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -682,8 +685,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>109</width>
<height>151</height>
<width>137</width>
<height>191</height>
</rect>
</property>
<attribute name="label">
Expand Down Expand Up @@ -747,7 +750,7 @@
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string>mOrientationButtonGroup</string>
<string notr="true">mOrientationButtonGroup</string>
</attribute>
</widget>
</item>
Expand All @@ -757,7 +760,7 @@
<string>Down</string>
</property>
<attribute name="buttonGroup">
<string>mOrientationButtonGroup</string>
<string notr="true">mOrientationButtonGroup</string>
</attribute>
</widget>
</item>
Expand All @@ -767,7 +770,7 @@
<string>Right</string>
</property>
<attribute name="buttonGroup">
<string>mOrientationButtonGroup</string>
<string notr="true">mOrientationButtonGroup</string>
</attribute>
</widget>
</item>
Expand All @@ -777,7 +780,7 @@
<string>Left</string>
</property>
<attribute name="buttonGroup">
<string>mOrientationButtonGroup</string>
<string notr="true">mOrientationButtonGroup</string>
</attribute>
</widget>
</item>
Expand Down

0 comments on commit 24d50e4

Please sign in to comment.