Skip to content
Permalink
Browse files

Merge pull request #224 from matthias-kuhn/diagram

Minor diagram improvements
  • Loading branch information
mhugent committed Sep 6, 2012
2 parents 4d90320 + 6cd3d77 commit 24d50e4b93066390c2bb2832fb481892d32263b0
@@ -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 )
{
@@ -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()
{
@@ -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();
@@ -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() )
{
@@ -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;
}

@@ -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
@@ -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 )
@@ -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">
@@ -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">
@@ -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">
@@ -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">
@@ -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">
@@ -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">
@@ -747,7 +750,7 @@
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string>mOrientationButtonGroup</string>
<string notr="true">mOrientationButtonGroup</string>
</attribute>
</widget>
</item>
@@ -757,7 +760,7 @@
<string>Down</string>
</property>
<attribute name="buttonGroup">
<string>mOrientationButtonGroup</string>
<string notr="true">mOrientationButtonGroup</string>
</attribute>
</widget>
</item>
@@ -767,7 +770,7 @@
<string>Right</string>
</property>
<attribute name="buttonGroup">
<string>mOrientationButtonGroup</string>
<string notr="true">mOrientationButtonGroup</string>
</attribute>
</widget>
</item>
@@ -777,7 +780,7 @@
<string>Left</string>
</property>
<attribute name="buttonGroup">
<string>mOrientationButtonGroup</string>
<string notr="true">mOrientationButtonGroup</string>
</attribute>
</widget>
</item>

0 comments on commit 24d50e4

Please sign in to comment.
You can’t perform that action at this time.