59_copyattributes.diff

patch enables the use to copy the selected value or all feature attributes. - Jürgen Fischer, 2009-08-01 04:09 PM

Download (3.68 KB)

View differences:

qgsidentifyresults.cpp (working copy)
29 29
#include <QPixmap>
30 30
#include <QSettings>
31 31
#include <QMenu>
32
#include <QClipboard>
32 33

  
33
#include <iostream>
34
#include "qgslogger.h"
34 35

  
35 36
QgsIdentifyResults::QgsIdentifyResults( const QgsAttributeAction& actions,
36 37
                                        QWidget *parent, Qt::WFlags f )
......
100 101
  if ( item == NULL )
101 102
    return;
102 103

  
103
  // The assumption is made that an instance of QgsIdentifyResults is
104
  // created for each new Identify Results dialog box, and that the
105
  // contents of the popup menu doesn't change during the time that
106
  // such a dialog box is around.
107 104
  if ( mActionPopup == 0 )
108 105
  {
109 106
    mActionPopup = new QMenu();
110
    QAction* a = mActionPopup->addAction( tr( "Run action" ) );
111
    a->setEnabled( false );
112
    mActionPopup->addSeparator();
113 107

  
114
    QgsAttributeAction::aIter iter = mActions.begin();
115
    for ( int j = 0; iter != mActions.end(); ++iter, ++j )
108
    QAction *a;
109
    a = mActionPopup->addAction( tr( "Copy attribute value" ) );
110
    a->setEnabled( true );
111
    a->setData( QVariant::fromValue( -2 ) );
112

  
113
    a = mActionPopup->addAction( tr( "Copy feature attributes" ) );
114
    a->setEnabled( true );
115
    a->setData( QVariant::fromValue( -1 ) );
116

  
117
    if ( mActions.size() > 0 )
116 118
    {
117
      QAction* a = mActionPopup->addAction( iter->name() );
118
      // The menu action stores an integer that is used later on to
119
      // associate an menu action with an actual qgis action.
120
      a->setData( QVariant::fromValue( j ) );
119
      // The assumption is made that an instance of QgsIdentifyResults is
120
      // created for each new Identify Results dialog box, and that the
121
      // contents of the popup menu doesn't change during the time that
122
      // such a dialog box is around.
123
      a = mActionPopup->addAction( tr( "Run action" ) );
124
      a->setEnabled( false );
125
      mActionPopup->addSeparator();
126

  
127
      QgsAttributeAction::aIter iter = mActions.begin();
128
      for ( int j = 0; iter != mActions.end(); ++iter, ++j )
129
      {
130
        QAction* a = mActionPopup->addAction( iter->name() );
131
        // The menu action stores an integer that is used later on to
132
        // associate an menu action with an actual qgis action.
133
        a->setData( QVariant::fromValue( j ) );
134
      }
121 135
    }
136

  
122 137
    connect( mActionPopup, SIGNAL( triggered( QAction* ) ),
123 138
             this, SLOT( popupItemSelected( QAction* ) ) );
124 139
  }
140

  
125 141
  // Save the attribute values as these are needed for substituting into
126 142
  // the action.
127 143
  extractAllItemData( item );
128 144

  
129
  if ( mActions.size() > 0 )
130
    mActionPopup->popup( event->globalPos() );
145
  mActionPopup->popup( event->globalPos() );
131 146
}
132 147

  
133 148
// Restore last window position/size and show the window
......
224 239
void QgsIdentifyResults::popupItemSelected( QAction* menuAction )
225 240
{
226 241
  int id = menuAction->data().toInt();
227
  mActions.doAction( id, mValues, mClickedOnValue );
242

  
243
  if ( id < 0 )
244
  {
245
    QClipboard *clipboard = QApplication::clipboard();
246
    QString text;
247

  
248
    if ( id == -2 )
249
    {
250
      text = mValues[ mClickedOnValue ].second;
251
    }
252
    else
253
    {
254
      for ( std::vector< std::pair<QString, QString> >::const_iterator it = mValues.begin(); it != mValues.end(); it++ )
255
      {
256
        text += QString( "%1: %2\n" ).arg( it->first ).arg( it->second );
257
      }
258
    }
259

  
260
    QgsDebugMsg( QString( "set clipboard: %1" ).arg( text ) );
261
    clipboard->setText( text );
262
  }
263
  else
264
  {
265
    mActions.doAction( id, mValues, mClickedOnValue );
266
  }
228 267
}
229 268

  
230 269
/** Expand all the identified features (show their attributes). */