@@ -31,6 +31,7 @@ back to QgsVectorLayer.
3131#include < QHeaderView>
3232#include < QMessageBox>
3333#include < QSettings>
34+ #include < QImageWriter>
3435
3536QgsAttributeActionDialog::QgsAttributeActionDialog ( QgsAttributeAction* actions,
3637 const QgsFields& fields,
@@ -61,6 +62,8 @@ QgsAttributeActionDialog::QgsAttributeActionDialog( QgsAttributeAction* actions,
6162 connect ( insertFieldButton, SIGNAL ( clicked () ), this , SLOT ( insertField () ) );
6263 connect ( insertExpressionButton, SIGNAL ( clicked () ), this , SLOT ( insertExpression () ) );
6364
65+ connect ( chooseIconButton, SIGNAL (clicked ()), this , SLOT ( chooseIcon () ) );
66+
6467 init ();
6568 // Populate the combo box with the field names. Will the field names
6669 // change? If so, they need to be passed into the init() call, or
@@ -78,13 +81,13 @@ void QgsAttributeActionDialog::init()
7881 for ( int i = 0 ; i < mActions ->size (); i++ )
7982 {
8083 const QgsAction action = ( *mActions )[i];
81- insertRow ( i, action.type (), action.name (), action.action (), action.capture () );
84+ insertRow ( i, action.type (), action.name (), action.action (), action.iconPath (), action. capture () );
8285 }
8386
8487 updateButtons ();
8588}
8689
87- void QgsAttributeActionDialog::insertRow ( int row, QgsAction::ActionType type, const QString &name, const QString &action, bool capture )
90+ void QgsAttributeActionDialog::insertRow ( int row, QgsAction::ActionType type, const QString &name, const QString &action, const QString& iconPath, bool capture )
8891{
8992 QTableWidgetItem* item;
9093 attributeActionTable->insertRow ( row );
@@ -97,6 +100,10 @@ void QgsAttributeActionDialog::insertRow( int row, QgsAction::ActionType type, c
97100 item->setFlags ( item->flags () & ~( Qt::ItemIsEditable | Qt::ItemIsUserCheckable ) );
98101 item->setCheckState ( capture ? Qt::Checked : Qt::Unchecked );
99102 attributeActionTable->setItem ( row, 3 , item );
103+ QIcon icon = QIcon ( iconPath );
104+ QTableWidgetItem* headerItem = new QTableWidgetItem ( icon, " " );
105+ headerItem->setData ( Qt::UserRole, iconPath );
106+ attributeActionTable->setVerticalHeaderItem ( row, headerItem );
100107
101108 updateButtons ();
102109}
@@ -250,7 +257,7 @@ void QgsAttributeActionDialog::insert( int pos )
250257 if ( pos >= numRows )
251258 {
252259 // Expand the table to have a row with index pos
253- insertRow ( pos, ( QgsAction::ActionType ) actionType->currentIndex (), name, actionAction->toPlainText (), captureCB->isChecked () );
260+ insertRow ( pos, ( QgsAction::ActionType ) actionType->currentIndex (), name, actionAction->toPlainText (), actionIcon-> text (), captureCB->isChecked () );
254261 }
255262 else
256263 {
@@ -259,6 +266,8 @@ void QgsAttributeActionDialog::insert( int pos )
259266 attributeActionTable->item ( pos, 1 )->setText ( name );
260267 attributeActionTable->item ( pos, 2 )->setText ( actionAction->toPlainText () );
261268 attributeActionTable->item ( pos, 3 )->setCheckState ( captureCB->isChecked () ? Qt::Checked : Qt::Unchecked );
269+ attributeActionTable->verticalHeaderItem ( pos )->setIcon ( QIcon ( actionIcon->text () ) );
270+ attributeActionTable->verticalHeaderItem ( pos )->setData ( Qt::UserRole, actionIcon->text () );
262271 }
263272 }
264273}
@@ -299,6 +308,23 @@ void QgsAttributeActionDialog::updateButtons()
299308 updateButton->setEnabled ( hasSelection && validNewAction );
300309}
301310
311+ void QgsAttributeActionDialog::chooseIcon ()
312+ {
313+ QList<QByteArray> list = QImageWriter::supportedImageFormats ();
314+ QStringList formatList;
315+ Q_FOREACH ( const QByteArray& format, list )
316+ formatList << QString ( " *.%1" ).arg ( QString ( format ) );
317+
318+ QString filter = QString ( " Images( %1 ); All( *.* )" ).arg ( formatList.join ( " " ) );
319+ QString icon = QFileDialog::getOpenFileName ( this , tr ( " Choose Icon..." ), actionIcon->text (), filter );
320+
321+ if ( !icon.isNull () )
322+ {
323+ actionIcon->setText ( icon );
324+ iconPreview->setPixmap ( QPixmap ( icon ) );
325+ }
326+ }
327+
302328void QgsAttributeActionDialog::insertField ()
303329{
304330 // Convert the selected field to an expression and
@@ -323,24 +349,25 @@ void QgsAttributeActionDialog::apply()
323349 const QgsAction::ActionType type = ( QgsAction::ActionType ) actionType->findText ( attributeActionTable->item ( i, 0 )->text () );
324350 const QString &name = attributeActionTable->item ( i, 1 )->text ();
325351 const QString &action = attributeActionTable->item ( i, 2 )->text ();
352+ const QString icon = attributeActionTable->verticalHeaderItem ( i )->data ( Qt::UserRole ).toString ();
326353 if ( !name.isEmpty () && !action.isEmpty () )
327354 {
328355 QTableWidgetItem *item = attributeActionTable->item ( i, 3 );
329- mActions ->addAction ( type, name, action, item->checkState () == Qt::Checked );
356+ mActions ->addAction ( type, name, action, icon, item->checkState () == Qt::Checked );
330357 }
331358 }
332359}
333360
334361void QgsAttributeActionDialog::addDefaultActions ()
335362{
336363 int pos = 0 ;
337- insertRow ( pos++, QgsAction::Generic, tr ( " Echo attribute's value" ), " echo \" [% \" MY_FIELD\" %]\" " , true );
338- insertRow ( pos++, QgsAction::Generic, tr ( " Run an application" ), " ogr2ogr -f \" ESRI Shapefile\" \" [% \" OUTPUT_PATH\" %]\" \" [% \" INPUT_FILE\" %]\" " , true );
339- insertRow ( pos++, QgsAction::GenericPython, tr ( " Get feature id" ), " QtGui.QMessageBox.information(None, \" Feature id\" , \" feature id is [% $id %]\" )" , false );
340- insertRow ( pos++, QgsAction::GenericPython, tr ( " Selected field's value (Identify features tool)" ), " QtGui.QMessageBox.information(None, \" Current field's value\" , \" [% $currentfield %]\" )" , false );
341- insertRow ( pos++, QgsAction::GenericPython, tr ( " Clicked coordinates (Run feature actions tool)" ), " QtGui.QMessageBox.information(None, \" Clicked coords\" , \" layer: [% $layerid %]\\ ncoords: ([% $clickx %],[% $clicky %])\" )" , false );
342- insertRow ( pos++, QgsAction::OpenUrl, tr ( " Open file" ), " [% \" PATH\" %]" , false );
343- insertRow ( pos++, QgsAction::OpenUrl, tr ( " Search on web based on attribute's value" ), " http://www.google.com/search?q=[% \" ATTRIBUTE\" %]" , false );
364+ insertRow ( pos++, QgsAction::Generic, tr ( " Echo attribute's value" ), " echo \" [% \" MY_FIELD\" %]\" " , " " , true );
365+ insertRow ( pos++, QgsAction::Generic, tr ( " Run an application" ), " ogr2ogr -f \" ESRI Shapefile\" \" [% \" OUTPUT_PATH\" %]\" \" [% \" INPUT_FILE\" %]\" " , " " , true );
366+ insertRow ( pos++, QgsAction::GenericPython, tr ( " Get feature id" ), " QtGui.QMessageBox.information(None, \" Feature id\" , \" feature id is [% $id %]\" )" , " " , false );
367+ insertRow ( pos++, QgsAction::GenericPython, tr ( " Selected field's value (Identify features tool)" ), " QtGui.QMessageBox.information(None, \" Current field's value\" , \" [% $currentfield %]\" )" , " " , false );
368+ insertRow ( pos++, QgsAction::GenericPython, tr ( " Clicked coordinates (Run feature actions tool)" ), " QtGui.QMessageBox.information(None, \" Clicked coords\" , \" layer: [% $layerid %]\\ ncoords: ([% $clickx %],[% $clicky %])\" )" , " " , false );
369+ insertRow ( pos++, QgsAction::OpenUrl, tr ( " Open file" ), " [% \" PATH\" %]" , " " , false );
370+ insertRow ( pos++, QgsAction::OpenUrl, tr ( " Search on web based on attribute's value" ), " http://www.google.com/search?q=[% \" ATTRIBUTE\" %]" , " " , false );
344371}
345372
346373void QgsAttributeActionDialog::itemSelectionChanged ()
0 commit comments