Skip to content

Commit

Permalink
Double clicking an attribute item adds it to assigned items
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Sep 6, 2012
1 parent ba0bed0 commit 6cd3d77
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 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

0 comments on commit 6cd3d77

Please sign in to comment.