Skip to content

Commit

Permalink
[relation widgets] General update
Browse files Browse the repository at this point in the history
 * Improve speed (lazy loading)
 * Loop detection for circular dependencies (Fix #10850)
 * Some memory leaks fixed
 * More const-correctness
 * Fix the attribute editor context
  • Loading branch information
m-kuhn committed Sep 12, 2014
1 parent 016e1d7 commit b1a2bef
Show file tree
Hide file tree
Showing 26 changed files with 313 additions and 212 deletions.
2 changes: 1 addition & 1 deletion python/gui/qgsattributeeditorcontext.sip
Expand Up @@ -24,5 +24,5 @@ class QgsAttributeEditorContext
*
* @param layer The layer to adjust for.
*/
void adjustForLayer( QgsVectorLayer* layer );
// void adjustForLayer( QgsVectorLayer* layer );
};
6 changes: 3 additions & 3 deletions python/gui/qgsvectorlayertools.sip
Expand Up @@ -13,7 +13,7 @@ class QgsVectorLayerTools
* @param defaultGeometry A default geometry to add to the feature
* @return True in case of success, False if the operation failed/was aborted
*/
virtual bool addFeature( QgsVectorLayer* layer, QgsAttributeMap defaultValues = QgsAttributeMap(), const QgsGeometry& defaultGeometry = QgsGeometry() ) = 0;
virtual bool addFeature( QgsVectorLayer* layer, QgsAttributeMap defaultValues = QgsAttributeMap(), const QgsGeometry& defaultGeometry = QgsGeometry() ) const = 0;


/**
Expand All @@ -25,7 +25,7 @@ class QgsVectorLayerTools
*
* @return True, if the editing session was started
*/
virtual bool startEditing( QgsVectorLayer* layer ) = 0;
virtual bool startEditing( QgsVectorLayer* layer ) const = 0;

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

};
6 changes: 3 additions & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -666,8 +666,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,

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

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

delete mComposerManager;

delete mVectorLayerTools;

deletePrintComposers();
removeAnnotationItems();

Expand Down
5 changes: 4 additions & 1 deletion src/app/qgisappinterface.cpp
Expand Up @@ -629,7 +629,10 @@ QgsAttributeDialog* QgisAppInterface::getFeatureForm( QgsVectorLayer *l, QgsFeat
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapSettings().hasCrsTransformEnabled() );
myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );

QgsAttributeDialog *dialog = new QgsAttributeDialog( l, &feature, false, NULL, true );
QgsAttributeEditorContext context;
context.setDistanceArea( myDa );
context.setVectorLayerTools( qgis->vectorLayerTools() );
QgsAttributeDialog *dialog = new QgsAttributeDialog( l, &feature, false, NULL, true, context );
return dialog;
}

Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsguivectorlayertools.cpp
Expand Up @@ -32,15 +32,15 @@ QgsGuiVectorLayerTools::QgsGuiVectorLayerTools()
: QObject( NULL )
{}

bool QgsGuiVectorLayerTools::addFeature( QgsVectorLayer* layer, QgsAttributeMap defaultValues, const QgsGeometry& defaultGeometry )
bool QgsGuiVectorLayerTools::addFeature( QgsVectorLayer* layer, QgsAttributeMap defaultValues, const QgsGeometry& defaultGeometry ) const
{
QgsFeature f;
f.setGeometry( defaultGeometry );
QgsFeatureAction a( tr( "Add feature" ), f, layer );
return a.addFeature( defaultValues );
}

bool QgsGuiVectorLayerTools::startEditing( QgsVectorLayer* layer )
bool QgsGuiVectorLayerTools::startEditing( QgsVectorLayer* layer ) const
{
if ( !layer )
{
Expand All @@ -65,7 +65,7 @@ bool QgsGuiVectorLayerTools::startEditing( QgsVectorLayer* layer )
return res;
}

bool QgsGuiVectorLayerTools::stopEditing( QgsVectorLayer* layer, bool allowCancel )
bool QgsGuiVectorLayerTools::stopEditing( QgsVectorLayer* layer, bool allowCancel ) const
{
bool res = true;

Expand Down Expand Up @@ -127,7 +127,7 @@ bool QgsGuiVectorLayerTools::stopEditing( QgsVectorLayer* layer, bool allowCance
return res;
}

void QgsGuiVectorLayerTools::commitError( QgsVectorLayer* vlayer )
void QgsGuiVectorLayerTools::commitError( QgsVectorLayer* vlayer ) const
{
QgsMessageViewer *mv = new QgsMessageViewer();
mv->setWindowTitle( tr( "Commit errors" ) );
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsguivectorlayertools.h
Expand Up @@ -37,7 +37,7 @@ class QgsGuiVectorLayerTools : public QgsVectorLayerTools, public QObject
*
* @return True in case of success, False if the operation failed/was aborted
*/
bool addFeature( QgsVectorLayer *layer, QgsAttributeMap defaultValues, const QgsGeometry &defaultGeometry );
bool addFeature( QgsVectorLayer *layer, QgsAttributeMap defaultValues, const QgsGeometry &defaultGeometry ) const;

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

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

private:
void commitError( QgsVectorLayer* vlayer );
void commitError( QgsVectorLayer* vlayer ) const;
};

#endif // QGSGUIVECTORLAYERTOOLS_H
1 change: 0 additions & 1 deletion src/gui/CMakeLists.txt
Expand Up @@ -116,7 +116,6 @@ qgisinterface.cpp
qgsannotationitem.cpp
qgsattributedialog.cpp
qgsattributeeditor.cpp
qgsattributeeditorcontext.cpp
qgsattributeform.cpp
qgsattributeforminterface.cpp
qgsattributeformlegacyinterface.cpp
Expand Down
34 changes: 21 additions & 13 deletions src/gui/attributetable/qgsfeaturelistview.cpp
Expand Up @@ -34,9 +34,10 @@

QgsFeatureListView::QgsFeatureListView( QWidget *parent )
: QListView( parent )
, mCurrentEditSelectionModel( NULL )
, mFeatureSelectionModel( NULL )
, mItemDelegate( NULL )
, mModel( 0 )
, mCurrentEditSelectionModel( 0 )
, mFeatureSelectionModel( 0 )
, mItemDelegate( 0 )
, mEditSelectionDrag( false )
{
setSelectionMode( QAbstractItemView::ExtendedSelection );
Expand Down Expand Up @@ -100,7 +101,7 @@ QString QgsFeatureListView::parserErrorString()
QgsFeatureIds QgsFeatureListView::currentEditSelection()
{
QgsFeatureIds selection;
Q_FOREACH ( QModelIndex idx, mCurrentEditSelectionModel->selectedIndexes() )
Q_FOREACH( QModelIndex idx, mCurrentEditSelectionModel->selectedIndexes() )
{
selection << idx.data( QgsAttributeTableModel::FeatureIdRole ).value<QgsFeatureId>();
}
Expand All @@ -115,20 +116,27 @@ void QgsFeatureListView::setCurrentFeatureEdited( bool state )

void QgsFeatureListView::mousePressEvent( QMouseEvent *event )
{
QPoint pos = event->pos();
if ( mModel )
{
QPoint pos = event->pos();

QModelIndex index = indexAt( pos );
QModelIndex index = indexAt( pos );

if ( QgsFeatureListViewDelegate::EditElement == mItemDelegate->positionToElement( event->pos() ) )
{
mEditSelectionDrag = true;
setEditSelection( mModel->mapToMaster( index ), QItemSelectionModel::ClearAndSelect );
if ( QgsFeatureListViewDelegate::EditElement == mItemDelegate->positionToElement( event->pos() ) )
{
mEditSelectionDrag = true;
setEditSelection( mModel->mapToMaster( index ), QItemSelectionModel::ClearAndSelect );
}
else
{
mFeatureSelectionModel->enableSync( false );
selectRow( index, true );
repaintRequested();
}
}
else
{
mFeatureSelectionModel->enableSync( false );
selectRow( index, true );
repaintRequested();
QgsDebugMsg( "No model assigned to this view" );
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/gui/editorwidgets/core/qgseditorwidgetwrapper.cpp
Expand Up @@ -42,9 +42,10 @@ QgsEditorWidgetWrapper* QgsEditorWidgetWrapper::fromWidget( QWidget* widget )

void QgsEditorWidgetWrapper::setEnabled( bool enabled )
{
if ( widget() )
QWidget* wdg = widget();
if ( wdg )
{
widget()->setEnabled( enabled );
wdg->setEnabled( enabled );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/core/qgswidgetwrapper.cpp
Expand Up @@ -47,7 +47,7 @@ void QgsWidgetWrapper::setConfig( const QgsEditorWidgetConfig& config )
mConfig = config;
}

void QgsWidgetWrapper::setContext( const QgsAttributeEditorContext& context )
void QgsWidgetWrapper::setContext( const QgsAttributeEditorContext context )
{
mContext = context;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/core/qgswidgetwrapper.h
Expand Up @@ -77,7 +77,7 @@ class GUI_EXPORT QgsWidgetWrapper : public QObject
*
* @param context context information
*/
void setContext( const QgsAttributeEditorContext& context );
void setContext( const QgsAttributeEditorContext context );

/**
* Use this inside your overriden classes to access the configuration.
Expand Down
5 changes: 2 additions & 3 deletions src/gui/editorwidgets/qgsrelationreferencefactory.cpp
Expand Up @@ -18,17 +18,16 @@
#include "qgsrelationreferencewidgetwrapper.h"
#include "qgsrelreferenceconfigdlg.h"

QgsRelationReferenceFactory::QgsRelationReferenceFactory( QString name, QgsAttributeEditorContext context, QgsMapCanvas* canvas, QgsMessageBar* messageBar )
QgsRelationReferenceFactory::QgsRelationReferenceFactory( QString name, QgsMapCanvas* canvas, QgsMessageBar* messageBar )
: QgsEditorWidgetFactory( name )
, mEditorContext( context )
, mCanvas( canvas )
, mMessageBar( messageBar )
{
}

QgsEditorWidgetWrapper* QgsRelationReferenceFactory::create( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent ) const
{
return new QgsRelationReferenceWidgetWrapper( vl, fieldIdx, editor, mEditorContext, mCanvas, mMessageBar, parent );
return new QgsRelationReferenceWidgetWrapper( vl, fieldIdx, editor, mCanvas, mMessageBar, parent );
}

QgsEditorConfigWidget* QgsRelationReferenceFactory::configWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const
Expand Down
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/qgsrelationreferencefactory.h
Expand Up @@ -25,7 +25,7 @@ class QgsMessageBar;
class GUI_EXPORT QgsRelationReferenceFactory : public QgsEditorWidgetFactory
{
public:
QgsRelationReferenceFactory( QString name, QgsAttributeEditorContext context, QgsMapCanvas* canvas, QgsMessageBar* messageBar );
QgsRelationReferenceFactory( QString name, QgsMapCanvas* canvas, QgsMessageBar* messageBar );

/**
* Override this in your implementation.
Expand Down

0 comments on commit b1a2bef

Please sign in to comment.