Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
QgsFixAttributeDialog seperated from QgsAttributeDialog to have the l…
…ist of features that are not stored yet there for fixing the attributes
  • Loading branch information
signedav committed Jan 9, 2020
1 parent c4dc133 commit f5e01d3
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 153 deletions.
14 changes: 1 addition & 13 deletions python/gui/auto_generated/qgsattributedialog.sip.in
Expand Up @@ -18,7 +18,7 @@ class QgsAttributeDialog : QDialog
%End
public:

QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeature, bool featureOwner, QWidget *parent /TransferThis/ = 0, bool showDialogButtons = true, const QgsAttributeEditorContext &context = QgsAttributeEditorContext(), bool showFixFeatureDialogButtons = false );
QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeature, bool featureOwner, QWidget *parent /TransferThis/ = 0, bool showDialogButtons = true, const QgsAttributeEditorContext &context = QgsAttributeEditorContext() );
%Docstring
Create an attribute dialog for a given layer and feature

Expand All @@ -28,16 +28,6 @@ Create an attribute dialog for a given layer and feature
:param parent: A parent widget for the dialog
:param showDialogButtons: ``True``: Show the dialog buttons accept/cancel
:param context: The context in which this dialog is created
%End

QgsAttributeDialog( QgsVectorLayer *vl, QgsFeatureList *features, QWidget *parent /TransferThis/ = 0, const QgsAttributeEditorContext &context = QgsAttributeEditorContext() );
%Docstring
Create an attribute dialog for a given layer and a feature list

:param vl: The layer for which the dialog will be generated
:param features: A list of features handled in the dialog
:param parent: A parent widget for the dialog
:param context: The context in which this dialog is created
%End

~QgsAttributeDialog();
Expand Down Expand Up @@ -85,8 +75,6 @@ Intercept window activate/deactivate events to show/hide the highlighted feature
:return: The same as the parent QDialog
%End

QgsFeatureList validFeatures();

public slots:
virtual void accept();

Expand Down
44 changes: 21 additions & 23 deletions src/app/qgisapp.cpp
Expand Up @@ -87,7 +87,7 @@
#include "qgssourceselectproviderregistry.h"
#include "qgssourceselectprovider.h"
#include "qgsprovidermetadata.h"
#include "qgsattributedialog.h"
#include "qgsfixattributedialog.h"

#include "qgsanalysis.h"
#include "qgsgeometrycheckregistry.h"
Expand Down Expand Up @@ -9593,8 +9593,6 @@ void QgisApp::pasteFromClipboard( QgsMapLayer *destinationLayer )
// check constraints
QgsFeatureList validFeatures = newFeatures;
QgsFeatureList invalidFeatures;
newFeatures.clear();

for ( const QgsFeature &f : qgis::as_const( validFeatures ) )
{
for ( int idx = 0; idx < pasteVectorLayer->fields().count(); ++idx )
Expand All @@ -9609,27 +9607,27 @@ void QgisApp::pasteFromClipboard( QgsMapLayer *destinationLayer )
}
}

// open attribute form to fix invalid features and offer the options:
// - fix part of invalid features and save (without the unfixed) -> on cancel invalid or all fixed
// - fix part of invalid features and save (with the unfixed as invalid) -> on store invalid
// - cancel everything
QgsAttributeDialog *dialog = new QgsAttributeDialog( pasteVectorLayer, &invalidFeatures, nullptr, QgsAttributeEditorContext() );
dialog->setMode( QgsAttributeEditorContext::AddFeatureMode );
int feedback = dialog->exec();

if ( feedback == 10 )
{
//cancel all
}
else if ( feedback == 11 )
{
//cancel all invalid
newFeatures << validFeatures << dialog->validFeatures();
}
else if ( feedback == 12 )
if ( !invalidFeatures.isEmpty() )
{
//store all invalid
newFeatures << validFeatures << invalidFeatures;
newFeatures.clear();

QgsFixAttributeDialog *dialog = new QgsFixAttributeDialog( pasteVectorLayer, invalidFeatures, this );
int feedback = dialog->exec();

if ( feedback == QgsFixAttributeDialog::VanishAll )
{
//vanish all
}
else if ( feedback == QgsFixAttributeDialog::CopyValid )
{
//copy valid and fixed, vanish unfixed
newFeatures << validFeatures << dialog->fixedFeatures();
}
else if ( feedback == QgsFixAttributeDialog::CopyAll )
{
//copy all, even unfixed
newFeatures << validFeatures << dialog->fixedFeatures() << dialog->unfixedFeatures();
}
}

pasteVectorLayer->addFeatures( newFeatures );
Expand Down
3 changes: 3 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -300,13 +300,15 @@ SET(QGIS_GUI_SRCS
qgsfeatureselectiondlg.cpp
qgsfieldcombobox.cpp
qgsfieldexpressionwidget.cpp
qgsfixattributedialog.cpp
qgsfeaturelistcombobox.cpp
qgsfieldvalidator.cpp
qgsfieldvalueslineedit.cpp
qgsfilecontentsourcelineedit.cpp
qgsfilewidget.cpp
qgsfilterlineedit.cpp
qgsfindfilesbypatternwidget.cpp
qgsfixattributedialog.cpp
qgsfloatingwidget.cpp
qgsfocuswatcher.cpp
qgsfontbutton.cpp
Expand Down Expand Up @@ -511,6 +513,7 @@ SET(QGIS_GUI_HDRS
qgsfilewidget.h
qgsfilterlineedit.h
qgsfindfilesbypatternwidget.h
qgsfixattributedialog.h
qgsfloatingwidget.h
qgsfocuswatcher.h
qgsfontbutton.h
Expand Down
100 changes: 1 addition & 99 deletions src/gui/qgsattributedialog.cpp
Expand Up @@ -22,22 +22,13 @@
#include "qgsapplication.h"
#include "qgssettings.h"

#include <QtWidgets/QProgressBar>
#include <QtWidgets/QPushButton>

QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeature, bool featureOwner, QWidget *parent, bool showDialogButtons, const QgsAttributeEditorContext &context, bool showFixFeatureDialogButtons )
QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeature, bool featureOwner, QWidget *parent, bool showDialogButtons, const QgsAttributeEditorContext &context )
: QDialog( parent )
, mOwnedFeature( featureOwner ? thepFeature : nullptr )
{
init( vl, thepFeature, context, showDialogButtons );
}

QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeatureList *features, QWidget *parent, const QgsAttributeEditorContext &context )
: QDialog( parent )
{
initList( vl, features, context );
}

QgsAttributeDialog::~QgsAttributeDialog()
{
if ( mHighlight )
Expand Down Expand Up @@ -125,95 +116,6 @@ void QgsAttributeDialog::init( QgsVectorLayer *layer, QgsFeature *feature, const
focusNextChild();
}

void QgsAttributeDialog::initList( QgsVectorLayer *layer, QgsFeatureList *features, const QgsAttributeEditorContext &context )
{

QgsAttributeEditorContext trackedContext = context;
setWindowTitle( tr( "%1 - Fix Feature Attributes" ).arg( layer->name() ) );
setLayout( new QGridLayout() );
layout()->setMargin( 0 );
mTrackedVectorLayerTools.setVectorLayerTools( trackedContext.vectorLayerTools() );
trackedContext.setVectorLayerTools( &mTrackedVectorLayerTools );
trackedContext.setFormMode( QgsAttributeEditorContext::StandaloneDialog );

mCurrentIndex = 0;
QLabel *description = new QLabel( tr( "%1 features do not fullfill the constraints. Please fix or cancel them." ).arg( features->count() ) );
layout()->addWidget( description );
QProgressBar *progressBar = new QProgressBar();
progressBar->setOrientation( Qt::Horizontal );
progressBar->setRange( 0, features->count() );

layout()->addWidget( progressBar );
mAttributeForm = new QgsAttributeForm( layer, features->at( mCurrentIndex ), trackedContext, this );
mAttributeForm->disconnectButtonBox();
layout()->addWidget( mAttributeForm );
QDialogButtonBox *buttonBox = mAttributeForm->findChild<QDialogButtonBox *>();

QPushButton *cancelAllBtn = new QPushButton( tr( "Cancel all" ) );
QPushButton *cancelAllInvalidBtn = new QPushButton( tr( "Cancel all invalid" ) );
QPushButton *storeAllInvalidBtn = new QPushButton( tr( "Store all (even invalid)" ) );
buttonBox->addButton( cancelAllBtn, QDialogButtonBox::RejectRole );
buttonBox->addButton( cancelAllInvalidBtn, QDialogButtonBox::RejectRole );
buttonBox->addButton( storeAllInvalidBtn, QDialogButtonBox::RejectRole );
connect( cancelAllBtn, &QAbstractButton::clicked, this, [ = ]()
{
done( 10 );
} );
connect( cancelAllInvalidBtn, &QAbstractButton::clicked, this, [ = ]()
{
done( 11 );
} );
connect( storeAllInvalidBtn, &QAbstractButton::clicked, this, [ = ]()
{
done( 12 );
} );
connect( buttonBox, &QDialogButtonBox::rejected, this, [ = ]()
{
//next feature
mCurrentIndex++;
progressBar->setValue( mCurrentIndex );
if ( mCurrentIndex < features->count() )
{
mAttributeForm->setFeature( features->at( mCurrentIndex ) );
}
else
{
done( 11 );
}
} );
connect( buttonBox, &QDialogButtonBox::accepted, this, [ = ]()
{
mAttributeForm->save();
QgsFeature feature;
feature.setAttributes( mAttributeForm->feature().attributes() );
mValidFeatures << feature;
//next feature
mCurrentIndex++;
progressBar->setValue( mCurrentIndex );
if ( mCurrentIndex < features->count() )
{
mAttributeForm->setFeature( features->at( mCurrentIndex ) );
}
else
{
done( 11 );
}
} );

connect( layer, &QObject::destroyed, this, &QWidget::close );

mMenu = new QgsActionMenu( layer, mAttributeForm->feature(), QStringLiteral( "Feature" ), this );
if ( !mMenu->actions().isEmpty() )
{
QMenuBar *menuBar = new QMenuBar( this );
menuBar->addMenu( mMenu );
layout()->setMenuBar( menuBar );
}

restoreGeometry();
focusNextChild();
}

void QgsAttributeDialog::setMode( QgsAttributeEditorContext::Mode mode )
{
mAttributeForm->setMode( mode );
Expand Down
19 changes: 1 addition & 18 deletions src/gui/qgsattributedialog.h
Expand Up @@ -51,18 +51,7 @@ class GUI_EXPORT QgsAttributeDialog : public QDialog
* \param context The context in which this dialog is created
*
*/
QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeature, bool featureOwner, QWidget *parent SIP_TRANSFERTHIS = nullptr, bool showDialogButtons = true, const QgsAttributeEditorContext &context = QgsAttributeEditorContext(), bool showFixFeatureDialogButtons = false );

/**
* Create an attribute dialog for a given layer and a feature list
*
* \param vl The layer for which the dialog will be generated
* \param features A list of features handled in the dialog
* \param parent A parent widget for the dialog
* \param context The context in which this dialog is created
*
*/
QgsAttributeDialog( QgsVectorLayer *vl, QgsFeatureList *features, QWidget *parent SIP_TRANSFERTHIS = nullptr, const QgsAttributeEditorContext &context = QgsAttributeEditorContext() );
QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeature, bool featureOwner, QWidget *parent SIP_TRANSFERTHIS = nullptr, bool showDialogButtons = true, const QgsAttributeEditorContext &context = QgsAttributeEditorContext() );

~QgsAttributeDialog() override;

Expand Down Expand Up @@ -106,8 +95,6 @@ class GUI_EXPORT QgsAttributeDialog : public QDialog
*/
bool event( QEvent *e ) override;

QgsFeatureList validFeatures() { return mValidFeatures; }

public slots:
void accept() override;
void reject() override;
Expand All @@ -117,7 +104,6 @@ class GUI_EXPORT QgsAttributeDialog : public QDialog

private:
void init( QgsVectorLayer *layer, QgsFeature *feature, const QgsAttributeEditorContext &context, bool showDialogButtons );
void initList( QgsVectorLayer *layer, QgsFeatureList *features, const QgsAttributeEditorContext &context );

QString mSettingsPath;
// Used to sync multiple widgets for the same field
Expand All @@ -135,9 +121,6 @@ class GUI_EXPORT QgsAttributeDialog : public QDialog

QgsActionMenu *mMenu;

int mCurrentIndex = 0;
QgsFeatureList mValidFeatures;

static int sFormCounter;

void saveGeometry();
Expand Down

0 comments on commit f5e01d3

Please sign in to comment.