Skip to content
Permalink
Browse files

Dual View: Commit feature edits to edit buffer, when the attribute ta…

…ble is closed

or when the view mode is changed
or when the focus is lost
  • Loading branch information
m-kuhn committed Apr 15, 2013
1 parent f9a6f0a commit 2d07fa697e9b004301f06ca7450adff361edebcc
@@ -2491,6 +2491,8 @@ bool QgsVectorLayer::commitChanges()
return false;
}

emit beforeCommitChanges();

bool success = mEditBuffer->commitChanges( mCommitErrors );

if ( success )
@@ -1242,8 +1242,15 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** This signal is emitted when modifications has been done on layer */
void layerModified();

/** Is emitted, when editing on this layer has started*/
void editingStarted();

/** Is emitted, when edited changes succesfully have been written to the data provider */
void editingStopped();

/** Is emitted, before changes are commited to the data provider */
void beforeCommitChanges();

/**
* Will be emitted, when a new attribute has been added to this vector layer.
* Applies only to types {@link QgsFields::OriginEdit} and {@link QgsFields::OriginProvider}
@@ -1267,6 +1274,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/**
* Is emitted, whenever the fields available from this layer have been changed.
* This can be due to manually adding attributes or due to a join.
*
* @note Added in 2.0
*/
void updatedFields();
void layerDeleted();
@@ -47,6 +47,7 @@ QgsDualView::QgsDualView( QWidget* parent )
connect( mActionExpressionPreview, SIGNAL( triggered() ), SLOT( previewExpressionBuilder() ) );
connect( mPreviewActionMapper, SIGNAL( mapped( QObject* ) ), SLOT( previewColumnChanged( QObject* ) ) );
connect( mFeatureList, SIGNAL( displayExpressionChanged( QString ) ), this, SLOT( previewExpressionChanged( QString ) ) );
connect( this, SIGNAL( currentChanged(int) ), this, SLOT( saveEditChanges() ) );
}

QgsDualView::~QgsDualView()
@@ -61,7 +62,7 @@ void QgsDualView::init( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, QgsDista
connect( mTableView, SIGNAL( willShowContextMenu( QMenu*, QModelIndex ) ), this, SLOT( viewWillShowContextMenu( QMenu*, QModelIndex ) ) );

connect( layer, SIGNAL( editingStarted() ), this, SLOT( editingToggled() ) );
connect( layer, SIGNAL( editingStopped() ), this, SLOT( editingToggled() ) );
connect( layer, SIGNAL( beforeCommitChanges() ), this, SLOT( editingToggled() ) );

initLayerCache( layer );
initModels( mapCanvas );
@@ -170,6 +171,18 @@ void QgsDualView::columnBoxInit()
}
}

void QgsDualView::hideEvent( QHideEvent* event )
{
saveEditChanges();
QStackedWidget::hideEvent( event );
}

void QgsDualView::focusOutEvent( QFocusEvent* event )
{
saveEditChanges();
QStackedWidget::focusOutEvent( event );
}

void QgsDualView::setView( QgsDualView::ViewMode view )
{
setCurrentIndex( view );
@@ -226,6 +239,26 @@ void QgsDualView::on_mFeatureList_currentEditSelectionChanged( const QgsFeature
// Backup old dialog and delete only after creating the new dialog, so we can "hot-swap" the contained QgsFeature
QgsAttributeDialog* oldDialog = mAttributeDialog;

if ( mAttributeDialog->dialog() )
{
saveEditChanges();
mAttributeEditorLayout->removeWidget( mAttributeDialog->dialog() );
}

mAttributeDialog = new QgsAttributeDialog( mLayerCache->layer(), new QgsFeature( feat ), true, mDistanceArea, this, false );
mAttributeEditorLayout->addWidget( mAttributeDialog->dialog() );
mAttributeDialog->dialog()->setVisible( true );

delete oldDialog;
}

void QgsDualView::setCurrentEditSelection( const QgsFeatureIds& fids )
{
mFeatureList->setEditSelection( fids );
}

void QgsDualView::saveEditChanges()
{
if ( mAttributeDialog->dialog() )
{
if ( mLayerCache->layer()->isEditable() )
@@ -253,20 +286,7 @@ void QgsDualView::on_mFeatureList_currentEditSelectionChanged( const QgsFeature

mLayerCache->layer()->endEditCommand();
}

mAttributeEditorLayout->removeWidget( mAttributeDialog->dialog() );
}

mAttributeDialog = new QgsAttributeDialog( mLayerCache->layer(), new QgsFeature( feat ), true, mDistanceArea, this, false );
mAttributeEditorLayout->addWidget( mAttributeDialog->dialog() );
mAttributeDialog->dialog()->setVisible( true );

delete oldDialog;
}

void QgsDualView::setCurrentEditSelection( const QgsFeatureIds& fids )
{
mFeatureList->setEditSelection( fids );
}

void QgsDualView::previewExpressionBuilder()
@@ -388,7 +408,6 @@ void QgsDualView::finished()
mProgressDlg = 0;
}


/*
* QgsAttributeTableAction
*/
@@ -28,7 +28,13 @@ class QgsAttributeDialog;
class QSignalMapper;

/**
* @brief
* This widget is used to show the attributes of a set of features of a {@link QgsVectorLayer}.
* The attributes can be edited.
* It supports two different layouts: the table layout, in which the attributes for the features
* are shown in a table and the editor layout, where the features are shown as a selectable list
* and the attributes for the currently selected feature are shown in a form.
*
* @note Added in 2.0
*/
class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBase
{
@@ -37,65 +43,115 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
public:

/**
* @brief
* The view modes, in which this widget can present information.
* Relates to the QStackedWidget stacks.
*
*/
enum ViewMode
{
/**
* Shows the features and attributes in a table layout
*/
AttributeTable = 0,
/**
* Show a list of the features, where one can be chosen
* and the according attribute dialog will be presented
* in the neighbouring frame.
*/
AttributeEditor = 1
};

/**
* @brief
*
* @param parent
* @brief Constructor
* @param parent The parent widget
*/
explicit QgsDualView( QWidget* parent = 0 );
virtual ~QgsDualView();

/**
* Has to be called to initialize the dual view.
*
* @param layer The layer which should be used to fetch features
* @param mapCanvas The mapCanvas (used for the FilterMode
* {@link QgsAttributeTableFilterModel::ShowVisible}
* @param myDa Used for attribute dialog creation
*/
void init( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, QgsDistanceArea myDa );
void columnBoxInit();

/**
* @brief
* Change the current view mode.
*
* @param view
* @param The view mode to set
*/
void setView( ViewMode view );

/**
* @brief
* Set the filter mode
*
* @param filterMode
*/
void setFilterMode( QgsAttributeTableFilterModel::FilterMode filterMode );

void setSelectedOnTop( bool selectedOnTop );

/**
* @brief
* Toggle the selectedOnTop flag. If enabled, selected features will be moved to top.
*
* @param featureRequest
* @param selectedOnTop True: Show selected features on top.
* False: Use defined sorting column.
*/
void setFeatureRequest( const QgsFeatureRequest* featureRequest );
void setSelectedOnTop( bool selectedOnTop );

/**
* @brief
* Returns the number of features on the layer.
*
* @return Number of features
*/
void setSelectionMode();

int featureCount();

/**
* Returns the number of features which are currently visible, according to the
* filter restrictions
*
* @return Number of features
*/
int filteredFeatureCount();

/**
* Set a list of currently visible features
*
* @param filteredFeatures A list of feature ids
*
*/
void setFilteredFeatures( QgsFeatureIds filteredFeatures );

/**
* Returns the model which has the information about all features (not only filtered)
*
* @return The master model
*/
QgsAttributeTableModel* masterModel() const { return mMasterModel; }

protected:
/**
* Initializes widgets which depend on the attributes of this layer
*/
void columnBoxInit();

virtual void hideEvent(QHideEvent *);
virtual void focusOutEvent(QFocusEvent *);

public slots:
void setCurrentEditSelection( const QgsFeatureIds& fids );
/**
* @brief Set the current edit selection in the {@link AttributeEditor} mode.
*
* @param fids A list of edited features (Currently only one at a time is supported)
*/
void setCurrentEditSelection( const QgsFeatureIds& fids );

/**
* @brief saveEditChanges
*/

void saveEditChanges();

signals:
/**
@@ -112,6 +168,8 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
private slots:
/**
* Changes the currently visible feature within the attribute editor
*
* @param feat The newly visible feature
*/
void on_mFeatureList_currentEditSelectionChanged( const QgsFeature &feat );

0 comments on commit 2d07fa6

Please sign in to comment.
You can’t perform that action at this time.