|
25 | 25 | #include "qgssymbol.h"
|
26 | 26 | #include "qgsattributeeditor.h"
|
27 | 27 |
|
| 28 | +#include "qgisapp.h" |
| 29 | + |
28 | 30 | #include <QTableWidgetItem>
|
29 | 31 | #include <QSettings>
|
30 | 32 | #include <QLabel>
|
@@ -187,11 +189,34 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
|
187 | 189 | }
|
188 | 190 |
|
189 | 191 | connect( buttonBox, SIGNAL( rejected() ), mDialog, SLOT( reject() ) );
|
190 |
| - connect( buttonBox, SIGNAL( rejected() ), this, SLOT( rejected() ) ); |
191 | 192 | }
|
192 | 193 |
|
193 | 194 | QMetaObject::connectSlotsByName( mDialog );
|
194 | 195 |
|
| 196 | + connect( mDialog, SIGNAL( destroyed() ), this, SLOT( dialogDestroyed() ) ); |
| 197 | + |
| 198 | + if ( !vl->editFormInit().isEmpty() ) |
| 199 | + { |
| 200 | +#if 0 |
| 201 | + // would be nice if only PyQt's QVariant.toPyObject() wouldn't take ownership |
| 202 | + vl->setProperty( "featureForm.dialog", QVariant::fromValue( qobject_cast<QObject*>( mDialog ) ) ); |
| 203 | + vl->setProperty( "featureForm.id", QVariant( mpFeature->id() ) ); |
| 204 | +#endif |
| 205 | + |
| 206 | + QString module = vl->editFormInit(); |
| 207 | + int pos = module.lastIndexOf( "." ); |
| 208 | + if ( pos >= 0 ) |
| 209 | + { |
| 210 | + QgisApp::instance()->runPythonString( QString( "import %1" ).arg( module.left( pos ) ) ); |
| 211 | + } |
| 212 | + |
| 213 | + QgisApp::instance()->runPythonString( QString( "_qgis_featureform_%1 = wrapinstance( %2, QtGui.QDialog )" ).arg( mLayer->getLayerID() ).arg(( unsigned long ) mDialog ) ); |
| 214 | + |
| 215 | + QString expr = QString( "%1(_qgis_featureform_%2,'%2',%3)" ).arg( vl->editFormInit() ).arg( vl->getLayerID() ).arg( mpFeature->id() ); |
| 216 | + QgsDebugMsg( QString( "running featureForm init: %1" ).arg( expr ) ); |
| 217 | + QgisApp::instance()->runPythonString( expr ); |
| 218 | + } |
| 219 | + |
195 | 220 | restoreGeometry();
|
196 | 221 | }
|
197 | 222 |
|
@@ -223,17 +248,41 @@ void QgsAttributeDialog::accept()
|
223 | 248 |
|
224 | 249 | int QgsAttributeDialog::exec()
|
225 | 250 | {
|
226 |
| - return mDialog->exec(); |
| 251 | + if ( mDialog ) |
| 252 | + { |
| 253 | + return mDialog->exec(); |
| 254 | + } |
| 255 | + else |
| 256 | + { |
| 257 | + QgsDebugMsg( "No dialog" ); |
| 258 | + return QDialog::Rejected; |
| 259 | + } |
227 | 260 | }
|
228 | 261 |
|
229 | 262 | void QgsAttributeDialog::saveGeometry()
|
230 | 263 | {
|
231 |
| - QSettings settings; |
232 |
| - settings.setValue( mSettingsPath + "geometry", mDialog->saveGeometry() ); |
| 264 | + if ( mDialog ) |
| 265 | + { |
| 266 | + QSettings settings; |
| 267 | + settings.setValue( mSettingsPath + "geometry", mDialog->saveGeometry() ); |
| 268 | + } |
233 | 269 | }
|
234 | 270 |
|
235 | 271 | void QgsAttributeDialog::restoreGeometry()
|
236 | 272 | {
|
237 |
| - QSettings settings; |
238 |
| - mDialog->restoreGeometry( settings.value( mSettingsPath + "geometry" ).toByteArray() ); |
| 273 | + if ( mDialog ) |
| 274 | + { |
| 275 | + QSettings settings; |
| 276 | + mDialog->restoreGeometry( settings.value( mSettingsPath + "geometry" ).toByteArray() ); |
| 277 | + } |
| 278 | +} |
| 279 | + |
| 280 | +void QgsAttributeDialog::dialogDestroyed() |
| 281 | +{ |
| 282 | +#if 0 |
| 283 | + mLayer->setProperty( "featureForm.dialog", QVariant() ); |
| 284 | + mLayer->setProperty( "featureForm.id", QVariant() ); |
| 285 | +#endif |
| 286 | + QgisApp::instance()->runPythonString( QString( "del _qgis_featureform_%1" ).arg( mLayer->getLayerID() ) ); |
| 287 | + mDialog = NULL; |
239 | 288 | }
|
0 commit comments