Skip to content

Commit 6cd3d77

Browse files
committed
Double clicking an attribute item adds it to assigned items
1 parent ba0bed0 commit 6cd3d77

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
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();

0 commit comments

Comments
 (0)