32 #include <QMessageBox>
33 #include <QProgressDialog>
40 , mFeatureListModel( 0 )
44 , mFeatureSelectionManager( 0 )
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 mAttributeEditorScrollArea->setLayout(
new QGridLayout() );
79 mAttributeEditorScrollArea->layout()->addWidget( mAttributeForm );
80 mAttributeEditorScrollArea->setWidget( mAttributeForm );
84 connect( mAttributeForm, SIGNAL( attributeChanged(
QString,
QVariant ) ),
this, SLOT( featureFormAttributeChanged() ) );
85 connect( mMasterModel, SIGNAL( modelChanged() ), mAttributeForm, SLOT( refreshFeature() ) );
87 if ( mFeatureListPreviewButton->defaultAction() )
88 mFeatureList->setDisplayExpression( mDisplayExpression );
109 if ( displayExpression ==
"" )
114 displayExpression =
QString(
"COALESCE(\"%1\", '<NULL>')" ).
arg( defaultField );
119 if ( displayExpression ==
"" )
123 if ( pkAttrs.
size() > 0 )
125 if ( pkAttrs.
size() == 1 )
126 defaultField = pkAttrs.
at( 0 );
131 Q_FOREACH (
int attr, pkAttrs )
133 pkFields.
append(
"COALESCE(\"" + fields[attr].
name() +
"\", '<NULL>')" );
136 displayExpression = pkFields.
join(
"||', '||" );
138 else if ( fields.
size() > 0 )
140 if ( fields.
size() == 1 )
141 defaultField = fields.
at( 0 ).name();
145 Q_FOREACH (
const QgsField& field, fields )
147 fieldNames.
append(
"COALESCE(\"" + field.
name() +
"\", '<NULL>')" );
150 displayExpression = fieldNames.
join(
"||', '||" );
155 displayExpression =
"'[Please define preview text]'";
159 mFeatureListPreviewButton->addAction( mActionExpressionPreview );
160 mFeatureListPreviewButton->addAction( mActionPreviewColumnsMenu );
162 Q_FOREACH (
const QgsField& field, fields )
165 if ( fieldIndex == -1 )
174 QAction* previewAction =
new QAction( icon, text, mFeatureListPreviewButton );
175 mPreviewActionMapper->
setMapping( previewAction, previewAction );
176 connect( previewAction, SIGNAL( triggered() ), mPreviewActionMapper, SLOT( map() ) );
177 mPreviewColumnsMenu->
addAction( previewAction );
179 if ( text == defaultField )
181 mFeatureListPreviewButton->setDefaultAction( previewAction );
187 if ( !mFeatureListPreviewButton->defaultAction() )
189 mFeatureList->setDisplayExpression( displayExpression );
190 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
191 mDisplayExpression = mFeatureList->displayExpression();
195 mFeatureListPreviewButton->defaultAction()->trigger();
215 void QgsDualView::initLayerCache(
QgsVectorLayer* layer,
bool cacheGeometry )
219 int cacheSize = settings.
value(
"/qgis/attributeTableRowCache",
"10000" ).
toInt();
224 connect( mLayerCache, SIGNAL( progress(
int,
bool & ) ),
this, SLOT( progress(
int,
bool & ) ) );
225 connect( mLayerCache, SIGNAL( finished() ),
this, SLOT( finished() ) );
233 delete mFeatureListModel;
241 connect( mMasterModel, SIGNAL( progress(
int,
bool & ) ),
this, SLOT( progress(
int,
bool & ) ) );
242 connect( mMasterModel, SIGNAL( finished() ),
this, SLOT( finished() ) );
244 connect( mConditionalFormatWidget, SIGNAL( rulesUpdated(
QString ) ), mMasterModel, SLOT( fieldConditionalStyleChanged(
QString ) ) );
255 void QgsDualView::on_mFeatureList_aboutToChangeEditSelection(
bool& ok )
261 void QgsDualView::on_mFeatureList_currentEditSelectionChanged(
const QgsFeature &feat )
276 mFeatureList->setCurrentFeatureEdited(
false );
277 mFeatureList->setEditSelection( fids );
282 return mAttributeForm->
save();
287 mConditionalFormatWidget->setVisible( !mConditionalFormatWidget->isVisible() );
288 mConditionalFormatWidget->viewRules();
291 void QgsDualView::previewExpressionBuilder()
301 dlg.setExpressionText( mFeatureList->displayExpression() );
303 if ( dlg.exec() == QDialog::Accepted )
305 mFeatureList->setDisplayExpression( dlg.expressionText() );
306 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
307 mFeatureListPreviewButton->setPopupMode( QToolButton::MenuButtonPopup );
310 mDisplayExpression = mFeatureList->displayExpression();
313 void QgsDualView::previewColumnChanged(
QObject* action )
319 if ( !mFeatureList->setDisplayExpression(
QString(
"COALESCE( \"%1\", '<NULL>' )" ).arg( previewAction->
text() ) ) )
322 tr(
"Could not set preview column" ),
323 tr(
"Could not set column '%1' as preview column.\nParser error:\n%2" )
324 .arg( previewAction->
text(), mFeatureList->parserErrorString() )
329 mFeatureListPreviewButton->setDefaultAction( previewAction );
330 mFeatureListPreviewButton->setPopupMode( QToolButton::InstantPopup );
334 mDisplayExpression = mFeatureList->displayExpression();
336 Q_ASSERT( previewAction );
349 void QgsDualView::viewWillShowContextMenu(
QMenu* menu,
const QModelIndex& atIndex )
374 if ( registeredActions.
size() > 0 )
380 for ( actionIt = registeredActions.
begin(); actionIt != registeredActions.
end(); ++actionIt )
383 menu->
addAction(( *actionIt )->text(), a, SLOT( execute() ) );
389 menu->
addAction(
tr(
"Open form" ), a, SLOT( featureForm() ) );
392 void QgsDualView::previewExpressionChanged(
const QString& expression )
397 void QgsDualView::featureFormAttributeChanged()
399 mFeatureList->setCurrentFeatureEdited(
true );
414 mTableView->setFeatureSelectionManager( featureSelectionManager );
417 if ( mFeatureSelectionManager && mFeatureSelectionManager->
parent() == this )
418 delete mFeatureSelectionManager;
420 mFeatureSelectionManager = featureSelectionManager;
423 void QgsDualView::progress(
int i,
bool& cancel )
427 mProgressDlg =
new QProgressDialog(
tr(
"Loading features..." ),
tr(
"Abort" ), 0, 0,
this );
430 mProgressDlg->
show();
434 mProgressDlg->
setLabelText(
tr(
"%1 features loaded." ).arg( i ) );
438 cancel = mProgressDlg && mProgressDlg->
wasCanceled();
441 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)
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...
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.
virtual void setFilteredFeatures(const QgsFeatureIds &ids)
Specify a list of features, which the filter will accept.
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)
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
Fast access to features using their ID.
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.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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.
void filterChanged()
Is emitted, whenever the filter changes.
Encapsulate a field in an attribute table or data source.
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)
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
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.
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.