33 #include <QProgressDialog>
34 #include <QMessageBox>
37 : QStackedWidget( parent )
39 , mMasterModel( NULL )
40 , mAttributeDialog( NULL )
42 , mProgressDlg( NULL )
43 , mFeatureSelectionManager( NULL )
59 connect(
this, SIGNAL( currentChanged(
int ) ),
this, SLOT(
saveEditChanges() ) );
71 connect( mTableView, SIGNAL( willShowContextMenu( QMenu*, QModelIndex ) ),
this, SLOT(
viewWillShowContextMenu( QMenu*, QModelIndex ) ) );
97 if ( displayExpression ==
"" )
102 displayExpression = QString(
"COALESCE(\"%1\", '<NULL>')" ).arg( defaultField );
107 if ( displayExpression ==
"" )
111 if ( pkAttrs.size() > 0 )
113 if ( pkAttrs.size() == 1 )
114 defaultField = pkAttrs.at( 0 );
117 QStringList pkFields;
119 Q_FOREACH(
int attr, pkAttrs )
121 pkFields.append(
"COALESCE(\"" + fields[attr].name() +
"\", '<NULL>')" );
124 displayExpression = pkFields.join(
"||', '||" );
126 else if ( fields.size() > 0 )
128 if ( fields.size() == 1 )
129 defaultField = fields.at( 0 ).name();
132 QStringList fieldNames;
135 fieldNames.append(
"COALESCE(\"" + field.
name() +
"\", '<NULL>')" );
138 displayExpression = fieldNames.join(
"||', '||" );
143 displayExpression =
"'[Please define preview text]'";
148 QList< QAction* > previewActions = mFeatureListPreviewButton->actions();
149 foreach ( QAction* a, previewActions )
151 if ( a != mActionExpressionPreview )
158 mFeatureListPreviewButton->addAction( mActionExpressionPreview );
159 mFeatureListPreviewButton->addAction( mActionPreviewColumnsMenu );
161 foreach (
const QgsField field, fields )
166 QString text = field.
name();
169 QAction* previewAction =
new QAction( icon, text, mFeatureListPreviewButton );
174 if ( text == defaultField )
176 mFeatureListPreviewButton->setDefaultAction( previewAction );
182 if ( !mFeatureListPreviewButton->defaultAction() )
184 mFeatureList->setDisplayExpression( displayExpression );
185 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
189 mFeatureListPreviewButton->defaultAction()->trigger();
207 setCurrentIndex( view );
224 int cacheSize = qMax( 1, settings.value(
"/qgis/attributeTableRowCache",
"10000" ).toInt() );
226 mLayerCache->setCacheGeometry(
false );
229 connect( mLayerCache, SIGNAL(
progress(
int,
bool & ) ),
this, SLOT(
progress(
int,
bool & ) ) );
232 mLayerCache->setFullCache(
true );
235 connect( layer, SIGNAL( editingStarted() ),
this, SLOT(
editingToggled() ) );
236 connect( layer, SIGNAL( beforeCommitChanges() ),
this, SLOT(
editingToggled() ) );
237 connect( layer, SIGNAL( editingStopped() ),
this, SLOT(
editingToggled() ) );
271 bool dontChange =
false;
300 mFeatureList->setEditSelection( fids );
317 if ( buttonBox && buttonBox->button( QDialogButtonBox::Ok ) )
319 QPushButton* okBtn = buttonBox->button( QDialogButtonBox::Ok );
332 if ( src.count() != dst.count() )
340 for ( ; i < dst.count() && dst[i] == src[i]; ++i )
343 if ( i == dst.count() )
348 for ( ; i < dst.count(); ++i )
350 if ( dst[i] == src[i] )
371 dlg.setWindowTitle(
tr(
"Expression based preview" ) );
374 if ( dlg.exec() == QDialog::Accepted )
376 mFeatureList->setDisplayExpression( dlg.expressionText() );
377 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
378 mFeatureListPreviewButton->setPopupMode( QToolButton::MenuButtonPopup );
384 QAction* previewAction = qobject_cast< QAction* >( action );
388 if ( !mFeatureList->setDisplayExpression( QString(
"COALESCE( \"%1\", '<NULL>' )" ).arg( previewAction->text() ) ) )
390 QMessageBox::warning(
this
391 ,
tr(
"Could not set preview column" )
392 ,
tr(
"Could not set column '%1' as preview column.\nParser error:\n%2" )
393 .arg( previewAction->text() )
394 .arg( mFeatureList->parserErrorString() )
399 mFeatureListPreviewButton->setDefaultAction( previewAction );
400 mFeatureListPreviewButton->setPopupMode( QToolButton::InstantPopup );
404 Q_ASSERT( previewAction );
428 QModelIndex sourceIndex =
mFilterModel->mapToSource( atIndex );
434 QAction *a = menu->addAction(
tr(
"Run layer action" ) );
435 a->setEnabled(
false );
445 menu->addAction( action.
name(), a, SLOT( execute() ) );
451 if ( registeredActions.size() > 0 )
454 menu->addSeparator();
456 QList<QgsMapLayerAction*>::iterator actionIt;
457 for ( actionIt = registeredActions.begin(); actionIt != registeredActions.end(); ++actionIt )
460 menu->addAction(( *actionIt )->text(), a, SLOT( execute() ) );
464 menu->addSeparator();
466 menu->addAction(
tr(
"Open form" ), a, SLOT( featureForm() ) );
510 for (
int idx = 0; idx < newFeat.
attributes().count(); ++idx )
512 if ( idx == attribute )
543 if ( fid == feat->
id() )
592 mTableView->setFeatureSelectionManager( featureSelectionManager );
605 mProgressDlg =
new QProgressDialog(
tr(
"Loading features..." ),
tr(
"Abort" ), 0, 0,
this );
612 mProgressDlg->setLabelText(
tr(
"%1 features loaded." ).arg( i ) );
614 QCoreApplication::processEvents();