32 #include <QMessageBox>
33 #include <QProgressDialog>
40 , mFeatureListModel( 0 )
44 , mFeatureSelectionManager( 0 )
50 mPreviewColumnsMenu =
new QMenu(
this );
51 mActionPreviewColumnsMenu->setMenu( mPreviewColumnsMenu );
57 connect( mActionExpressionPreview, SIGNAL( triggered() ), SLOT( previewExpressionBuilder() ) );
58 connect( mPreviewActionMapper, SIGNAL( mapped(
QObject* ) ), SLOT( previewColumnChanged(
QObject* ) ) );
64 mEditorContext = context;
69 initModels( mapCanvas, request );
71 mTableView->setModel( mFilterModel );
72 mFeatureList->setModel( mFeatureListModel );
74 mAttributeEditorScrollArea->setLayout(
new QGridLayout() );
75 mAttributeEditorScrollArea->layout()->addWidget( mAttributeForm );
76 mAttributeEditorScrollArea->setWidget( mAttributeForm );
80 connect( mAttributeForm, SIGNAL( attributeChanged(
QString,
QVariant ) ),
this, SLOT( featureFormAttributeChanged() ) );
81 connect( mMasterModel, SIGNAL( modelChanged() ), mAttributeForm, SLOT( refreshFeature() ) );
83 if ( mFeatureListPreviewButton->defaultAction() )
84 mFeatureList->setDisplayExpression( mDisplayExpression );
102 if ( displayExpression ==
"" )
107 displayExpression =
QString(
"COALESCE(\"%1\", '<NULL>')" ).
arg( defaultField );
112 if ( displayExpression ==
"" )
116 if ( pkAttrs.
size() > 0 )
118 if ( pkAttrs.
size() == 1 )
119 defaultField = pkAttrs.
at( 0 );
124 Q_FOREACH (
int attr, pkAttrs )
126 pkFields.
append(
"COALESCE(\"" + fields[attr].
name() +
"\", '<NULL>')" );
129 displayExpression = pkFields.
join(
"||', '||" );
131 else if ( fields.
size() > 0 )
133 if ( fields.
size() == 1 )
134 defaultField = fields.
at( 0 ).name();
140 fieldNames.
append(
"COALESCE(\"" + field.
name() +
"\", '<NULL>')" );
143 displayExpression = fieldNames.
join(
"||', '||" );
148 displayExpression =
"'[Please define preview text]'";
152 mFeatureListPreviewButton->addAction( mActionExpressionPreview );
153 mFeatureListPreviewButton->addAction( mActionPreviewColumnsMenu );
155 Q_FOREACH (
const QgsField& field, fields )
158 if ( fieldIndex == -1 )
167 QAction* previewAction =
new QAction( icon, text, mFeatureListPreviewButton );
168 mPreviewActionMapper->
setMapping( previewAction, previewAction );
169 connect( previewAction, SIGNAL( triggered() ), mPreviewActionMapper, SLOT( map() ) );
170 mPreviewColumnsMenu->
addAction( previewAction );
172 if ( text == defaultField )
174 mFeatureListPreviewButton->setDefaultAction( previewAction );
180 if ( !mFeatureListPreviewButton->defaultAction() )
182 mFeatureList->setDisplayExpression( displayExpression );
183 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
184 mDisplayExpression = mFeatureList->displayExpression();
188 mFeatureListPreviewButton->defaultAction()->trigger();
208 void QgsDualView::initLayerCache(
QgsVectorLayer* layer,
bool cacheGeometry )
212 int cacheSize = settings.
value(
"/qgis/attributeTableRowCache",
"10000" ).
toInt();
217 connect( mLayerCache, SIGNAL( progress(
int,
bool & ) ),
this, SLOT( progress(
int,
bool & ) ) );
218 connect( mLayerCache, SIGNAL( finished() ),
this, SLOT( finished() ) );
226 delete mFeatureListModel;
234 connect( mMasterModel, SIGNAL( progress(
int,
bool & ) ),
this, SLOT( progress(
int,
bool & ) ) );
235 connect( mMasterModel, SIGNAL( finished() ),
this, SLOT( finished() ) );
246 void QgsDualView::on_mFeatureList_aboutToChangeEditSelection(
bool& ok )
252 void QgsDualView::on_mFeatureList_currentEditSelectionChanged(
const QgsFeature &feat )
267 mFeatureList->setCurrentFeatureEdited(
false );
268 mFeatureList->setEditSelection( fids );
273 return mAttributeForm->
save();
276 void QgsDualView::previewExpressionBuilder()
281 dlg.setExpressionText( mFeatureList->displayExpression() );
283 if ( dlg.exec() == QDialog::Accepted )
285 mFeatureList->setDisplayExpression( dlg.expressionText() );
286 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
287 mFeatureListPreviewButton->setPopupMode( QToolButton::MenuButtonPopup );
290 mDisplayExpression = mFeatureList->displayExpression();
293 void QgsDualView::previewColumnChanged(
QObject* action )
299 if ( !mFeatureList->setDisplayExpression(
QString(
"COALESCE( \"%1\", '<NULL>' )" ).arg( previewAction->
text() ) ) )
302 tr(
"Could not set preview column" ),
303 tr(
"Could not set column '%1' as preview column.\nParser error:\n%2" )
304 .arg( previewAction->
text() )
305 .arg( mFeatureList->parserErrorString() )
310 mFeatureListPreviewButton->setDefaultAction( previewAction );
311 mFeatureListPreviewButton->setPopupMode( QToolButton::InstantPopup );
315 mDisplayExpression = mFeatureList->displayExpression();
317 Q_ASSERT( previewAction );
330 void QgsDualView::viewWillShowContextMenu(
QMenu* menu,
QModelIndex atIndex )
355 if ( registeredActions.
size() > 0 )
361 for ( actionIt = registeredActions.
begin(); actionIt != registeredActions.
end(); ++actionIt )
364 menu->
addAction(( *actionIt )->text(), a, SLOT( execute() ) );
370 menu->
addAction(
tr(
"Open form" ), a, SLOT( featureForm() ) );
373 void QgsDualView::previewExpressionChanged(
const QString expression )
378 void QgsDualView::featureFormAttributeChanged()
380 mFeatureList->setCurrentFeatureEdited(
true );
395 mTableView->setFeatureSelectionManager( featureSelectionManager );
398 if ( mFeatureSelectionManager && mFeatureSelectionManager->
parent() == this )
399 delete mFeatureSelectionManager;
401 mFeatureSelectionManager = featureSelectionManager;
404 void QgsDualView::progress(
int i,
bool& cancel )
408 mProgressDlg =
new QProgressDialog(
tr(
"Loading features..." ),
tr(
"Abort" ), 0, 0,
this );
411 mProgressDlg->
show();
415 mProgressDlg->
setLabelText(
tr(
"%1 features loaded." ).arg( i ) );
419 cancel = mProgressDlg && mProgressDlg->
wasCanceled();
422 void QgsDualView::finished()
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 using this model as source for any oth...
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.
void setLabelText(const QString &text)
ViewMode
The view modes, in which this widget can present information.
const T & at(int i) const
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.
QString join(const QString &separator) const
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.
QString tr(const char *sourceText, const char *disambiguation, int n)
Map canvas is a class for displaying all GIS data types on a canvas.
virtual int rowCount(const QModelIndex &parent) const
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
const char * name() const
void setValue(int progress)
void setMapping(QObject *sender, int id)
QString name() const
The name of the action.
void processEvents(QFlags< QEventLoop::ProcessEventsFlag > flags)
void append(const T &value)
QList< QgsMapLayerAction * > mapLayerActions(QgsMapLayer *layer, QgsMapLayerAction::Targets targets=QgsMapLayerAction::AllActions)
Returns the map layer actions which can run on the specified layer.
void executeMapLayerAction(QgsMapLayerAction *action, const QModelIndex &idx) const
Execute a QgsMapLayerAction.
int toInt(bool *ok) const
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)...
void init(QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request=QgsFeatureRequest(), const QgsAttributeEditorContext &context=QgsAttributeEditorContext())
Has to be called to initialize the dual view.
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
void executeAction(int action, const QModelIndex &idx) const
Execute an action.
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)
void setSelectedOnTop(bool selectedOnTop)
Toggle the selectedOnTop flag.
QVariant value(const QString &key, const QVariant &defaultValue) const
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const
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.
StandardButton warning(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
QgsFeatureId rowToId(int row) const
Maps row to feature id.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
QgsVectorDataProvider * dataProvider()
Returns the data provider.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
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.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
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.