diff --git a/src/app/qgsdiagramproperties.cpp b/src/app/qgsdiagramproperties.cpp index f0cc449d80a..298bad2c924 100644 --- a/src/app/qgsdiagramproperties.cpp +++ b/src/app/qgsdiagramproperties.cpp @@ -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() { diff --git a/src/app/qgsdiagramproperties.h b/src/app/qgsdiagramproperties.h index 573e94b2952..88f15f5b34d 100644 --- a/src/app/qgsdiagramproperties.h +++ b/src/app/qgsdiagramproperties.h @@ -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();