30 #include <QProgressDialog>
31 #include <QMessageBox>
34 : QStackedWidget( parent )
35 , mAttributeDialog( NULL )
36 , mProgressDlg( NULL )
52 connect(
this, SIGNAL( currentChanged(
int ) ),
this, SLOT(
saveEditChanges() ) );
64 connect( mTableView, SIGNAL( willShowContextMenu( QMenu*, QModelIndex ) ),
this, SLOT(
viewWillShowContextMenu( QMenu*, QModelIndex ) ) );
90 if ( displayExpression ==
"" )
95 displayExpression = QString(
"COALESCE(\"%1\", '<NULL>')" ).arg( defaultField );
100 if ( displayExpression ==
"" )
104 if ( pkAttrs.size() > 0 )
106 if ( pkAttrs.size() == 1 )
107 defaultField = pkAttrs.at( 0 );
110 QStringList pkFields;
112 Q_FOREACH(
int attr, pkAttrs )
114 pkFields.append(
"COALESCE(\"" + fields[attr].name() +
"\", '<NULL>')" );
117 displayExpression = pkFields.join(
"||', '||" );
119 else if ( fields.size() > 0 )
121 if ( fields.size() == 1 )
122 defaultField = fields.at( 0 ).name();
125 QStringList fieldNames;
128 fieldNames.append(
"COALESCE(\"" + field.
name() +
"\", '<NULL>')" );
131 displayExpression = fieldNames.join(
"||', '||" );
136 displayExpression =
"'[Please define preview text]'";
141 QList< QAction* > previewActions = mFeatureListPreviewButton->actions();
142 foreach ( QAction* a, previewActions )
144 if ( a != mActionExpressionPreview )
151 mFeatureListPreviewButton->addAction( mActionExpressionPreview );
152 mFeatureListPreviewButton->addAction( mActionPreviewColumnsMenu );
154 foreach (
const QgsField field, fields )
159 QString text = field.
name();
162 QAction* previewAction =
new QAction( icon, text, mFeatureListPreviewButton );
167 if ( text == defaultField )
169 mFeatureListPreviewButton->setDefaultAction( previewAction );
175 if ( !mFeatureListPreviewButton->defaultAction() )
177 mFeatureList->setDisplayExpression( displayExpression );
178 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
182 mFeatureListPreviewButton->defaultAction()->trigger();
200 setCurrentIndex( view );
217 int cacheSize = qMax( 1, settings.value(
"/qgis/attributeTableRowCache",
"10000" ).toInt() );
219 mLayerCache->setCacheGeometry(
false );
222 connect( mLayerCache, SIGNAL(
progress(
int,
bool & ) ),
this, SLOT(
progress(
int,
bool & ) ) );
225 mLayerCache->setFullCache(
true );
228 connect( layer, SIGNAL( editingStarted() ),
this, SLOT(
editingToggled() ) );
229 connect( layer, SIGNAL( beforeCommitChanges() ),
this, SLOT(
editingToggled() ) );
230 connect( layer, SIGNAL( editingStopped() ),
this, SLOT(
editingToggled() ) );
275 mFeatureList->setEditSelection( fids );
295 if ( src.count() != dst.count() )
303 for (
int i = 0; i < dst.count(); ++i )
305 if ( dst[i] != src[i] )
320 dlg.setWindowTitle(
tr(
"Expression based preview" ) );
323 if ( dlg.exec() == QDialog::Accepted )
325 mFeatureList->setDisplayExpression( dlg.expressionText() );
326 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
327 mFeatureListPreviewButton->setPopupMode( QToolButton::MenuButtonPopup );
333 QAction* previewAction = qobject_cast< QAction* >( action );
337 if ( !mFeatureList->setDisplayExpression( QString(
"COALESCE( \"%1\", '<NULL>' )" ).arg( previewAction->text() ) ) )
339 QMessageBox::warning(
this
340 ,
tr(
"Could not set preview column" )
341 ,
tr(
"Could not set column '%1' as preview column.\nParser error:\n%2" )
342 .arg( previewAction->text() )
343 .arg( mFeatureList->parserErrorString() )
348 mFeatureListPreviewButton->setDefaultAction( previewAction );
349 mFeatureListPreviewButton->setPopupMode( QToolButton::InstantPopup );
353 Q_ASSERT( previewAction );
377 QModelIndex sourceIndex =
mFilterModel->mapToSource( atIndex );
382 QAction *a = menu->addAction(
tr(
"Run action" ) );
383 a->setEnabled(
false );
393 menu->addAction( action.
name(), a, SLOT( execute() ) );
398 menu->addAction(
tr(
"Open form" ), a, SLOT( featureForm() ) );
442 for (
int idx = 0; idx < newFeat.
attributes().count(); ++idx )
444 if ( idx == attribute )
475 if ( fid == feat->
id() )
521 mProgressDlg =
new QProgressDialog(
tr(
"Loading features..." ),
tr(
"Abort" ), 0, 0,
this );
528 mProgressDlg->setLabelText(
tr(
"%1 features loaded." ).arg( i ) );
530 QCoreApplication::processEvents();