Skip to content
Permalink
Browse files

Fix re-initialization of dual view

  • Loading branch information
m-kuhn committed Sep 22, 2014
1 parent f351195 commit 55f86d5dfad2deddbd3e75509add91e4305c40d0
@@ -118,8 +118,10 @@ void QgsAttributeTableView::setModel( QgsAttributeTableFilterModel* filterModel
mFilterModel = filterModel;
QTableView::setModel( filterModel );

connect( mFilterModel, SIGNAL( destroyed() ), this, SLOT( modelDeleted() ) );

delete mFeatureSelectionModel;
mFeatureSelectionModel = NULL;
mFeatureSelectionModel = 0;

if ( filterModel )
{
@@ -255,6 +257,13 @@ void QgsAttributeTableView::_q_selectRow( int row )
selectRow( row, false );
}

void QgsAttributeTableView::modelDeleted()
{
mFilterModel = 0;
mFeatureSelectionManager = 0;
mFeatureSelectionModel = 0;
}

void QgsAttributeTableView::selectRow( int row, bool anchor )
{
if ( selectionBehavior() == QTableView::SelectColumns
@@ -137,6 +137,9 @@ class GUI_EXPORT QgsAttributeTableView : public QTableView
virtual void selectRow( int row );
virtual void _q_selectRow( int row );

private slots:
void modelDeleted();

private:
void selectRow( int row, bool anchor );
QgsAttributeTableModel* mMasterModel;
@@ -37,6 +37,8 @@ QgsDualView::QgsDualView( QWidget* parent )
: QStackedWidget( parent )
, mEditorContext()
, mMasterModel( 0 )
, mFilterModel( 0 )
, mFeatureListModel( 0 )
, mAttributeForm( 0 )
, mLayerCache( 0 )
, mProgressDlg( 0 )
@@ -78,7 +80,9 @@ void QgsDualView::init( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, const Qg

connect( mAttributeForm, SIGNAL( attributeChanged( QString, QVariant ) ), this, SLOT( featureFormAttributeChanged() ) );

if ( !mFeatureListPreviewButton->actions().count() )
if ( mFeatureListPreviewButton->defaultAction() )
mFeatureList->setDisplayExpression( mDisplayExpression );
else
columnBoxInit();
}

@@ -143,21 +147,10 @@ void QgsDualView::columnBoxInit()
}
}

// now initialise the menu
QList< QAction* > previewActions = mFeatureListPreviewButton->actions();
foreach ( QAction* a, previewActions )
{
if ( a != mActionExpressionPreview )
{
mPreviewActionMapper->removeMappings( a );
delete a;
}
}

mFeatureListPreviewButton->addAction( mActionExpressionPreview );
mFeatureListPreviewButton->addAction( mActionPreviewColumnsMenu );

foreach ( const QgsField& field, fields )
Q_FOREACH( const QgsField& field, fields )
{
if ( mLayerCache->layer()->editorWidgetV2( mLayerCache->layer()->fieldNameIndex( field.name() ) ) != "Hidden" )
{
@@ -182,6 +175,7 @@ void QgsDualView::columnBoxInit()
{
mFeatureList->setDisplayExpression( displayExpression );
mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
mDisplayExpression = mFeatureList->displayExpression();
}
else
{
@@ -223,6 +217,10 @@ void QgsDualView::initLayerCache( QgsVectorLayer* layer )

void QgsDualView::initModels( QgsMapCanvas* mapCanvas, const QgsFeatureRequest& request )
{
delete mFeatureListModel;
delete mFilterModel;
delete mMasterModel;

mMasterModel = new QgsAttributeTableModel( mLayerCache, this );
mMasterModel->setRequest( request );
mMasterModel->setEditorContext( mEditorContext );
@@ -282,6 +280,8 @@ void QgsDualView::previewExpressionBuilder()
mFeatureListPreviewButton->setDefaultAction( mActionExpressionPreview );
mFeatureListPreviewButton->setPopupMode( QToolButton::MenuButtonPopup );
}

mDisplayExpression = mFeatureList->displayExpression();
}

void QgsDualView::previewColumnChanged( QObject* action )
@@ -306,6 +306,8 @@ void QgsDualView::previewColumnChanged( QObject* action )
}
}

mDisplayExpression = mFeatureList->displayExpression();

Q_ASSERT( previewAction );
}

@@ -232,6 +232,7 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
QProgressDialog* mProgressDlg;
QgsIFeatureSelectionManager* mFeatureSelectionManager;
QgsDistanceArea mDistanceArea;
QString mDisplayExpression;

friend class TestQgsDualView;
};
@@ -34,7 +34,7 @@ QWidget* QgsRelationWidgetWrapper::createWidget( QWidget* parent )

void QgsRelationWidgetWrapper::setFeature( const QgsFeature& feature )
{
if ( mWidget )
if ( mWidget && mRelation.isValid() )
mWidget->setRelationFeature( mRelation, feature );
}

0 comments on commit 55f86d5

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