Skip to content
Permalink
Browse files

[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
  • Loading branch information
m-kuhn committed Sep 1, 2014
1 parent 016e1d7 commit b1a2bef1fc9e1b2b323855aa252338d0ed2912f9
@@ -24,5 +24,5 @@ class QgsAttributeEditorContext
*
* @param layer The layer to adjust for.
*/
void adjustForLayer( QgsVectorLayer* layer );
// void adjustForLayer( QgsVectorLayer* layer );
};
@@ -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;


/**
@@ -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.
@@ -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;

};
@@ -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" ) ) );
@@ -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
@@ -935,6 +933,8 @@ QgisApp::~QgisApp()

delete mComposerManager;

delete mVectorLayerTools;

deletePrintComposers();
removeAnnotationItems();

@@ -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;
}

@@ -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 )
{
@@ -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;

@@ -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" ) );
@@ -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
@@ -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.
@@ -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
@@ -116,7 +116,6 @@ qgisinterface.cpp
qgsannotationitem.cpp
qgsattributedialog.cpp
qgsattributeeditor.cpp
qgsattributeeditorcontext.cpp
qgsattributeform.cpp
qgsattributeforminterface.cpp
qgsattributeformlegacyinterface.cpp
@@ -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 );
@@ -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>();
}
@@ -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" );
}
}

@@ -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 );
}
}

@@ -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;
}
@@ -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.
@@ -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
@@ -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.

0 comments on commit b1a2bef

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