29 #include <QTableWidgetItem>
33 #include <QScrollArea>
37 #include <QDialogButtonBox>
40 #include <QVBoxLayout>
43 #include <QPushButton>
49 , mSettingsPath(
"/Windows/AttributeDialog/" )
51 , mFeature( thepFeature )
52 , mFeatureOwner( featureOwner )
55 , mShowDialogButtons( showDialogButtons )
66 QDialogButtonBox *buttonBox = NULL;
73 if (
file.open( QFile::ReadOnly ) )
78 loader.setWorkingDirectory( fi.dir() );
79 QWidget *myWidget = loader.load( &
file, parent );
82 mDialog = qobject_cast<QDialog*>( myWidget );
83 buttonBox = myWidget->findChild<QDialogButtonBox*>();
89 mDialog =
new QDialog( parent );
91 QGridLayout *gridLayout;
92 QTabWidget *tabWidget;
95 gridLayout =
new QGridLayout(
mDialog );
96 gridLayout->setObjectName( QString::fromUtf8(
"gridLayout" ) );
98 tabWidget =
new QTabWidget(
mDialog );
99 gridLayout->addWidget( tabWidget );
103 QWidget* tabPage =
new QWidget( tabWidget );
105 tabWidget->addTab( tabPage, widgDef->
name() );
106 QGridLayout *tabPageLayout =
new QGridLayout( tabPage );
114 QgsDebugMsg(
"No support for fields in attribute editor on top level" );
118 buttonBox =
new QDialogButtonBox(
mDialog );
119 buttonBox->setObjectName( QString::fromUtf8(
"buttonBox" ) );
120 gridLayout->addWidget( buttonBox );
125 mDialog =
new QDialog( parent );
127 QGridLayout *gridLayout;
131 gridLayout =
new QGridLayout(
mDialog );
132 gridLayout->setSpacing( 6 );
133 gridLayout->setMargin( 2 );
134 gridLayout->setObjectName( QString::fromUtf8(
"gridLayout" ) );
135 mFrame =
new QFrame(
mDialog );
136 mFrame->setObjectName( QString::fromUtf8(
"mFrame" ) );
137 mFrame->setFrameShape( QFrame::NoFrame );
138 mFrame->setFrameShadow( QFrame::Plain );
140 gridLayout->addWidget( mFrame, 0, 0, 1, 1 );
142 buttonBox =
new QDialogButtonBox(
mDialog );
143 buttonBox->setObjectName( QString::fromUtf8(
"buttonBox" ) );
144 gridLayout->addWidget( buttonBox, 2, 0, 1, 1 );
149 QVBoxLayout *mypOuterLayout =
new QVBoxLayout();
150 mypOuterLayout->setContentsMargins( 0, 0, 0, 0 );
153 mFrame->setLayout( mypOuterLayout );
155 QScrollArea *mypScrollArea =
new QScrollArea();
156 mypScrollArea->setFrameShape( QFrame::NoFrame );
157 mypScrollArea->setFrameShadow( QFrame::Plain );
160 mypOuterLayout->addWidget( mypScrollArea );
162 QFrame *mypInnerFrame =
new QFrame();
163 mypInnerFrame->setFrameShape( QFrame::NoFrame );
164 mypInnerFrame->setFrameShadow( QFrame::Plain );
167 mypScrollArea->setWidget( mypInnerFrame );
169 mypScrollArea->setWidgetResizable(
true );
170 QGridLayout *mypInnerLayout =
new QGridLayout( mypInnerFrame );
173 for (
int fldIdx = 0; fldIdx < theFields.
count(); ++fldIdx )
179 const QgsField &myField = theFields[fldIdx];
182 myFieldName +=
" (" + vl->
dateFormat( fldIdx ) +
")";
189 QLabel *mypLabel =
new QLabel( myFieldName, mypInnerFrame );
195 myWidget->setEnabled(
true );
199 foreach ( QWidget *w, myWidget->findChildren<QWidget *>() )
201 w->setEnabled( qobject_cast<QLabel *>( w ) ?
true :
false );
206 foreach ( QWidget *w, myWidget->findChildren<QWidget *>() )
208 if ( qobject_cast<QWebView *>( w ) )
209 w->setEnabled(
true );
210 else if ( qobject_cast<QPushButton *>( w ) && w->objectName() ==
"openUrl" )
211 w->setEnabled(
true );
213 w->setEnabled(
false );
218 myWidget->setEnabled(
false );
224 mypInnerLayout->addWidget( mypLabel, index++, 0, 1, 2 );
225 mypInnerLayout->addWidget( myWidget, index++, 0, 1, 2 );
229 mypInnerLayout->addWidget( mypLabel, index, 0 );
230 mypInnerLayout->addWidget( myWidget, index, 1 );
236 if ( mypInnerLayout->rowCount() > 0 )
238 QWidget* widget = mypInnerLayout->itemAtPosition( 0, 1 )->widget();
240 widget->setFocus( Qt::OtherFocusReason );
243 QSpacerItem *mypSpacer =
new QSpacerItem( 10, 10, QSizePolicy::Fixed, QSizePolicy::Expanding );
244 mypInnerLayout->addItem( mypSpacer, mypInnerLayout->rowCount() + 1, 0 );
252 myDa.
setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
255 for (
int fldIdx = 0; fldIdx < theFields.
count(); ++fldIdx )
257 QList<QWidget *> myWidgets =
mDialog->findChildren<QWidget*>( theFields[fldIdx].name() );
258 if ( myWidgets.isEmpty() )
261 foreach ( QWidget *myWidget, myWidgets )
269 myWidget->setEnabled(
true );
273 foreach ( QWidget *w, myWidget->findChildren<QWidget *>() )
275 w->setEnabled( qobject_cast<QLabel *>( w ) ?
true :
false );
280 foreach ( QWidget *w, myWidget->findChildren<QWidget *>() )
282 w->setEnabled( qobject_cast<QWebView *>( w ) ?
true :
false );
287 myWidget->setEnabled(
false );
293 foreach ( QLineEdit *le,
mDialog->findChildren<QLineEdit*>() )
295 if ( !le->objectName().startsWith(
"expr_" ) )
298 le->setReadOnly(
true );
299 QString expr = le->text();
300 le->setText(
tr(
"Error" ) );
323 switch ( value.type() )
325 case QVariant::Invalid: text =
"NULL";
break;
326 case QVariant::Int: text = QString::number( value.toInt() );
break;
327 case QVariant::Double: text = QString::number( value.toDouble() );
break;
328 case QVariant::String:
329 default: text = value.toString();
342 if (
mDialog->objectName().isEmpty() )
343 mDialog->setObjectName(
"QgsAttributeDialogBase" );
345 if (
mDialog->windowTitle().isEmpty() )
346 mDialog->setWindowTitle(
tr(
"Attributes - %1" ).arg( vl->
name() ) );
357 buttonBox->setStandardButtons( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
358 connect( buttonBox, SIGNAL( accepted() ),
mDialog, SLOT(
accept() ) );
359 connect( buttonBox, SIGNAL( accepted() ),
this, SLOT(
accept() ) );
363 buttonBox->setStandardButtons( QDialogButtonBox::Cancel );
366 connect( buttonBox, SIGNAL( rejected() ),
mDialog, SLOT( reject() ) );
373 buttonBox->setVisible(
false );
377 QMetaObject::connectSlotsByName(
mDialog );
385 vl->setProperty(
"featureForm.dialog", QVariant::fromValue( qobject_cast<QObject*>(
mDialog ) ) );
386 vl->setProperty(
"featureForm.id", QVariant( mpFeature->id() ) );
390 int pos = module.lastIndexOf(
"." );
399 QString reload = QString(
"if hasattr(%1,'DEBUGMODE') and %1.DEBUGMODE:"
400 " reload(%1)" ).arg( module.left( pos ) );
406 QString form = QString(
"_qgis_featureform_%1 = sip.wrapinstance( %2, QtGui.QDialog )" )
408 .arg((
unsigned long )
mDialog );
410 QString layer = QString(
"_qgis_layer_%1 = sip.wrapinstance( %2, qgis.core.QgsVectorLayer )" )
412 .arg((
unsigned long ) vl );
416 QDateTime dt = QDateTime::currentDateTime();
417 QString featurevarname = QString(
"_qgis_feature_%1" ).arg( dt.toString(
"yyyyMMddhhmmsszzz" ) );
418 QString
feature = QString(
"%1 = sip.wrapinstance( %2, qgis.core.QgsFeature )" )
419 .arg( featurevarname )
426 mReturnvarname = QString(
"_qgis_feature_form_%1" ).arg( dt.toString(
"yyyyMMddhhmmsszzz" ) );
427 QString expr = QString(
"%5 = %1(_qgis_featureform_%2, _qgis_layer_%3, %4)" )
431 .arg( featurevarname )
434 QgsDebugMsg( QString(
"running featureForm init: %1" ).arg( expr ) );
478 for (
int idx = 0; idx < fields.
count(); ++idx )
496 return QDialog::Accepted;
504 mDialog->setAttribute( Qt::WA_DeleteOnClose );
508 mDialog->installEventFilter(
this );
544 mLayer->setProperty(
"featureForm.dialog", QVariant() );
545 mLayer->setProperty(
"featureForm.id", QVariant() );
549 QString expr = QString(
"if locals().has_key('_qgis_featureform_%1'): del _qgis_featureform_%1\n" ).arg(
mFormNr );
555 QString expr = QString(
"if locals().has_key('%1'): del %1\n" ).arg(
mReturnvarname );
569 case QEvent::WindowActivate:
572 case QEvent::WindowDeactivate: