33 #include <QMessageBox>
34 #include <QProgressDialog>
37 : QStackedWidget( parent )
43 , mFeatureSelectionManager( 0 )
65 connect( mTableView, SIGNAL( willShowContextMenu( QMenu*, QModelIndex ) ),
this, SLOT(
viewWillShowContextMenu( QMenu*, QModelIndex ) ) );
73 mAttributeEditorScrollArea->setLayout(
new QGridLayout() );
95 if ( displayExpression ==
"" )
100 displayExpression = QString(
"COALESCE(\"%1\", '<NULL>')" ).arg( defaultField );
105 if ( displayExpression ==
"" )
109 if ( pkAttrs.size() > 0 )
111 if ( pkAttrs.size() == 1 )
112 defaultField = pkAttrs.at( 0 );
115 QStringList pkFields;
117 Q_FOREACH(
int attr, pkAttrs )
119 pkFields.append(
"COALESCE(\"" + fields[attr].name() +
"\", '<NULL>')" );
122 displayExpression = pkFields.join(
"||', '||" );
124 else if ( fields.size() > 0 )
126 if ( fields.size() == 1 )
127 defaultField = fields.at( 0 ).name();
130 QStringList fieldNames;
133 fieldNames.append(
"COALESCE(\"" + field.
name() +
"\", '<NULL>')" );
136 displayExpression = fieldNames.join(
"||', '||" );
141 displayExpression =
"'[Please define preview text]'";
146 QList< QAction* > previewActions = mFeatureListPreviewButton->actions();
147 foreach ( QAction* a, previewActions )
149 if ( a != mActionExpressionPreview )
156 mFeatureListPreviewButton->addAction( mActionExpressionPreview );
157 mFeatureListPreviewButton->addAction( mActionPreviewColumnsMenu );
159 foreach (
const QgsField& field, fields )
164 QString text = field.
name();
167 QAction* previewAction =
new QAction( icon, text, mFeatureListPreviewButton );
172 if ( text == defaultField )
174 mFeatureListPreviewButton->setDefaultAction( previewAction );
180 if ( !mFeatureListPreviewButton->defaultAction() )
182 mFeatureList->setDisplayExpression( displayExpression );
183 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
187 mFeatureListPreviewButton->defaultAction()->trigger();
193 setCurrentIndex( view );
211 int cacheSize = qMax( 1, settings.value(
"/qgis/attributeTableRowCache",
"10000" ).toInt() );
213 mLayerCache->setCacheGeometry(
false );
216 connect( mLayerCache, SIGNAL(
progress(
int,
bool & ) ),
this, SLOT(
progress(
int,
bool & ) ) );
219 mLayerCache->setFullCache(
true );
261 mFeatureList->setCurrentFeatureEdited(
false );
262 mFeatureList->setEditSelection( fids );
274 dlg.setWindowTitle(
tr(
"Expression based preview" ) );
277 if ( dlg.exec() == QDialog::Accepted )
279 mFeatureList->setDisplayExpression( dlg.expressionText() );
280 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
281 mFeatureListPreviewButton->setPopupMode( QToolButton::MenuButtonPopup );
287 QAction* previewAction = qobject_cast< QAction* >( action );
291 if ( !mFeatureList->setDisplayExpression( QString(
"COALESCE( \"%1\", '<NULL>' )" ).arg( previewAction->text() ) ) )
293 QMessageBox::warning(
this
294 ,
tr(
"Could not set preview column" )
295 ,
tr(
"Could not set column '%1' as preview column.\nParser error:\n%2" )
296 .arg( previewAction->text() )
297 .arg( mFeatureList->parserErrorString() )
302 mFeatureListPreviewButton->setDefaultAction( previewAction );
303 mFeatureListPreviewButton->setPopupMode( QToolButton::InstantPopup );
307 Q_ASSERT( previewAction );
322 QModelIndex sourceIndex =
mFilterModel->mapToSource( atIndex );
328 QAction *a = menu->addAction(
tr(
"Run layer action" ) );
329 a->setEnabled(
false );
339 menu->addAction( action.
name(), a, SLOT( execute() ) );
345 if ( registeredActions.size() > 0 )
348 menu->addSeparator();
350 QList<QgsMapLayerAction*>::iterator actionIt;
351 for ( actionIt = registeredActions.begin(); actionIt != registeredActions.end(); ++actionIt )
354 menu->addAction(( *actionIt )->text(), a, SLOT( execute() ) );
358 menu->addSeparator();
360 menu->addAction(
tr(
"Open form" ), a, SLOT( featureForm() ) );
370 mFeatureList->setCurrentFeatureEdited(
true );
385 mTableView->setFeatureSelectionManager( featureSelectionManager );
398 mProgressDlg =
new QProgressDialog(
tr(
"Loading features..." ),
tr(
"Abort" ), 0, 0,
this );
405 mProgressDlg->setLabelText(
tr(
"%1 features loaded." ).arg( i ) );
407 QCoreApplication::processEvents();
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)
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)
virtual void finished()
Will be called, once all the features are loaded.
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)
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of rows.
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...
QgsAttributeForm * mAttributeForm
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.
QMenu * mPreviewColumnsMenu
const QString displayExpression()
Get the preview expression, used to create a human readable preview string.
static QIcon icon(QString icon)
void on_mFeatureList_aboutToChangeEditSelection(bool &ok)
QgsAttributeEditorContext mEditorContext
Map canvas is a class for displaying all GIS data types on a canvas.
QSignalMapper * mPreviewActionMapper
void setView(ViewMode view)
Change the current view mode.
void previewColumnChanged(QObject *previewAction)
Show a list of the features, where one can be chosen and the according attribute dialog will be prese...
void init(QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request=QgsFeatureRequest(), QgsAttributeEditorContext context=QgsAttributeEditorContext())
Has to be called to initialize the dual view.
void initLayerCache(QgsVectorLayer *layer)
QString name() const
The name of the action.
QgsMapLayerAction * mAction
QgsFeatureListModel * mFeatureListModel
void executeMapLayerAction(QgsMapLayerAction *action, const QModelIndex &idx) const
Execute a QgsMapLayerAction.
QgsIFeatureSelectionManager * mFeatureSelectionManager
QList< QgsMapLayerAction * > mapLayerActions(QgsMapLayer *layer)
Returns the map layer actions which can run on the specified layer.
void on_mFeatureList_currentEditSelectionChanged(const QgsFeature &feat)
Changes the currently visible feature within the attribute editor.
const QString editorWidgetV2(int fieldIdx) const
Get the id for the editor widget used to represent the field at the given index.
void viewWillShowContextMenu(QMenu *menu, QModelIndex atIndex)
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
const QString displayField() const
Returns the primary display field name used in the identify results dialog.
void filterChanged()
Is emitted, whenever the filter changes.
Encapsulate a field in an attribute table or data source.
void previewExpressionBuilder()
fast access to features using their ID
void executeAction(int action, const QModelIndex &idx) const
Execute an action.
void featureFormAttributeChanged()
Will be called whenever the currently shown feature form changes.
This class caches features of a given QgsVectorLayer.
QgsAttributeTableModel * masterModel() const
Returns the model which has the information about all features (not only filtered) ...
bool saveEditChanges()
saveEditChanges
void setRequest(const QgsFeatureRequest &request)
virtual void progress(int i, bool &cancel)
Will be called periodically, when loading layers from slow data providers.
void setSelectedOnTop(bool selectedOnTop)
Toggle the selectedOnTop flag.
QgsVectorLayerCache * mLayerCache
static QgsMapLayerActionRegistry * instance()
Returns the instance pointer, creating the object on the first call.
QgsAttributeTableFilterModel * mFilterModel
bool runable() const
Whether the action is runable on the current platform.
void initModels(QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request)
QgsFeatureId rowToId(int row) const
Maps row to feature id.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
QProgressDialog * mProgressDlg
virtual bool isEditable() const
Returns true if the provider is in editing mode.
QgsAttributeList pendingPkAttributesList()
returns list of attribute making up the primary key
Is an interface class to abstract feature selection handling.
QgsAttributeTableModel * mMasterModel
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.
void previewExpressionChanged(const QString expression)
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.