Skip to content

Commit

Permalink
use bool variables instead of connecting/disconnecting signals
Browse files Browse the repository at this point in the history
also move simple QgsVertexEntry to qgsvertexeditor.h
  • Loading branch information
3nids committed Feb 25, 2019
1 parent 643a763 commit 3e7d781
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 103 deletions.
1 change: 0 additions & 1 deletion src/app/CMakeLists.txt
Expand Up @@ -126,7 +126,6 @@ SET(QGIS_APP_SRCS
decorations/qgsdecorationgriddialog.cpp

vertextool/qgslockedfeature.cpp
vertextool/qgsvertexentry.cpp
vertextool/qgsvertexeditor.cpp
vertextool/qgsvertextool.cpp

Expand Down
4 changes: 2 additions & 2 deletions src/app/vertextool/qgslockedfeature.h
Expand Up @@ -16,11 +16,11 @@
#ifndef QGSLOCKEDFEATURE_H
#define QGSLOCKEDFEATURE_H

#include <QObject>

#include "qgsgeometry.h"
#include "qgsfeatureid.h"

#include <QObject>

class QgsMapCanvas;
class QgsVectorLayer;
class QgsMapLayer;
Expand Down
13 changes: 4 additions & 9 deletions src/app/vertextool/qgsvertexeditor.cpp
Expand Up @@ -20,7 +20,6 @@
#include "qgsmapcanvas.h"
#include "qgsmessagelog.h"
#include "qgslockedfeature.h"
#include "qgsvertexentry.h"
#include "qgsvectorlayer.h"
#include "qgsgeometryutils.h"
#include "qgsproject.h"
Expand Down Expand Up @@ -379,7 +378,7 @@ void QgsVertexEditor::updateEditor( QgsLockedFeature *lockedFeature )

void QgsVertexEditor::updateTableSelection()
{
if ( !mLockedFeature || mUpdatingVertexSelection )
if ( !mLockedFeature || mUpdatingVertexSelection || mUpdatingTableSelection )
return;

mUpdatingTableSelection = true;
Expand All @@ -395,11 +394,7 @@ void QgsVertexEditor::updateTableSelection()
selection.select( mVertexModel->index( i, 0 ), mVertexModel->index( i, mVertexModel->columnCount() - 1 ) );
}
}
disconnect( mLockedFeature, &QgsLockedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection );
disconnect( mTableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &QgsVertexEditor::updateVertexSelection );
mTableView->selectionModel()->select( selection, QItemSelectionModel::ClearAndSelect );
connect( mLockedFeature, &QgsLockedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection );
connect( mTableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &QgsVertexEditor::updateVertexSelection );

if ( firstSelectedRow >= 0 )
mTableView->scrollTo( mVertexModel->index( firstSelectedRow, 0 ), QAbstractItemView::PositionAtTop );
Expand All @@ -409,11 +404,10 @@ void QgsVertexEditor::updateTableSelection()

void QgsVertexEditor::updateVertexSelection( const QItemSelection &, const QItemSelection & )
{
if ( !mLockedFeature || mUpdatingTableSelection )
if ( !mLockedFeature || mUpdatingVertexSelection || mUpdatingTableSelection )
return;

mUpdatingVertexSelection = true;
disconnect( mLockedFeature, &QgsLockedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection );

mLockedFeature->deselectAllVertices();

Expand Down Expand Up @@ -450,7 +444,6 @@ void QgsVertexEditor::updateVertexSelection( const QItemSelection &, const QItem
}

mUpdatingVertexSelection = false;
connect( mLockedFeature, &QgsLockedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection );
}

void QgsVertexEditor::keyPressEvent( QKeyEvent *e )
Expand Down Expand Up @@ -504,3 +497,5 @@ void CoordinateItemDelegate::setModelData( QWidget *editor, QAbstractItemModel *
QStyledItemDelegate::setModelData( editor, model, index );
}
}


41 changes: 35 additions & 6 deletions src/app/vertextool/qgsvertexeditor.h
Expand Up @@ -19,19 +19,48 @@
#ifndef QGSVERTEXEDITOR_H
#define QGSVERTEXEDITOR_H

#include "qgsdockwidget.h"
#include <QAbstractTableModel>
#include <QItemSelection>
#include <QStyledItemDelegate>

#include "qgis_app.h"
#include "qgsdockwidget.h"
#include "qgspoint.h"

class QLabel;
class QTableView;

class QgsMapCanvas;
class QgsLockedFeature;
class QgsVectorLayer;

class QLabel;
class QTableView;

class QgsVertexEditorModel : public QAbstractTableModel
class APP_EXPORT QgsVertexEntry
{
public:
QgsVertexEntry( const QgsPoint &p,
QgsVertexId vertexId )
: mSelected( false )
, mPoint( p )
, mVertexId( vertexId )
{
}

QgsVertexEntry( const QgsVertexEntry &rh ) = delete;
QgsVertexEntry &operator=( const QgsVertexEntry &rh ) = delete;

const QgsPoint &point() const { return mPoint; }
QgsVertexId vertexId() const { return mVertexId; }
bool isSelected() const { return mSelected; }
void setSelected( bool selected ) { mSelected = selected; }

private:
bool mSelected;
QgsPoint mPoint;
QgsVertexId mVertexId;
};

class APP_EXPORT QgsVertexEditorModel : public QAbstractTableModel
{
Q_OBJECT
public:
Expand Down Expand Up @@ -65,7 +94,7 @@ class QgsVertexEditorModel : public QAbstractTableModel

};

class QgsVertexEditor : public QgsDockWidget
class APP_EXPORT QgsVertexEditor : public QgsDockWidget
{
Q_OBJECT
public:
Expand Down Expand Up @@ -98,7 +127,7 @@ class QgsVertexEditor : public QgsDockWidget
};


class CoordinateItemDelegate : public QStyledItemDelegate
class APP_EXPORT CoordinateItemDelegate : public QStyledItemDelegate
{
Q_OBJECT

Expand Down
37 changes: 0 additions & 37 deletions src/app/vertextool/qgsvertexentry.cpp

This file was deleted.

47 changes: 0 additions & 47 deletions src/app/vertextool/qgsvertexentry.h

This file was deleted.

1 change: 0 additions & 1 deletion src/app/vertextool/qgsvertextool.cpp
Expand Up @@ -37,7 +37,6 @@
#include "qgisapp.h"
#include "qgslockedfeature.h"
#include "qgsvertexeditor.h"
#include "qgsvertexentry.h"
#include "qgsmapmouseevent.h"

#include <QMenu>
Expand Down

0 comments on commit 3e7d781

Please sign in to comment.