33 #include <QMessageBox> 34 #include <QProgressDialog> 37 : QStackedWidget( parent )
41 , mFeatureListModel( 0 )
45 , mFeatureSelectionManager( 0 )
49 mPreviewActionMapper =
new QSignalMapper(
this );
51 mPreviewColumnsMenu =
new QMenu(
this );
52 mActionPreviewColumnsMenu->setMenu( mPreviewColumnsMenu );
58 connect( mActionExpressionPreview, SIGNAL( triggered() ), SLOT( previewExpressionBuilder() ) );
59 connect( mPreviewActionMapper, SIGNAL( mapped( QObject* ) ), SLOT( previewColumnChanged( QObject* ) ) );
60 connect( mFeatureList, SIGNAL(
displayExpressionChanged( QString ) ),
this, SLOT( previewExpressionChanged( QString ) ) );
65 mEditorContext = context;
67 connect( mTableView, SIGNAL( willShowContextMenu( QMenu*, QModelIndex ) ),
this, SLOT( viewWillShowContextMenu( QMenu*, QModelIndex ) ) );
70 initModels( mapCanvas, request );
72 mTableView->setModel( mFilterModel );
73 mFeatureList->setModel( mFeatureListModel );
75 mAttributeEditorScrollArea->setLayout(
new QGridLayout() );
76 mAttributeEditorScrollArea->layout()->addWidget( mAttributeForm );
77 mAttributeEditorScrollArea->setWidget( mAttributeForm );
81 connect( mAttributeForm, SIGNAL( attributeChanged( QString, QVariant ) ),
this, SLOT( featureFormAttributeChanged() ) );
82 connect( mMasterModel, SIGNAL( modelChanged() ), mAttributeForm, SLOT( refreshFeature() ) );
84 if ( mFeatureListPreviewButton->defaultAction() )
85 mFeatureList->setDisplayExpression( mDisplayExpression );
103 if ( displayExpression ==
"" )
108 displayExpression = QString(
"COALESCE(\"%1\", '<NULL>')" ).arg( defaultField );
113 if ( displayExpression ==
"" )
117 if ( pkAttrs.size() > 0 )
119 if ( pkAttrs.size() == 1 )
120 defaultField = pkAttrs.at( 0 );
123 QStringList pkFields;
125 Q_FOREACH (
int attr, pkAttrs )
127 pkFields.append(
"COALESCE(\"" + fields[attr].name() +
"\", '<NULL>')" );
130 displayExpression = pkFields.join(
"||', '||" );
132 else if ( fields.size() > 0 )
134 if ( fields.size() == 1 )
135 defaultField = fields.at( 0 ).name();
138 QStringList fieldNames;
141 fieldNames.append(
"COALESCE(\"" + field.
name() +
"\", '<NULL>')" );
144 displayExpression = fieldNames.join(
"||', '||" );
149 displayExpression =
"'[Please define preview text]'";
153 mFeatureListPreviewButton->addAction( mActionExpressionPreview );
154 mFeatureListPreviewButton->addAction( mActionPreviewColumnsMenu );
156 Q_FOREACH (
const QgsField& field, fields )
159 if ( fieldIndex == -1 )
165 QString text = field.
name();
168 QAction* previewAction =
new QAction( icon, text, mFeatureListPreviewButton );
169 mPreviewActionMapper->setMapping( previewAction, previewAction );
170 connect( previewAction, SIGNAL( triggered() ), mPreviewActionMapper, SLOT( map() ) );
171 mPreviewColumnsMenu->addAction( previewAction );
173 if ( text == defaultField )
175 mFeatureListPreviewButton->setDefaultAction( previewAction );
181 if ( !mFeatureListPreviewButton->defaultAction() )
183 mFeatureList->setDisplayExpression( displayExpression );
184 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
185 mDisplayExpression = mFeatureList->displayExpression();
189 mFeatureListPreviewButton->defaultAction()->trigger();
195 setCurrentIndex( view );
209 void QgsDualView::initLayerCache(
QgsVectorLayer* layer,
bool cacheGeometry )
213 int cacheSize = settings.value(
"/qgis/attributeTableRowCache",
"10000" ).toInt();
218 connect( mLayerCache, SIGNAL( progress(
int,
bool & ) ),
this, SLOT( progress(
int,
bool & ) ) );
219 connect( mLayerCache, SIGNAL( finished() ),
this, SLOT( finished() ) );
227 delete mFeatureListModel;
235 connect( mMasterModel, SIGNAL( progress(
int,
bool & ) ),
this, SLOT( progress(
int,
bool & ) ) );
236 connect( mMasterModel, SIGNAL( finished() ),
this, SLOT( finished() ) );
247 void QgsDualView::on_mFeatureList_aboutToChangeEditSelection(
bool& ok )
253 void QgsDualView::on_mFeatureList_currentEditSelectionChanged(
const QgsFeature &feat )
268 mFeatureList->setCurrentFeatureEdited(
false );
269 mFeatureList->setEditSelection( fids );
274 return mAttributeForm->
save();
277 void QgsDualView::previewExpressionBuilder()
281 dlg.setWindowTitle(
tr(
"Expression based preview" ) );
284 if ( dlg.exec() == QDialog::Accepted )
286 mFeatureList->setDisplayExpression( dlg.expressionText() );
287 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
288 mFeatureListPreviewButton->setPopupMode( QToolButton::MenuButtonPopup );
291 mDisplayExpression = mFeatureList->displayExpression();
294 void QgsDualView::previewColumnChanged( QObject* action )
296 QAction* previewAction = qobject_cast< QAction* >( action );
300 if ( !mFeatureList->setDisplayExpression( QString(
"COALESCE( \"%1\", '<NULL>' )" ).arg( previewAction->text() ) ) )
302 QMessageBox::warning(
this,
303 tr(
"Could not set preview column" ),
304 tr(
"Could not set column '%1' as preview column.\nParser error:\n%2" )
305 .arg( previewAction->text() )
306 .arg( mFeatureList->parserErrorString() )
311 mFeatureListPreviewButton->setDefaultAction( previewAction );
312 mFeatureListPreviewButton->setPopupMode( QToolButton::InstantPopup );
316 mDisplayExpression = mFeatureList->displayExpression();
318 Q_ASSERT( previewAction );
328 return mFilterModel->rowCount();
331 void QgsDualView::viewWillShowContextMenu( QMenu* menu, QModelIndex atIndex )
333 QModelIndex sourceIndex = mFilterModel->mapToSource( atIndex );
339 QAction *a = menu->addAction(
tr(
"Run layer action" ) );
340 a->setEnabled(
false );
350 menu->addAction( action.
name(), a, SLOT( execute() ) );
356 if ( registeredActions.size() > 0 )
359 menu->addSeparator();
361 QList<QgsMapLayerAction*>::iterator actionIt;
362 for ( actionIt = registeredActions.begin(); actionIt != registeredActions.end(); ++actionIt )
365 menu->addAction(( *actionIt )->text(), a, SLOT( execute() ) );
369 menu->addSeparator();
371 menu->addAction(
tr(
"Open form" ), a, SLOT( featureForm() ) );
374 void QgsDualView::previewExpressionChanged(
const QString expression )
379 void QgsDualView::featureFormAttributeChanged()
381 mFeatureList->setCurrentFeatureEdited(
true );
396 mTableView->setFeatureSelectionManager( featureSelectionManager );
399 if ( mFeatureSelectionManager && mFeatureSelectionManager->parent() == this )
400 delete mFeatureSelectionManager;
402 mFeatureSelectionManager = featureSelectionManager;
405 void QgsDualView::progress(
int i,
bool& cancel )
409 mProgressDlg =
new QProgressDialog(
tr(
"Loading features..." ),
tr(
"Abort" ), 0, 0,
this );
410 mProgressDlg->setWindowTitle(
tr(
"Attribute table" ) );
411 mProgressDlg->setWindowModality( Qt::WindowModal );
412 mProgressDlg->show();
415 mProgressDlg->setValue( i );
416 mProgressDlg->setLabelText(
tr(
"%1 features loaded." ).arg( i ) );
418 QCoreApplication::processEvents();
420 cancel = mProgressDlg->wasCanceled();
423 void QgsDualView::finished()
435 mDualView->masterModel()->executeAction( mAction, mFieldIdx );
441 editedIds << mDualView->masterModel()->rowToId( mFieldIdx.row() );
442 mDualView->setCurrentEditSelection( editedIds );
452 mDualView->masterModel()->executeMapLayerAction( mAction, mFieldIdx );
QList< QgsField > toList() const
Utility function to return a list of QgsField instances.
QgsFeatureId id() const
Get the feature id for this feature.
void setRequest(const QgsFeatureRequest &request)
Set a request that will be used to fill this attribute table model.
const QString & name() const
Gets the name of the field.
void setFilterMode(QgsAttributeTableFilterModel::FilterMode filterMode)
Set the filter mode.
virtual void loadLayer()
Loads the layer into the model Preferably to be called, before basing any other models on this model...
void setExpressionText(const QString &text)
void setSelectedOnTop(bool selectedOnTop)
Changes the sort order of the features.
void setFilterMode(FilterMode filterMode)
Set the filter mode the filter will use.
QgsAttributeAction * actions()
void setFeatureSelectionManager(QgsIFeatureSelectionManager *featureSelectionManager)
QSet< QgsFeatureId > QgsFeatureIds
This class contains context information for attribute editor widgets.
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
ViewMode
The view modes, in which this widget can present information.
QgsVectorLayer * layer()
Returns the layer to which this cache belongs.
int filteredFeatureCount()
Returns the number of features which are currently visible, according to the filter restrictions...
QgsDualView(QWidget *parent=0)
Constructor.
void setDisplayExpression(const QString &displayExpression)
Set the preview expression, used to create a human readable preview string.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
void setCurrentEditSelection(const QgsFeatureIds &fids)
Set the current edit selection in the AttributeEditor mode.
const QString displayExpression()
Get the preview expression, used to create a human readable preview string.
virtual bool isEditable() const override
Returns true if the provider is in editing mode.
Map canvas is a class for displaying all GIS data types on a canvas.
void setView(ViewMode view)
Change the current view mode.
Show a list of the features, where one can be chosen and the according attribute dialog will be prese...
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
QString name() const
The name of the action.
QList< QgsMapLayerAction * > mapLayerActions(QgsMapLayer *layer, QgsMapLayerAction::Targets targets=QgsMapLayerAction::AllActions)
Returns the map layer actions which can run on the specified layer.
virtual int capabilities() const
Returns a bitmask containing the supported capabilities Note, some capabilities may change depending ...
void setEditorContext(const QgsAttributeEditorContext &context)
Sets the context in which this table is shown.
const QString editorWidgetV2(int fieldIdx) const
Get the id for the editor widget used to represent the field at the given index.
Utility class that encapsulates an action based on vector attributes.
void setFilteredFeatures(QgsFeatureIds filteredFeatures)
Set a list of currently visible features.
void displayExpressionChanged(const QString expression)
Is emitted, whenever the display expression is successfully changed.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< int > QgsAttributeList
void init(QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request=QgsFeatureRequest(), const QgsAttributeEditorContext &context=QgsAttributeEditorContext())
Has to be called to initialize the dual view.
QgsFeatureIds filteredFeatures()
const QString displayField() const
Returns the primary display field name used in the identify results dialog.
Filter using a rectangle, no need to set NoGeometry.
void filterChanged()
Is emitted, whenever the filter changes.
FilterType filterType() const
Encapsulate a field in an attribute table or data source.
fast access to features using their ID
This class caches features of a given QgsVectorLayer.
bool saveEditChanges()
saveEditChanges
void setRequest(const QgsFeatureRequest &request)
QgsAttributeTableFilterModel::FilterMode filterMode()
void setSelectedOnTop(bool selectedOnTop)
Toggle the selectedOnTop flag.
static QgsMapLayerActionRegistry * instance()
Returns the instance pointer, creating the object on the first call.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows.
void setCacheGeometry(bool cacheGeometry)
Enable or disable the caching of geometries.
void setFullCache(bool fullCache)
This enables or disables full caching.
QgsFeatureId idxToFid(const QModelIndex &index) const
bool runable() const
Whether the action is runable on the current platform.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
QgsVectorDataProvider * dataProvider()
Returns the data provider.
QgsAttributeList pendingPkAttributesList()
returns list of attribute making up the primary key
Is an interface class to abstract feature selection handling.
Represents a vector layer which manages a vector based data sets.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
virtual void setFilteredFeatures(QgsFeatureIds ids)
Specify a list of features, which the filter will accept.
A generic dialog for building expression strings.
void columnBoxInit()
Initializes widgets which depend on the attributes of this layer.
int featureCount()
Returns the number of features on the layer.