18 #include "qgseditorwidgetwrapper.h"
31 #include <QTableWidgetItem>
35 #include <QScrollArea>
39 #include <QDialogButtonBox>
42 #include <QVBoxLayout>
45 #include <QPushButton>
55 , mFeature( thepFeature )
56 , mFeatureOwner( featureOwner )
58 , mFormNr( sFormCounter++ )
59 , mShowDialogButtons( showDialogButtons )
70 , mFeature( thepFeature )
71 , mFeatureOwner( featureOwner )
73 , mFormNr( sFormCounter++ )
74 , mShowDialogButtons( showDialogButtons )
90 QDialogButtonBox *buttonBox = NULL;
97 if (
file.open( QFile::ReadOnly ) )
102 loader.setWorkingDirectory( fi.dir() );
103 QWidget *myWidget = loader.load( &
file, qobject_cast<QWidget*>( parent() ) );
106 mDialog = qobject_cast<QDialog*>( myWidget );
107 buttonBox = myWidget->findChild<QDialogButtonBox*>();
113 mDialog =
new QDialog( qobject_cast<QWidget*>( parent() ) );
115 QGridLayout *gridLayout;
116 QTabWidget *tabWidget;
119 gridLayout =
new QGridLayout(
mDialog );
120 gridLayout->setObjectName( QString::fromUtf8(
"gridLayout" ) );
122 tabWidget =
new QTabWidget(
mDialog );
123 gridLayout->addWidget( tabWidget );
127 QWidget* tabPage =
new QWidget( tabWidget );
129 tabWidget->addTab( tabPage, widgDef->
name() );
130 QGridLayout *tabPageLayout =
new QGridLayout( tabPage );
140 QgsDebugMsg(
"No support for fields in attribute editor on top level" );
144 buttonBox =
new QDialogButtonBox(
mDialog );
145 buttonBox->setObjectName( QString::fromUtf8(
"buttonBox" ) );
146 gridLayout->addWidget( buttonBox );
152 mDialog =
new QDialog( qobject_cast<QWidget*>( parent() ) );
154 QGridLayout *gridLayout;
158 gridLayout =
new QGridLayout(
mDialog );
159 gridLayout->setSpacing( 6 );
160 gridLayout->setMargin( 2 );
161 gridLayout->setObjectName( QString::fromUtf8(
"gridLayout" ) );
162 mFrame =
new QFrame(
mDialog );
163 mFrame->setObjectName( QString::fromUtf8(
"mFrame" ) );
164 mFrame->setFrameShape( QFrame::NoFrame );
165 mFrame->setFrameShadow( QFrame::Plain );
167 gridLayout->addWidget( mFrame, 0, 0, 1, 1 );
169 buttonBox =
new QDialogButtonBox(
mDialog );
170 buttonBox->setObjectName( QString::fromUtf8(
"buttonBox" ) );
171 gridLayout->addWidget( buttonBox, 2, 0, 1, 1 );
176 QVBoxLayout *mypOuterLayout =
new QVBoxLayout();
177 mypOuterLayout->setContentsMargins( 0, 0, 0, 0 );
180 mFrame->setLayout( mypOuterLayout );
182 QScrollArea *mypScrollArea =
new QScrollArea();
183 mypScrollArea->setFrameShape( QFrame::NoFrame );
184 mypScrollArea->setFrameShadow( QFrame::Plain );
187 mypOuterLayout->addWidget( mypScrollArea );
189 QFrame *mypInnerFrame =
new QFrame();
190 mypInnerFrame->setFrameShape( QFrame::NoFrame );
191 mypInnerFrame->setFrameShadow( QFrame::Plain );
194 mypScrollArea->setWidget( mypInnerFrame );
196 mypScrollArea->setWidgetResizable(
true );
197 QGridLayout *mypInnerLayout =
new QGridLayout( mypInnerFrame );
200 for (
int fldIdx = 0; fldIdx < theFields.
count(); ++fldIdx )
206 const QgsField &myField = theFields[fldIdx];
216 QLabel *mypLabel =
new QLabel( myFieldName, mypInnerFrame );
222 myWidget->setEnabled(
true );
226 foreach ( QWidget *w, myWidget->findChildren<QWidget *>() )
228 w->setEnabled( qobject_cast<QLabel *>( w ) ?
true :
false );
233 foreach ( QWidget *w, myWidget->findChildren<QWidget *>() )
235 if ( qobject_cast<QWebView *>( w ) )
236 w->setEnabled(
true );
237 else if ( qobject_cast<QPushButton *>( w ) && w->objectName() ==
"openUrl" )
238 w->setEnabled(
true );
240 w->setEnabled(
false );
245 QgsEditorWidgetWrapper* ww = QgsEditorWidgetWrapper::fromWidget( myWidget );
248 ww->setEnabled(
false );
253 myWidget->setEnabled(
false );
259 mypInnerLayout->addWidget( mypLabel, index++, 0, 1, 2 );
260 mypInnerLayout->addWidget( myWidget, index++, 0, 1, 2 );
264 mypInnerLayout->addWidget( mypLabel, index, 0 );
265 mypInnerLayout->addWidget( myWidget, index, 1 );
278 myWidget->setProperty(
"qgisRelation", relation.
id() );
279 myWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
280 mypInnerLayout->addWidget( myWidget, index, 0, 1, 2 );
281 mypInnerLayout->setRowStretch( index, 2 );
286 if ( mypInnerLayout->rowCount() > 0 )
288 QWidget* widget = mypInnerLayout->itemAtPosition( 0, 1 )->widget();
290 widget->setFocus( Qt::OtherFocusReason );
293 QSpacerItem *mypSpacer =
new QSpacerItem( 0, 0, QSizePolicy::Fixed, QSizePolicy::MinimumExpanding );
294 mypInnerLayout->addItem( mypSpacer, mypInnerLayout->rowCount() + 1, 0 );
302 myDa.
setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
307 QList<QWidget *> myWidgets =
mDialog->findChildren<QWidget*>();
308 Q_FOREACH( QWidget* myWidget, myWidgets )
311 QVariant vRel = myWidget->property(
"qgisRelation" );
312 if ( vRel.isValid() )
319 if ( !myWidget->layout() )
321 myWidget->setLayout(
new QHBoxLayout() );
323 myWidget->layout()->addWidget( relWdg );
330 for (
int fldIdx = 0; fldIdx < theFields.
count(); ++fldIdx )
332 if ( myWidget->objectName() == theFields[fldIdx].name() )
340 myWidget->setEnabled(
true );
344 foreach ( QWidget *w, myWidget->findChildren<QWidget *>() )
346 w->setEnabled( qobject_cast<QLabel *>( w ) ?
true :
false );
351 foreach ( QWidget *w, myWidget->findChildren<QWidget *>() )
353 w->setEnabled( qobject_cast<QWebView *>( w ) ?
true :
false );
358 QgsEditorWidgetWrapper* ww = QgsEditorWidgetWrapper::fromWidget( myWidget );
361 ww->setEnabled(
false );
366 myWidget->setEnabled(
false );
374 foreach ( QLineEdit *le,
mDialog->findChildren<QLineEdit*>() )
376 if ( !le->objectName().startsWith(
"expr_" ) )
379 le->setReadOnly(
true );
380 QString expr = le->text();
381 le->setText(
tr(
"Error" ) );
404 switch ( value.type() )
406 case QVariant::Invalid: text =
"NULL";
break;
407 case QVariant::Int: text = QString::number( value.toInt() );
break;
408 case QVariant::Double: text = QString::number( value.toDouble() );
break;
409 case QVariant::String:
410 default: text = value.toString();
425 if (
mDialog->objectName().isEmpty() )
426 mDialog->setObjectName(
"QgsAttributeDialogBase" );
428 if (
mDialog->windowTitle().isEmpty() )
440 buttonBox->setStandardButtons( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
441 connect( buttonBox, SIGNAL( accepted() ),
mDialog, SLOT(
accept() ) );
442 connect( buttonBox, SIGNAL( accepted() ),
this, SLOT(
accept() ) );
446 buttonBox->setStandardButtons( QDialogButtonBox::Cancel );
449 connect( buttonBox, SIGNAL( rejected() ),
mDialog, SLOT( reject() ) );
461 buttonBox->setStandardButtons( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
462 connect( buttonBox, SIGNAL( accepted() ),
mDialog, SLOT(
accept() ) );
463 connect( buttonBox, SIGNAL( accepted() ),
this, SLOT(
accept() ) );
466 buttonBox->setVisible(
false );
470 QMetaObject::connectSlotsByName(
mDialog );
478 vl->setProperty(
"featureForm.dialog", QVariant::fromValue( qobject_cast<QObject*>(
mDialog ) ) );
479 vl->setProperty(
"featureForm.id", QVariant( mpFeature->id() ) );
483 int pos = module.lastIndexOf(
"." );
492 QString reload = QString(
"if hasattr(%1,'DEBUGMODE') and %1.DEBUGMODE:"
493 " reload(%1)" ).arg( module.left( pos ) );
497 QString form = QString(
"_qgis_featureform_%1 = sip.wrapinstance( %2, QtGui.QDialog )" )
499 .arg((
unsigned long )
mDialog );
501 QString layer = QString(
"_qgis_layer_%1 = sip.wrapinstance( %2, qgis.core.QgsVectorLayer )" )
503 .arg((
unsigned long )
mLayer );
507 QDateTime dt = QDateTime::currentDateTime();
508 QString featurevarname = QString(
"_qgis_feature_%1" ).arg( dt.toString(
"yyyyMMddhhmmsszzz" ) );
509 QString
feature = QString(
"%1 = sip.wrapinstance( %2, qgis.core.QgsFeature )" )
510 .arg( featurevarname )
517 mReturnvarname = QString(
"_qgis_feature_form_%1" ).arg( dt.toString(
"yyyyMMddhhmmsszzz" ) );
518 QString expr = QString(
"%5 = %1(_qgis_featureform_%2, _qgis_layer_%3, %4)" )
522 .arg( featurevarname )
525 QgsDebugMsg( QString(
"running featureForm init: %1" ).arg( expr ) );
569 for (
int idx = 0; idx < fields.
count(); ++idx )
587 return QDialog::Accepted;
595 mDialog->setAttribute( Qt::WA_DeleteOnClose );
599 mDialog->installEventFilter(
this );
635 mLayer->setProperty(
"featureForm.dialog", QVariant() );
636 mLayer->setProperty(
"featureForm.id", QVariant() );
640 QString expr = QString(
"if locals().has_key('_qgis_featureform_%1'): del _qgis_featureform_%1\n" ).arg(
mFormNr );
646 QString expr = QString(
"if locals().has_key('%1'): del %1\n" ).arg(
mReturnvarname );
660 case QEvent::WindowActivate:
663 case QEvent::WindowDeactivate: