33 #include <QProgressDialog>
34 #include <QMessageBox>
37 : QStackedWidget( parent )
39 , mMasterModel( NULL )
40 , mAttributeDialog( NULL )
42 , mProgressDlg( NULL )
43 , mFeatureSelectionManager( NULL )
59 connect(
this, SIGNAL( currentChanged(
int ) ),
this, SLOT(
saveEditChanges() ) );
71 connect( mTableView, SIGNAL( willShowContextMenu( QMenu*, QModelIndex ) ),
this, SLOT(
viewWillShowContextMenu( QMenu*, QModelIndex ) ) );
97 if ( displayExpression ==
"" )
102 displayExpression = QString(
"COALESCE(\"%1\", '<NULL>')" ).arg( defaultField );
107 if ( displayExpression ==
"" )
111 if ( pkAttrs.size() > 0 )
113 if ( pkAttrs.size() == 1 )
114 defaultField = pkAttrs.at( 0 );
117 QStringList pkFields;
119 Q_FOREACH(
int attr, pkAttrs )
121 pkFields.append(
"COALESCE(\"" + fields[attr].name() +
"\", '<NULL>')" );
124 displayExpression = pkFields.join(
"||', '||" );
126 else if ( fields.size() > 0 )
128 if ( fields.size() == 1 )
129 defaultField = fields.at( 0 ).name();
132 QStringList fieldNames;
135 fieldNames.append(
"COALESCE(\"" + field.
name() +
"\", '<NULL>')" );
138 displayExpression = fieldNames.join(
"||', '||" );
143 displayExpression =
"'[Please define preview text]'";
148 QList< QAction* > previewActions = mFeatureListPreviewButton->actions();
149 foreach ( QAction* a, previewActions )
151 if ( a != mActionExpressionPreview )
158 mFeatureListPreviewButton->addAction( mActionExpressionPreview );
159 mFeatureListPreviewButton->addAction( mActionPreviewColumnsMenu );
161 foreach (
const QgsField field, fields )
166 QString text = field.
name();
169 QAction* previewAction =
new QAction( icon, text, mFeatureListPreviewButton );
174 if ( text == defaultField )
176 mFeatureListPreviewButton->setDefaultAction( previewAction );
182 if ( !mFeatureListPreviewButton->defaultAction() )
184 mFeatureList->setDisplayExpression( displayExpression );
185 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
189 mFeatureListPreviewButton->defaultAction()->trigger();
196 QStackedWidget::hideEvent( event );
202 QStackedWidget::focusOutEvent( event );
207 setCurrentIndex( view );
224 int cacheSize = qMax( 1, settings.value(
"/qgis/attributeTableRowCache",
"10000" ).toInt() );
226 mLayerCache->setCacheGeometry(
false );
229 connect( mLayerCache, SIGNAL(
progress(
int,
bool & ) ),
this, SLOT(
progress(
int,
bool & ) ) );
232 mLayerCache->setFullCache(
true );
235 connect( layer, SIGNAL( editingStarted() ),
this, SLOT(
editingToggled() ) );
236 connect( layer, SIGNAL( beforeCommitChanges() ),
this, SLOT(
editingToggled() ) );
237 connect( layer, SIGNAL( editingStopped() ),
this, SLOT(
editingToggled() ) );
271 bool dontChange =
false;
300 mFeatureList->setEditSelection( fids );
317 if ( buttonBox && buttonBox->button( QDialogButtonBox::Ok ) )
319 QPushButton* okBtn = buttonBox->button( QDialogButtonBox::Ok );
332 if ( src.count() != dst.count() )
340 for ( ; i < dst.count() && dst[i] == src[i]; ++i )
343 if ( i == dst.count() )
348 for ( ; i < dst.count(); ++i )
350 if ( dst[i] == src[i] )
371 dlg.setWindowTitle(
tr(
"Expression based preview" ) );
374 if ( dlg.exec() == QDialog::Accepted )
376 mFeatureList->setDisplayExpression( dlg.expressionText() );
377 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
378 mFeatureListPreviewButton->setPopupMode( QToolButton::MenuButtonPopup );
384 QAction* previewAction = qobject_cast< QAction* >( action );
388 if ( !mFeatureList->setDisplayExpression( QString(
"COALESCE( \"%1\", '<NULL>' )" ).arg( previewAction->text() ) ) )
390 QMessageBox::warning(
this
391 ,
tr(
"Could not set preview column" )
392 ,
tr(
"Could not set column '%1' as preview column.\nParser error:\n%2" )
393 .arg( previewAction->text() )
394 .arg( mFeatureList->parserErrorString() )
399 mFeatureListPreviewButton->setDefaultAction( previewAction );
400 mFeatureListPreviewButton->setPopupMode( QToolButton::InstantPopup );
404 Q_ASSERT( previewAction );
428 QModelIndex sourceIndex =
mFilterModel->mapToSource( atIndex );
434 QAction *a = menu->addAction(
tr(
"Run layer action" ) );
435 a->setEnabled(
false );
445 menu->addAction( action.
name(), a, SLOT( execute() ) );
451 if ( registeredActions.size() > 0 )
454 menu->addSeparator();
456 QList<QgsMapLayerAction*>::iterator actionIt;
457 for ( actionIt = registeredActions.begin(); actionIt != registeredActions.end(); ++actionIt )
460 menu->addAction(( *actionIt )->text(), a, SLOT( execute() ) );
464 menu->addSeparator();
466 menu->addAction(
tr(
"Open form" ), a, SLOT( featureForm() ) );
510 for (
int idx = 0; idx < newFeat.
attributes().count(); ++idx )
512 if ( idx == attribute )
543 if ( fid == feat->
id() )
592 mTableView->setFeatureSelectionManager( featureSelectionManager );
605 mProgressDlg =
new QProgressDialog(
tr(
"Loading features..." ),
tr(
"Abort" ), 0, 0,
this );
612 mProgressDlg->setLabelText(
tr(
"%1 features loaded." ).arg( i ) );
614 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.
bool isValid() const
Return the validity of this feature.
void setFilterMode(FilterMode filterMode)
Set the filter mode the filter will use.
QgsAttributeAction * actions()
virtual void hideEvent(QHideEvent *)
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.
void beginEditCommand(QString text)
Create edit command for undo/redo operations.
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
void attributeDeleted(int attribute)
If an attribute on this layer is deleted, remove the field also for open attribute dialogs...
ViewMode
The view modes, in which this widget can present information.
void reloadAttribute(const int &attribute)
Update the shown feature if an attribute changed.
bool setAttribute(int field, const QVariant &attr)
Set an attribute by id.
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...
bool editable()
Is this dialog editable?
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)
QgsAttributeEditorContext mEditorContext
Map canvas is a class for displaying all GIS data types on a canvas.
virtual void focusOutEvent(QFocusEvent *)
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
void deleteAttribute(int field)
Deletes an attribute and its value.
QgsFeatureListModel * mFeatureListModel
void executeMapLayerAction(QgsMapLayerAction *action, const QModelIndex &idx) const
Execute a QgsMapLayerAction.
The attribute value should not be shown in the attribute form.
EditType editType(int idx)
get edit type
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.
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
Q_DECL_DEPRECATED bool changeAttributeValue(QgsFeatureId fid, int field, QVariant value, bool emitSignal)
Changes an attribute value (but does not commit it)
const QgsAttributes & attributes() const
const QString displayField() const
Returns the primary display field name used in the identify results dialog.
void featureDeleted(QgsFeatureId fid)
Gets called when a feature is deleted.
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 endEditCommand()
Finish edit command and add it to undo/redo stack.
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.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
QVector< QVariant > QgsAttributes
bool featureAtId(QgsFeatureId featureId, QgsFeature &feature, bool skipCache=false)
Gets the feature at the given feature id.
QgsAttributeDialog * mAttributeDialog
QgsAttributeTableFilterModel * mFilterModel
void attributeAdded(int attribute)
If an attribute on this layer is added, add the field also for open attribute dialogs.
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
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.