summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Stanciu <[email protected]>2015-04-11 14:11:20 +0200
committerTorsten Rahn <[email protected]>2015-04-11 14:12:36 +0200
commit37aa24b06758ea6de76d4c60dbe6f58c1b43170b (patch)
treef0aaad64df090f95a45a92ea3fadc9dbde1dbb0e
parent116483e4604826d762a5692c89741f7335e53169 (diff)
Extends the precision node editor (the one from previous patch, for polygons) to polylines
REVIEW: 123141
-rw-r--r--src/plugins/render/annotate/EditPolygonDialog.cpp7
-rw-r--r--src/plugins/render/annotate/EditPolylineDialog.cpp23
-rw-r--r--src/plugins/render/annotate/NodeItemDelegate.cpp89
-rw-r--r--src/plugins/render/annotate/NodeItemDelegate.h12
4 files changed, 101 insertions, 30 deletions
diff --git a/src/plugins/render/annotate/EditPolygonDialog.cpp b/src/plugins/render/annotate/EditPolygonDialog.cpp
index 783c154..f5a7667 100644
--- a/src/plugins/render/annotate/EditPolygonDialog.cpp
+++ b/src/plugins/render/annotate/EditPolygonDialog.cpp
@@ -133,7 +133,12 @@ EditPolygonDialog::EditPolygonDialog( GeoDataPlacemark *placemark, QWidget *pare
connect( d->m_polyDialog, SIGNAL(colorSelected(QColor)), this, SLOT(updatePolygon()) );
// Setting the NodeView's delegate: mainly used for the editing the polygon's nodes
- d->m_delegate = new NodeItemDelegate( d->m_placemark, this, d->m_nodeView );
+ d->m_delegate = new NodeItemDelegate( d->m_placemark, d->m_nodeView );
+
+ connect( d->m_delegate, SIGNAL( modelChanged( GeoDataPlacemark* ) ),
+ this, SLOT( handleItemMoving( GeoDataPlacemark* ) ) );
+ connect( d->m_delegate, SIGNAL( geometryChanged() ),
+ this, SLOT( updatePolygon() ) );
d->m_nodeView->setItemDelegate( d->m_delegate );
d->m_nodeView->setEditTriggers( QAbstractItemView::AllEditTriggers );
diff --git a/src/plugins/render/annotate/EditPolylineDialog.cpp b/src/plugins/render/annotate/EditPolylineDialog.cpp
index e7b399d..9020db4 100644
--- a/src/plugins/render/annotate/EditPolylineDialog.cpp
+++ b/src/plugins/render/annotate/EditPolylineDialog.cpp
@@ -23,6 +23,7 @@
#include "GeoDataTypes.h"
#include "NodeModel.h"
#include "FormattedTextWidget.h"
+#include "NodeItemDelegate.h"
namespace Marble
@@ -42,7 +43,9 @@ public:
QString m_initialDescription;
GeoDataLineStyle m_initialLineStyle;
FormattedTextWidget *m_formattedTextWidget;
+ GeoDataLineString m_initialLineString;
+ NodeItemDelegate *m_delegate;
NodeModel *m_nodeModel;
};
@@ -59,6 +62,7 @@ EditPolylineDialog::Private::~Private()
{
delete m_linesDialog;
delete m_nodeModel;
+ delete m_delegate;
}
EditPolylineDialog::EditPolylineDialog( GeoDataPlacemark *placemark, QWidget *parent ) :
@@ -78,7 +82,7 @@ EditPolylineDialog::EditPolylineDialog( GeoDataPlacemark *placemark, QWidget *pa
d->m_placemark->setName( tr("Untitled Path") );
}
-
+ d->m_initialLineString = *(static_cast<GeoDataLineString*>( placemark->geometry() ) );
d->m_name->setText( placemark->name() );
d->m_initialName = d->m_name->text();
connect( d->m_name, SIGNAL(editingFinished()), this, SLOT(updatePolyline()) );
@@ -102,6 +106,17 @@ EditPolylineDialog::EditPolylineDialog( GeoDataPlacemark *placemark, QWidget *pa
linesPixmap.fill( lineStyle.color() );
d->m_linesColorButton->setIcon( QIcon( linesPixmap ) );
+ // Setting the NodeView's delegate: mainly used for the editing the polyline's nodes
+ d->m_delegate = new NodeItemDelegate( d->m_placemark, d->m_nodeView );
+
+ connect( d->m_delegate, SIGNAL( modelChanged( GeoDataPlacemark* ) ),
+ this, SLOT( handleItemMoving( GeoDataPlacemark* ) ) );
+ connect( d->m_delegate, SIGNAL( geometryChanged() ),
+ this, SLOT( updatePolyline() ) );
+
+ d->m_nodeView->setItemDelegate( d->m_delegate );
+ d->m_nodeView->setEditTriggers( QAbstractItemView::AllEditTriggers );
+
// Setup the color dialogs.
d->m_linesDialog = new QColorDialog( this );
d->m_linesDialog->setOption( QColorDialog::ShowAlphaChannel );
@@ -184,6 +199,12 @@ void EditPolylineDialog::restoreInitial( int result )
return;
}
+ GeoDataLineString* currentLineString = static_cast<GeoDataLineString*>( d->m_placemark->geometry() );
+
+ if( *currentLineString != d->m_initialLineString ) {
+ d->m_placemark->setGeometry( new GeoDataLineString( d->m_initialLineString ) );
+ }
+
if ( d->m_placemark->name() != d->m_initialName ) {
d->m_placemark->setName( d->m_initialName );
}
diff --git a/src/plugins/render/annotate/NodeItemDelegate.cpp b/src/plugins/render/annotate/NodeItemDelegate.cpp
index bed78aa..a937c9f 100644
--- a/src/plugins/render/annotate/NodeItemDelegate.cpp
+++ b/src/plugins/render/annotate/NodeItemDelegate.cpp
@@ -17,6 +17,8 @@
// Marble
#include "LatLonEdit.h"
+#include "GeoDataTypes.h"
+#include "GeoDataLineString.h"
namespace Marble
{
@@ -28,8 +30,8 @@ QSize NodeItemDelegate::sizeHint( const QStyleOptionViewItem &option, const QMod
return QSize( 25, 25 );
}
-NodeItemDelegate::NodeItemDelegate( GeoDataPlacemark* placemark, EditPolygonDialog* dialog, QTreeView* view ):
- m_placemark( placemark ), m_dialog( dialog ), m_view( view )
+NodeItemDelegate::NodeItemDelegate( GeoDataPlacemark* placemark, QTreeView* view ):
+ m_placemark( placemark ), m_view( view )
{
}
@@ -45,20 +47,39 @@ QWidget* NodeItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewI
void NodeItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
+
LatLonEdit *latLonEditWidget = static_cast<LatLonEdit*>(editor);
+ qreal value = 0;
+
+ if( m_placemark->geometry()->nodeType() == GeoDataTypes::GeoDataPolygonType ) {
+
+ GeoDataPolygon *polygon = static_cast<GeoDataPolygon*>( m_placemark->geometry() );
- GeoDataPolygon *polygon = static_cast<GeoDataPolygon*>( m_placemark->geometry() );
- GeoDataLinearRing outerBoundary = polygon->outerBoundary();
- qreal value;
+ GeoDataLinearRing outerBoundary = polygon->outerBoundary();
- // Setting the latlonedit spinboxes values
- if( index.column() == 1 ) {
- latLonEditWidget->setDimension( Marble::Latitude );
- value = outerBoundary.at( index.row() ).longitude( GeoDataCoordinates::Degree );
+ // Setting the latlonedit spinboxes values
+ if( index.column() == 1 ) {
+ latLonEditWidget->setDimension( Marble::Longitude );
+ value = outerBoundary.at( index.row() ).longitude( GeoDataCoordinates::Degree );
+ }
+ else {
+ latLonEditWidget->setDimension( Marble::Latitude );
+ value = outerBoundary.at( index.row() ).latitude( GeoDataCoordinates::Degree );
+ }
}
- else {
- latLonEditWidget->setDimension( Marble::Longitude );
- value = outerBoundary.at( index.row() ).latitude(GeoDataCoordinates::Degree );
+ else if ( m_placemark->geometry()->nodeType() == GeoDataTypes::GeoDataLineStringType ) {
+
+ GeoDataLineString *lineString = static_cast<GeoDataLineString*>( m_placemark->geometry() );
+
+ // Setting the latlonedit spinboxes values
+ if( index.column() == 1 ) {
+ latLonEditWidget->setDimension( Marble::Longitude );
+ value = lineString->at( index.row() ).longitude( GeoDataCoordinates::Degree );
+ }
+ else {
+ latLonEditWidget->setDimension( Marble::Latitude );
+ value = lineString->at( index.row() ).latitude(GeoDataCoordinates::Degree );
+ }
}
latLonEditWidget->setValue( value );
@@ -74,31 +95,47 @@ void NodeItemDelegate::setModelData( QWidget* editor, QAbstractItemModel *model,
Q_UNUSED( editor );
Q_UNUSED( model );
Q_UNUSED( index );
- // The EditPolygonDialog already has a function that updates the NodeModel
- m_dialog->handleItemMoving( m_placemark );
+
+ // The dialogs already have a function that updates the NodeModel
+ emit modelChanged( m_placemark );
}
void NodeItemDelegate::previewNodeMove( qreal value )
{
+ if( m_placemark->geometry()->nodeType() == GeoDataTypes::GeoDataPolygonType ) {
+ GeoDataPolygon *polygon = static_cast<GeoDataPolygon*>( m_placemark->geometry() );
+ GeoDataLinearRing outerBoundary = polygon->outerBoundary();
- GeoDataPolygon *polygon = static_cast<GeoDataPolygon*>( m_placemark->geometry() );
- GeoDataLinearRing outerBoundary = polygon->outerBoundary();
+ GeoDataCoordinates* coordinates = new GeoDataCoordinates( outerBoundary[m_indexBeingEdited.row()] );
- GeoDataCoordinates* coordinates = new GeoDataCoordinates( outerBoundary[m_indexBeingEdited.row()] );
+ if( m_indexBeingEdited.column() == 1) {
+ coordinates->setLongitude( value, GeoDataCoordinates::Degree );
+ }
+ else {
+ coordinates->setLatitude( value, GeoDataCoordinates::Degree );
+ }
- if( m_indexBeingEdited.column() == 1) {
- coordinates->setLongitude( value, GeoDataCoordinates::Degree );
- }
- else {
- coordinates->setLatitude( value, GeoDataCoordinates::Degree );
+ outerBoundary[ m_indexBeingEdited.row() ] = *coordinates;
+ polygon->setOuterBoundary( outerBoundary );
}
+ else if ( m_placemark->geometry()->nodeType() == GeoDataTypes::GeoDataLineStringType ) {
- outerBoundary[ m_indexBeingEdited.row() ] = *coordinates;
- polygon->setOuterBoundary( outerBoundary );
+ GeoDataLineString *lineString = static_cast<GeoDataLineString*>( m_placemark->geometry() );
+ GeoDataCoordinates* coordinates = new GeoDataCoordinates( lineString->at( m_indexBeingEdited.row() ) );
- // Updating chagnes ( repainting graphics )
+ if( m_indexBeingEdited.column() == 1) {
+ coordinates->setLongitude( value, GeoDataCoordinates::Degree );
+ }
+ else {
+ coordinates->setLatitude( value, GeoDataCoordinates::Degree );
+ }
+
+ lineString->at( m_indexBeingEdited.row() ) = *coordinates;
- m_dialog->updatePolygon();
+ }
+
+ // Updating chagnes ( repainting graphics )
+ emit geometryChanged();
}
void NodeItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
diff --git a/src/plugins/render/annotate/NodeItemDelegate.h b/src/plugins/render/annotate/NodeItemDelegate.h
index aaa8084..55c74c0 100644
--- a/src/plugins/render/annotate/NodeItemDelegate.h
+++ b/src/plugins/render/annotate/NodeItemDelegate.h
@@ -22,13 +22,18 @@
namespace Marble
{
+/**
+ * @brief The NodeItemDelegate class handles the NodeModel view for both the EditPolygonDialog
+ * and EditPolylineDialog. It manages editing and updating the NodeModel and triggers drawing
+ * updates when changes are made.
+ */
class NodeItemDelegate : public QItemDelegate
{
Q_OBJECT
public:
- NodeItemDelegate( GeoDataPlacemark* placemark, EditPolygonDialog* dialog, QTreeView* view );
+ NodeItemDelegate( GeoDataPlacemark* placemark, QTreeView* view );
QSize sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const;
QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
@@ -38,13 +43,16 @@ public:
private:
GeoDataPlacemark* m_placemark;
- EditPolygonDialog* m_dialog;
mutable QModelIndex m_indexBeingEdited;
QTreeView* m_view;
private slots:
void previewNodeMove( qreal value);
void unsetCurrentEditor( QWidget* widget );
+
+signals:
+ void modelChanged( GeoDataPlacemark* placemark ) const;
+ void geometryChanged() const;
};
}