RememberValues.patch

Nathan Woodrow, 2010-11-30 11:19 PM

Download (3.66 KB)

View differences:

src/app/qgsattributedialog.cpp (working copy)
43 43
#include <QLineEdit>
44 44

  
45 45
int QgsAttributeDialog::smFormCounter = 0;
46
QCheckBox *cbxReuseValues;
46 47

  
47 48
QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeature, bool featureOwner )
48 49
    : mDialog( 0 )
......
99 100
    mFrame->setFrameShape( QFrame::StyledPanel );
100 101
    mFrame->setFrameShadow( QFrame::Raised );
101 102

  
102
    gridLayout->addWidget( mFrame, 0, 0, 1, 1 );
103
    gridLayout->addWidget( mFrame, 0, 0, 1, 2 );
103 104

  
105
    cbxReuseValues = new QCheckBox( "Save values for next time", mDialog );
106
    cbxReuseValues->setEnabled( true );
107

  
108
    QSettings settings;
109
    // read the digitizing settings
110
    bool reuseLastValues = settings.value( "/qgis/digitizing/reuseLastValues", false ).toBool();
111
    if ( reuseLastValues)
112
    {
113
      cbxReuseValues->setCheckState( Qt::Checked );
114
    }
115
    else
116
    {
117
      cbxReuseValues->setCheckState( Qt::Unchecked );
118
    }
119

  
120
    mFrame->setObjectName( QString::fromUtf8( "cbxRememberLastValues" ) );
121
    gridLayout->addWidget( cbxReuseValues, 2 , 0 , 1 , 1 );
122

  
104 123
    buttonBox = new QDialogButtonBox( mDialog );
105 124
    buttonBox->setObjectName( QString::fromUtf8( "buttonBox" ) );
106
    gridLayout->addWidget( buttonBox, 2, 0, 1, 1 );
125
    gridLayout->addWidget( buttonBox, 2, 1, 1, 1 );
107 126

  
108 127
    //
109 128
    //Set up dynamic inside a scroll box
......
279 298
  if ( !mLayer->isEditable() || !mFeature )
280 299
    return;
281 300

  
301
  QSettings settings;
302
  settings.setValue( "/qgis/digitizing/reuseLastValues", cbxReuseValues->isChecked() );
303
#ifdef QGISDEBUG
304
  QgsDebugMsg( QString( "reuseLastValues bool: %1" ).arg( cbxReuseValues->isChecked() ) );
305
#endif
306

  
282 307
  //write the new values back to the feature
283 308
  QgsAttributeMap myAttributes = mFeature->attributeMap();
284 309
  int myIndex = 0;
......
292 317

  
293 318
    ++myIndex;
294 319
  }
320

  
321

  
295 322
}
296 323

  
297 324
int QgsAttributeDialog::exec()
src/app/qgsfeatureaction.cpp (working copy)
136 136

  
137 137
  QSettings settings;
138 138
  bool reuseLastValues = settings.value( "/qgis/digitizing/reuseLastValues", false ).toBool();
139
  QgsDebugMsg( QString( "reuseLastValues: %1" ).arg( reuseLastValues ) );
140 139

  
141 140
  // add the fields to the QgsFeature
142 141
  const QgsFieldMap fields = mLayer->pendingFields();
......
165 164
  }
166 165
  else
167 166
  {
168
    QgsAttributeMap origValues;
169
    if ( reuseLastValues )
170
      origValues = mFeature.attributeMap();
171

  
172 167
    QgsAttributeDialog *dialog = newDialog( false );
173 168
    if ( dialog->exec() )
174 169
    {
170
      reuseLastValues = settings.value( "/qgis/digitizing/reuseLastValues", false ).toBool();
175 171
      if ( reuseLastValues )
176 172
      {
177 173
        for ( QgsFieldMap::const_iterator it = fields.constBegin(); it != fields.constEnd(); ++it )
178 174
        {
179 175
          const QgsAttributeMap &newValues = mFeature.attributeMap();
180
          if ( newValues.contains( it.key() )
181
               && origValues.contains( it.key() )
182
               && origValues[ it.key()] != newValues[ it.key()] )
183
          {
184
            QgsDebugMsg( QString( "saving %1 for %2" ).arg( mLastUsedValues[ mLayer ][ it.key()].toString() ).arg( it.key() ) );
185
            mLastUsedValues[ mLayer ][ it.key()] = newValues[ it.key()];
186
          }
176
          QgsDebugMsg( QString( "saving %1 for %2" ).arg( mLastUsedValues[ mLayer ][ it.key()].toString() ).arg( it.key() ) );
177
          mLastUsedValues[ mLayer ][ it.key()] = newValues[ it.key()];
187 178
        }
188 179
      }
189 180