30 #include <QProgressDialog>
31 #include <QMessageBox>
34 : QStackedWidget( parent )
35 , mAttributeDialog( NULL )
36 , mProgressDlg( NULL )
52 connect(
this, SIGNAL( currentChanged(
int ) ),
this, SLOT(
saveEditChanges() ) );
64 connect( mTableView, SIGNAL( willShowContextMenu( QMenu*, QModelIndex ) ),
this, SLOT(
viewWillShowContextMenu( QMenu*, QModelIndex ) ) );
90 if ( displayExpression ==
"" )
95 displayExpression = QString(
"COALESCE(\"%1\", '<NULL>')" ).arg( defaultField );
100 if ( displayExpression ==
"" )
104 if ( pkAttrs.size() > 0 )
106 if ( pkAttrs.size() == 1 )
107 defaultField = pkAttrs.at( 0 );
110 QStringList pkFields;
112 Q_FOREACH(
int attr, pkAttrs )
114 pkFields.append(
"COALESCE(\"" + fields[attr].name() +
"\", '<NULL>')" );
117 displayExpression = pkFields.join(
"||', '||" );
119 else if ( fields.size() > 0 )
121 if ( fields.size() == 1 )
122 defaultField = fields.at( 0 ).name();
125 QStringList fieldNames;
128 fieldNames.append(
"COALESCE(\"" + field.
name() +
"\", '<NULL>')" );
131 displayExpression = fieldNames.join(
"||', '||" );
136 displayExpression =
"'[Please define preview text]'";
141 QList< QAction* > previewActions = mFeatureListPreviewButton->actions();
142 foreach ( QAction* a, previewActions )
144 if ( a != mActionExpressionPreview )
151 mFeatureListPreviewButton->addAction( mActionExpressionPreview );
152 mFeatureListPreviewButton->addAction( mActionPreviewColumnsMenu );
154 foreach (
const QgsField field, fields )
159 QString text = field.
name();
162 QAction* previewAction =
new QAction( icon, text, mFeatureListPreviewButton );
167 if ( text == defaultField )
169 mFeatureListPreviewButton->setDefaultAction( previewAction );
175 if ( !mFeatureListPreviewButton->defaultAction() )
177 mFeatureList->setDisplayExpression( displayExpression );
178 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
182 mFeatureListPreviewButton->defaultAction()->trigger();
189 QStackedWidget::hideEvent( event );
195 QStackedWidget::focusOutEvent( event );
200 setCurrentIndex( view );
217 int cacheSize = qMax( 1, settings.value(
"/qgis/attributeTableRowCache",
"10000" ).toInt() );
219 mLayerCache->setCacheGeometry(
false );
222 connect( mLayerCache, SIGNAL(
progress(
int,
bool & ) ),
this, SLOT(
progress(
int,
bool & ) ) );
225 mLayerCache->setFullCache(
true );
228 connect( layer, SIGNAL( editingStarted() ),
this, SLOT(
editingToggled() ) );
229 connect( layer, SIGNAL( beforeCommitChanges() ),
this, SLOT(
editingToggled() ) );
230 connect( layer, SIGNAL( editingStopped() ),
this, SLOT(
editingToggled() ) );
275 mFeatureList->setEditSelection( fids );
295 if ( src.count() != dst.count() )
303 for (
int i = 0; i < dst.count(); ++i )
305 if ( dst[i] != src[i] )
320 dlg.setWindowTitle(
tr(
"Expression based preview" ) );
323 if ( dlg.exec() == QDialog::Accepted )
325 mFeatureList->setDisplayExpression( dlg.expressionText() );
326 mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
327 mFeatureListPreviewButton->setPopupMode( QToolButton::MenuButtonPopup );
333 QAction* previewAction = qobject_cast< QAction* >( action );
337 if ( !mFeatureList->setDisplayExpression( QString(
"COALESCE( \"%1\", '<NULL>' )" ).arg( previewAction->text() ) ) )
339 QMessageBox::warning(
this
340 ,
tr(
"Could not set preview column" )
341 ,
tr(
"Could not set column '%1' as preview column.\nParser error:\n%2" )
342 .arg( previewAction->text() )
343 .arg( mFeatureList->parserErrorString() )
348 mFeatureListPreviewButton->setDefaultAction( previewAction );
349 mFeatureListPreviewButton->setPopupMode( QToolButton::InstantPopup );
353 Q_ASSERT( previewAction );
377 QModelIndex sourceIndex =
mFilterModel->mapToSource( atIndex );
382 QAction *a = menu->addAction(
tr(
"Run action" ) );
383 a->setEnabled(
false );
393 menu->addAction( action.
name(), a, SLOT( execute() ) );
398 menu->addAction(
tr(
"Open form" ), a, SLOT( featureForm() ) );
442 for (
int idx = 0; idx < newFeat.
attributes().count(); ++idx )
444 if ( idx == attribute )
475 if ( fid == feat->
id() )
521 mProgressDlg =
new QProgressDialog(
tr(
"Loading features..." ),
tr(
"Abort" ), 0, 0,
this );
528 mProgressDlg->setLabelText(
tr(
"%1 features loaded." ).arg( i ) );
530 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.
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 initModels(QgsMapCanvas *mapCanvas)
void setExpressionText(const QString &text)
void saveEditChanges()
saveEditChanges
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 setDisplayExpression(const QString displayExpression)
Set the preview expression, used to create a human readable preview string.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of rows.
QSet< QgsFeatureId > QgsFeatureIds
void beginEditCommand(QString text)
Create edit command for undo/redo operations.
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.
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)
bool changeAttributeValue(QgsFeatureId fid, int field, QVariant value, bool emitSignal=true)
changed an attribute value (but does not commit it)
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 initLayerCache(QgsVectorLayer *layer)
QString name() const
The name of the action.
void deleteAttribute(int field)
Deletes an attribute and its value.
QgsFeatureListModel * mFeatureListModel
void init(QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, QgsDistanceArea myDa)
Has to be called to initialize the dual view.
The attribute value should not be shown in the attribute form.
EditType editType(int idx)
get edit type
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.
QList< int > QgsAttributeList
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) ...
General purpose distance and area calculator.
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
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.
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
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.
QgsDistanceArea mDistanceArea
static QIcon getThemeIcon(const QString theName)
Helper to get a theme icon.