32 #include <QMessageBox> 33 #include <QProgressDialog> 38 , mMasterModel( nullptr )
39 , mFilterModel( nullptr )
40 , mFeatureListModel( nullptr )
41 , mAttributeForm( nullptr )
42 , mLayerCache( nullptr )
43 , mProgressDlg( nullptr )
44 , mFeatureSelectionManager( nullptr )
48 mConditionalFormatWidget->hide();
52 mPreviewColumnsMenu =
new QMenu(
this );
53 mActionPreviewColumnsMenu->setMenu( mPreviewColumnsMenu );
59 connect( mActionExpressionPreview, SIGNAL( triggered() ), SLOT( previewExpressionBuilder() ) );
60 connect( mPreviewActionMapper, SIGNAL( mapped(
QObject* ) ), SLOT( previewColumnChanged(
QObject* ) ) );
66 mEditorContext = context;
71 initModels( mapCanvas, request );
73 mConditionalFormatWidget->setLayer( layer );
75 mTableView->setModel( mFilterModel );
76 mFeatureList->setModel( mFeatureListModel );
78 if ( !mAttributeEditorScrollArea->layout() )
79 mAttributeEditorScrollArea->setLayout(
new QGridLayout() );
80 mAttributeEditorScrollArea->layout()->addWidget( mAttributeForm );
81 mAttributeEditorScrollArea->setWidget( mAttributeForm );
85 connect( mAttributeForm, SIGNAL( attributeChanged(
QString,
QVariant ) ),
this, SLOT( featureFormAttributeChanged() ) );
86 connect( mMasterModel, SIGNAL( modelChanged() ), mAttributeForm, SLOT( refreshFeature() ) );
88 if ( mFeatureListPreviewButton->defaultAction() )
89 mFeatureList->setDisplayExpression( mDisplayExpression );
110 if ( displayExpression ==
"" )
115 displayExpression =
QString(
"COALESCE(\"%1\", '<NULL>')" ).
arg( defaultField );
120 if ( displayExpression ==
"" )
126 if ( pkAttrs.
size() == 1 )
127 defaultField = pkAttrs.
at( 0 );
132 Q_FOREACH (
int attr, pkAttrs )
134 pkFields.
append(
"COALESCE(\"" + fields[attr].
name() +
"\", '<NULL>')" );
137 displayExpression = pkFields.
join(
"||', '||" );
141 if ( fields.
size() == 1 )
142 defaultField = fields.
at( 0 ).name();
146 Q_FOREACH (
const QgsField& field, fields )
148 fieldNames.
append(
"COALESCE(\"" + field.
name() +
"\", '<NULL>')" );
151 displayExpression = fieldNames.
join(
"||', '||" );
156 displayExpression =
"'[Please define preview text]'";
160 mFeatureListPreviewButton->addAction( mActionExpressionPreview );
161 mFeatureListPreviewButton->addAction( mActionPreviewColumnsMenu );
163 Q_FOREACH (
const QgsField& field, fields )
166 if ( fieldIndex == -1 )
175 QAction* previewAction =
new QAction( icon, text, mFeatureListPreviewButton );
176 mPreviewActionMapper->
setMapping( previewAction, previewAction );
177 connect( previewAction, SIGNAL( triggered() ), mPreviewActionMapper, SLOT( map() ) );
178 mPreviewColumnsMenu->
addAction( previewAction );
180 if ( text == defaultField )
182 mFeatureListPreviewButton->setDefaultAction( previewAction );
188 if ( !mFeatureListPreviewButton->defaultAction() )
190 mFeatureList->setDisplayExpression( displayExpression );
191 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
192 mDisplayExpression = mFeatureList->displayExpression();
196 mFeatureListPreviewButton->defaultAction()->trigger();
216 void QgsDualView::initLayerCache(
QgsVectorLayer* layer,
bool cacheGeometry )
220 int cacheSize = settings.
value(
"/qgis/attributeTableRowCache",
"10000" ).
toInt();
225 connect( mLayerCache, SIGNAL( progress(
int,
bool & ) ),
this, SLOT( progress(
int,
bool & ) ) );
226 connect( mLayerCache, SIGNAL( finished() ),
this, SLOT( finished() ) );
234 delete mFeatureListModel;
242 connect( mMasterModel, SIGNAL( progress(
int,
bool & ) ),
this, SLOT( progress(
int,
bool & ) ) );
243 connect( mMasterModel, SIGNAL( finished() ),
this, SLOT( finished() ) );
245 connect( mConditionalFormatWidget, SIGNAL( rulesUpdated(
QString ) ), mMasterModel, SLOT( fieldConditionalStyleChanged(
QString ) ) );
256 void QgsDualView::on_mFeatureList_aboutToChangeEditSelection(
bool& ok )
262 void QgsDualView::on_mFeatureList_currentEditSelectionChanged(
const QgsFeature &feat )
277 mFeatureList->setCurrentFeatureEdited(
false );
278 mFeatureList->setEditSelection( fids );
283 return mAttributeForm->
save();
288 mConditionalFormatWidget->setVisible( !mConditionalFormatWidget->isVisible() );
289 mConditionalFormatWidget->viewRules();
292 void QgsDualView::previewExpressionBuilder()
302 dlg.setExpressionText( mFeatureList->displayExpression() );
304 if ( dlg.exec() == QDialog::Accepted )
306 mFeatureList->setDisplayExpression( dlg.expressionText() );
307 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
308 mFeatureListPreviewButton->setPopupMode( QToolButton::MenuButtonPopup );
311 mDisplayExpression = mFeatureList->displayExpression();
314 void QgsDualView::previewColumnChanged(
QObject* action )
320 if ( !mFeatureList->setDisplayExpression(
QString(
"COALESCE( \"%1\", '<NULL>' )" ).arg( previewAction->
text() ) ) )
323 tr(
"Could not set preview column" ),
324 tr(
"Could not set column '%1' as preview column.\nParser error:\n%2" )
325 .arg( previewAction->
text(), mFeatureList->parserErrorString() )
330 mFeatureListPreviewButton->setDefaultAction( previewAction );
331 mFeatureListPreviewButton->setPopupMode( QToolButton::InstantPopup );
335 mDisplayExpression = mFeatureList->displayExpression();
337 Q_ASSERT( previewAction );
350 void QgsDualView::viewWillShowContextMenu(
QMenu* menu,
const QModelIndex& atIndex )
361 menu->
addAction(
tr(
"Zoom to feature" ),
this, SLOT( zoomToCurrentFeature() ) );
387 if ( !registeredActions.
isEmpty() )
393 for ( actionIt = registeredActions.
begin(); actionIt != registeredActions.
end(); ++actionIt )
396 menu->
addAction(( *actionIt )->text(), a, SLOT( execute() ) );
402 menu->
addAction(
tr(
"Open form" ), a, SLOT( featureForm() ) );
405 void QgsDualView::zoomToCurrentFeature()
422 void QgsDualView::previewExpressionChanged(
const QString& expression )
427 void QgsDualView::featureFormAttributeChanged()
429 mFeatureList->setCurrentFeatureEdited(
true );
444 mTableView->setFeatureSelectionManager( featureSelectionManager );
445 mFeatureList->setFeatureSelectionManager( featureSelectionManager );
447 if ( mFeatureSelectionManager && mFeatureSelectionManager->
parent() == this )
448 delete mFeatureSelectionManager;
450 mFeatureSelectionManager = featureSelectionManager;
453 void QgsDualView::progress(
int i,
bool& cancel )
457 mProgressDlg =
new QProgressDialog(
tr(
"Loading features..." ),
tr(
"Abort" ), 0, 0,
this );
460 mProgressDlg->
show();
464 mProgressDlg->
setLabelText(
tr(
"%1 features loaded." ).arg( i ) );
468 cancel = mProgressDlg && mProgressDlg->
wasCanceled();
471 void QgsDualView::finished()
474 mProgressDlg =
nullptr;
483 mDualView->masterModel()->executeAction( mAction, mFieldIdx );
489 editedIds << mDualView->masterModel()->rowToId( mFieldIdx.row() );
490 mDualView->setCurrentEditSelection( editedIds );
500 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.
QgsFeatureId rowToId(const QModelIndex &row)
Returns the feature id for a given model index.
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...
QgsMapCanvas * mapCanvas() const
Returns the map canvas.
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)
void openConditionalStyles()
const QgsRectangle & filterRect() const
Get the rectangle from which features will be taken.
QSet< QgsFeatureId > QgsFeatureIds
QgsFields fields() const
Returns the list of fields of this layer.
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
bool isNull() const
test if the rectangle is null (all coordinates zero or after call to setMinimal()).
QList< QgsMapLayerAction * > mapLayerActions(QgsMapLayer *layer, const QgsMapLayerAction::Targets &targets=QgsMapLayerAction::AllActions)
Returns the map layer actions which can run on the specified layer.
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...
void setDisplayExpression(const QString &displayExpression)
Set the preview expression, used to create a human readable preview string.
QString join(const QString &separator) const
const_iterator insert(const T &value)
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.
QgsEditFormConfig * editFormConfig() const
Get the configuration of the form used to represent this vector layer.
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.
virtual void setFilteredFeatures(const QgsFeatureIds &ids)
Specify a list of features, which the filter will accept.
QgsDualView(QWidget *parent=nullptr)
Constructor.
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
QgsVectorLayer * layer() const
Returns the layer this filter acts on.
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)
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
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.
QString name() const
Gets the name of the field.
Utility class that encapsulates an action based on vector attributes.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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.
QgsFeatureIds filteredFeatures()
const QString displayField() const
Returns the primary display field name used in the identify results dialog.
void filterChanged()
Is emitted, whenever the filter changes.
QGis::GeometryType geometryType() const
Returns point, line or polygon.
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()
QgsAttributeList pkAttributeList() const
Returns list of attributes making up the primary key.
void setSelectedOnTop(bool selectedOnTop)
Toggle the selectedOnTop flag.
QVariant value(const QString &key, const QVariant &defaultValue) const
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const
void zoomToFeatureIds(QgsVectorLayer *layer, const QgsFeatureIds &ids)
Set canvas extent to the bounding box of a set of features.
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.
void displayExpressionChanged(const QString &expression)
Is emitted, whenever the display expression is successfully changed.
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)
static QgsExpressionContextScope * projectScope()
Creates a new scope which contains variables and functions relating to the current QGIS project...
QgsVectorDataProvider * dataProvider()
Returns the data provider.
void setFilteredFeatures(const QgsFeatureIds &filteredFeatures)
Set a list of currently visible features.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
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
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.