Skip to content

Commit b1a2bef

Browse files
committed
[relation widgets] General update
* Improve speed (lazy loading) * Loop detection for circular dependencies (Fix #10850) * Some memory leaks fixed * More const-correctness * Fix the attribute editor context
1 parent 016e1d7 commit b1a2bef

26 files changed

+313
-212
lines changed

python/gui/qgsattributeeditorcontext.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ class QgsAttributeEditorContext
2424
*
2525
* @param layer The layer to adjust for.
2626
*/
27-
void adjustForLayer( QgsVectorLayer* layer );
27+
// void adjustForLayer( QgsVectorLayer* layer );
2828
};

python/gui/qgsvectorlayertools.sip

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class QgsVectorLayerTools
1313
* @param defaultGeometry A default geometry to add to the feature
1414
* @return True in case of success, False if the operation failed/was aborted
1515
*/
16-
virtual bool addFeature( QgsVectorLayer* layer, QgsAttributeMap defaultValues = QgsAttributeMap(), const QgsGeometry& defaultGeometry = QgsGeometry() ) = 0;
16+
virtual bool addFeature( QgsVectorLayer* layer, QgsAttributeMap defaultValues = QgsAttributeMap(), const QgsGeometry& defaultGeometry = QgsGeometry() ) const = 0;
1717

1818

1919
/**
@@ -25,7 +25,7 @@ class QgsVectorLayerTools
2525
*
2626
* @return True, if the editing session was started
2727
*/
28-
virtual bool startEditing( QgsVectorLayer* layer ) = 0;
28+
virtual bool startEditing( QgsVectorLayer* layer ) const = 0;
2929

3030
/**
3131
* Will be called, when an editing session is ended and the features should be commited.
@@ -35,6 +35,6 @@ class QgsVectorLayerTools
3535
* @param allowCancel True if a cancel button should be offered
3636
* @return True if successful
3737
*/
38-
virtual bool stopEditing( QgsVectorLayer* layer, bool allowCancel = true ) = 0;
38+
virtual bool stopEditing( QgsVectorLayer* layer, bool allowCancel = true ) const = 0;
3939

4040
};

src/app/qgisapp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
666666

667667
// Init the editor widget types
668668
QgsEditorWidgetRegistry* editorWidgetRegistry = QgsEditorWidgetRegistry::instance();
669-
QgsAttributeEditorContext context;
670-
context.setVectorLayerTools( vectorLayerTools() );
671669
editorWidgetRegistry->registerWidget( "Classification", new QgsClassificationWidgetWrapperFactory( tr( "Classification" ) ) );
672670
editorWidgetRegistry->registerWidget( "Range", new QgsRangeWidgetFactory( tr( "Range" ) ) );
673671
editorWidgetRegistry->registerWidget( "UniqueValues", new QgsUniqueValueWidgetFactory( tr( "Unique Values" ) ) );
@@ -682,7 +680,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
682680
editorWidgetRegistry->registerWidget( "Photo", new QgsPhotoWidgetFactory( tr( "Photo" ) ) );
683681
editorWidgetRegistry->registerWidget( "WebView", new QgsWebViewWidgetFactory( tr( "Web View" ) ) );
684682
editorWidgetRegistry->registerWidget( "Color", new QgsColorWidgetFactory( tr( "Color" ) ) );
685-
editorWidgetRegistry->registerWidget( "RelationReference", new QgsRelationReferenceFactory( tr( "Relation Reference" ), context, mMapCanvas, mInfoBar ) );
683+
editorWidgetRegistry->registerWidget( "RelationReference", new QgsRelationReferenceFactory( tr( "Relation Reference" ), mMapCanvas, mInfoBar ) );
686684
editorWidgetRegistry->registerWidget( "DateTime", new QgsDateTimeEditFactory( tr( "Date/Time" ) ) );
687685

688686
mInternalClipboard = new QgsClipboard; // create clipboard
@@ -935,6 +933,8 @@ QgisApp::~QgisApp()
935933

936934
delete mComposerManager;
937935

936+
delete mVectorLayerTools;
937+
938938
deletePrintComposers();
939939
removeAnnotationItems();
940940

src/app/qgisappinterface.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,10 @@ QgsAttributeDialog* QgisAppInterface::getFeatureForm( QgsVectorLayer *l, QgsFeat
629629
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapSettings().hasCrsTransformEnabled() );
630630
myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
631631

632-
QgsAttributeDialog *dialog = new QgsAttributeDialog( l, &feature, false, NULL, true );
632+
QgsAttributeEditorContext context;
633+
context.setDistanceArea( myDa );
634+
context.setVectorLayerTools( qgis->vectorLayerTools() );
635+
QgsAttributeDialog *dialog = new QgsAttributeDialog( l, &feature, false, NULL, true, context );
633636
return dialog;
634637
}
635638

src/app/qgsguivectorlayertools.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ QgsGuiVectorLayerTools::QgsGuiVectorLayerTools()
3232
: QObject( NULL )
3333
{}
3434

35-
bool QgsGuiVectorLayerTools::addFeature( QgsVectorLayer* layer, QgsAttributeMap defaultValues, const QgsGeometry& defaultGeometry )
35+
bool QgsGuiVectorLayerTools::addFeature( QgsVectorLayer* layer, QgsAttributeMap defaultValues, const QgsGeometry& defaultGeometry ) const
3636
{
3737
QgsFeature f;
3838
f.setGeometry( defaultGeometry );
3939
QgsFeatureAction a( tr( "Add feature" ), f, layer );
4040
return a.addFeature( defaultValues );
4141
}
4242

43-
bool QgsGuiVectorLayerTools::startEditing( QgsVectorLayer* layer )
43+
bool QgsGuiVectorLayerTools::startEditing( QgsVectorLayer* layer ) const
4444
{
4545
if ( !layer )
4646
{
@@ -65,7 +65,7 @@ bool QgsGuiVectorLayerTools::startEditing( QgsVectorLayer* layer )
6565
return res;
6666
}
6767

68-
bool QgsGuiVectorLayerTools::stopEditing( QgsVectorLayer* layer, bool allowCancel )
68+
bool QgsGuiVectorLayerTools::stopEditing( QgsVectorLayer* layer, bool allowCancel ) const
6969
{
7070
bool res = true;
7171

@@ -127,7 +127,7 @@ bool QgsGuiVectorLayerTools::stopEditing( QgsVectorLayer* layer, bool allowCance
127127
return res;
128128
}
129129

130-
void QgsGuiVectorLayerTools::commitError( QgsVectorLayer* vlayer )
130+
void QgsGuiVectorLayerTools::commitError( QgsVectorLayer* vlayer ) const
131131
{
132132
QgsMessageViewer *mv = new QgsMessageViewer();
133133
mv->setWindowTitle( tr( "Commit errors" ) );

src/app/qgsguivectorlayertools.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class QgsGuiVectorLayerTools : public QgsVectorLayerTools, public QObject
3737
*
3838
* @return True in case of success, False if the operation failed/was aborted
3939
*/
40-
bool addFeature( QgsVectorLayer *layer, QgsAttributeMap defaultValues, const QgsGeometry &defaultGeometry );
40+
bool addFeature( QgsVectorLayer *layer, QgsAttributeMap defaultValues, const QgsGeometry &defaultGeometry ) const;
4141

4242
/**
4343
* This should be called, whenever a vector layer should be switched to edit mode. If successful
@@ -47,7 +47,7 @@ class QgsGuiVectorLayerTools : public QgsVectorLayerTools, public QObject
4747
*
4848
* @return True, if the editing session was started
4949
*/
50-
bool startEditing( QgsVectorLayer* layer );
50+
bool startEditing( QgsVectorLayer* layer ) const;
5151

5252
/**
5353
* Should be called, when an editing session is ended and the features should be commited.
@@ -59,10 +59,10 @@ class QgsGuiVectorLayerTools : public QgsVectorLayerTools, public QObject
5959
*
6060
* @return True if successful
6161
*/
62-
bool stopEditing( QgsVectorLayer* layer , bool allowCancel = true );
62+
bool stopEditing( QgsVectorLayer* layer , bool allowCancel = true ) const;
6363

6464
private:
65-
void commitError( QgsVectorLayer* vlayer );
65+
void commitError( QgsVectorLayer* vlayer ) const;
6666
};
6767

6868
#endif // QGSGUIVECTORLAYERTOOLS_H

src/gui/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ qgisinterface.cpp
116116
qgsannotationitem.cpp
117117
qgsattributedialog.cpp
118118
qgsattributeeditor.cpp
119-
qgsattributeeditorcontext.cpp
120119
qgsattributeform.cpp
121120
qgsattributeforminterface.cpp
122121
qgsattributeformlegacyinterface.cpp

src/gui/attributetable/qgsfeaturelistview.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@
3434

3535
QgsFeatureListView::QgsFeatureListView( QWidget *parent )
3636
: QListView( parent )
37-
, mCurrentEditSelectionModel( NULL )
38-
, mFeatureSelectionModel( NULL )
39-
, mItemDelegate( NULL )
37+
, mModel( 0 )
38+
, mCurrentEditSelectionModel( 0 )
39+
, mFeatureSelectionModel( 0 )
40+
, mItemDelegate( 0 )
4041
, mEditSelectionDrag( false )
4142
{
4243
setSelectionMode( QAbstractItemView::ExtendedSelection );
@@ -100,7 +101,7 @@ QString QgsFeatureListView::parserErrorString()
100101
QgsFeatureIds QgsFeatureListView::currentEditSelection()
101102
{
102103
QgsFeatureIds selection;
103-
Q_FOREACH ( QModelIndex idx, mCurrentEditSelectionModel->selectedIndexes() )
104+
Q_FOREACH( QModelIndex idx, mCurrentEditSelectionModel->selectedIndexes() )
104105
{
105106
selection << idx.data( QgsAttributeTableModel::FeatureIdRole ).value<QgsFeatureId>();
106107
}
@@ -115,20 +116,27 @@ void QgsFeatureListView::setCurrentFeatureEdited( bool state )
115116

116117
void QgsFeatureListView::mousePressEvent( QMouseEvent *event )
117118
{
118-
QPoint pos = event->pos();
119+
if ( mModel )
120+
{
121+
QPoint pos = event->pos();
119122

120-
QModelIndex index = indexAt( pos );
123+
QModelIndex index = indexAt( pos );
121124

122-
if ( QgsFeatureListViewDelegate::EditElement == mItemDelegate->positionToElement( event->pos() ) )
123-
{
124-
mEditSelectionDrag = true;
125-
setEditSelection( mModel->mapToMaster( index ), QItemSelectionModel::ClearAndSelect );
125+
if ( QgsFeatureListViewDelegate::EditElement == mItemDelegate->positionToElement( event->pos() ) )
126+
{
127+
mEditSelectionDrag = true;
128+
setEditSelection( mModel->mapToMaster( index ), QItemSelectionModel::ClearAndSelect );
129+
}
130+
else
131+
{
132+
mFeatureSelectionModel->enableSync( false );
133+
selectRow( index, true );
134+
repaintRequested();
135+
}
126136
}
127137
else
128138
{
129-
mFeatureSelectionModel->enableSync( false );
130-
selectRow( index, true );
131-
repaintRequested();
139+
QgsDebugMsg( "No model assigned to this view" );
132140
}
133141
}
134142

src/gui/editorwidgets/core/qgseditorwidgetwrapper.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ QgsEditorWidgetWrapper* QgsEditorWidgetWrapper::fromWidget( QWidget* widget )
4242

4343
void QgsEditorWidgetWrapper::setEnabled( bool enabled )
4444
{
45-
if ( widget() )
45+
QWidget* wdg = widget();
46+
if ( wdg )
4647
{
47-
widget()->setEnabled( enabled );
48+
wdg->setEnabled( enabled );
4849
}
4950
}
5051

src/gui/editorwidgets/core/qgswidgetwrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void QgsWidgetWrapper::setConfig( const QgsEditorWidgetConfig& config )
4747
mConfig = config;
4848
}
4949

50-
void QgsWidgetWrapper::setContext( const QgsAttributeEditorContext& context )
50+
void QgsWidgetWrapper::setContext( const QgsAttributeEditorContext context )
5151
{
5252
mContext = context;
5353
}

0 commit comments

Comments
 (0)