summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Stanciu <[email protected]>2015-03-23 23:41:57 +0200
committerMarius Stanciu <[email protected]>2015-03-23 23:41:57 +0200
commit995c2f88fce40e72af0dc572cb6f95de0f861ed3 (patch)
tree6cf7895ff3d8a13a5b602f1f6c9ec8cdf2041135
parent3e8e9c027dfec7b292b390110ee960478b5686e5 (diff)
Adds the possibility to precisely move polygon nodes
REVIEW: 122938
-rw-r--r--src/lib/marble/EditPlacemarkDialog.h2
-rw-r--r--src/plugins/render/annotate/CMakeLists.txt1
-rw-r--r--src/plugins/render/annotate/EditPolygonDialog.cpp23
-rw-r--r--src/plugins/render/annotate/EditPolygonDialog.h2
-rw-r--r--src/plugins/render/annotate/EditPolygonDialog.ui5
-rw-r--r--src/plugins/render/annotate/NodeItemDelegate.cpp138
-rw-r--r--src/plugins/render/annotate/NodeItemDelegate.h51
-rw-r--r--src/plugins/render/annotate/NodeModel.cpp9
-rw-r--r--src/plugins/render/annotate/NodeModel.h1
9 files changed, 223 insertions, 9 deletions
diff --git a/src/lib/marble/EditPlacemarkDialog.h b/src/lib/marble/EditPlacemarkDialog.h
index 24a5610..015173c 100644
--- a/src/lib/marble/EditPlacemarkDialog.h
+++ b/src/lib/marble/EditPlacemarkDialog.h
@@ -15,13 +15,11 @@
#include <QDialog>
-
namespace Marble {
class GeoDataFeature;
class GeoDataPlacemark;
-
/**
* @brief The EditPlacemarkDialog class deals with customizing placemarks.
*/
diff --git a/src/plugins/render/annotate/CMakeLists.txt b/src/plugins/render/annotate/CMakeLists.txt
index 594ea89..9ce5ffe 100644
--- a/src/plugins/render/annotate/CMakeLists.txt
+++ b/src/plugins/render/annotate/CMakeLists.txt
@@ -22,6 +22,7 @@ set( annotate_SRCS
AreaAnnotation.cpp
EditGroundOverlayDialog.cpp
EditPolygonDialog.cpp
+ NodeItemDelegate.cpp
EditPolylineDialog.cpp
GroundOverlayFrame.cpp
MergingPolygonNodesAnimation.cpp
diff --git a/src/plugins/render/annotate/EditPolygonDialog.cpp b/src/plugins/render/annotate/EditPolygonDialog.cpp
index 8c8b302..c647e6b 100644
--- a/src/plugins/render/annotate/EditPolygonDialog.cpp
+++ b/src/plugins/render/annotate/EditPolygonDialog.cpp
@@ -20,7 +20,7 @@
#include "GeoDataStyle.h"
#include "GeoDataTypes.h"
#include "NodeModel.h"
-
+#include "NodeItemDelegate.h"
namespace Marble {
@@ -38,8 +38,10 @@ public:
QString m_initialDescription;
QString m_initialName;
GeoDataStyle m_initialStyle;
+ GeoDataLinearRing m_initialOuterBoundary;
NodeModel *m_nodeModel;
+ NodeItemDelegate *m_delegate;
};
EditPolygonDialog::Private::Private( GeoDataPlacemark *placemark ) :
@@ -57,6 +59,7 @@ EditPolygonDialog::Private::~Private()
delete m_linesDialog;
delete m_polyDialog;
delete m_nodeModel;
+ delete m_delegate;
}
EditPolygonDialog::EditPolygonDialog( GeoDataPlacemark *placemark, QWidget *parent ) :
@@ -120,13 +123,22 @@ EditPolygonDialog::EditPolygonDialog( GeoDataPlacemark *placemark, QWidget *pare
connect( d->m_polyDialog, SIGNAL(colorSelected(QColor)), this, SLOT(updatePolyDialog(const QColor&)) );
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_nodeView->setItemDelegate( d->m_delegate );
+ d->m_nodeView->setEditTriggers( QAbstractItemView::AllEditTriggers );
+
+ // Populating the model
if( placemark->geometry()->nodeType() == GeoDataTypes::GeoDataPolygonType ) {
GeoDataPolygon *polygon = static_cast<GeoDataPolygon*>( placemark->geometry() );
GeoDataLinearRing outerBoundary = polygon->outerBoundary();
for( int i = 0; i < outerBoundary.size(); ++i ) {
d->m_nodeModel->addNode( outerBoundary.at( i ) );
}
+ d->m_initialOuterBoundary = outerBoundary;
}
+
d->m_nodeView->setModel( d->m_nodeModel );
// Resize column to contents size for better UI.
@@ -237,6 +249,13 @@ void EditPolygonDialog::restoreInitial( int result )
return;
}
+ GeoDataPolygon *polygon = static_cast<GeoDataPolygon*>( d->m_placemark->geometry() );
+ GeoDataLinearRing outerBoundary = polygon->outerBoundary();
+
+ if ( outerBoundary != d->m_initialOuterBoundary ) {
+ polygon->setOuterBoundary( d->m_initialOuterBoundary );
+ }
+
if ( d->m_placemark->name() != d->m_initialName ) {
d->m_placemark->setName( d->m_initialName );
}
@@ -248,10 +267,8 @@ void EditPolygonDialog::restoreInitial( int result )
if ( *d->m_placemark->style() != d->m_initialStyle ) {
d->m_placemark->setStyle( new GeoDataStyle( d->m_initialStyle ) );
}
-
emit polygonUpdated( d->m_placemark );
}
}
-
#include "EditPolygonDialog.moc"
diff --git a/src/plugins/render/annotate/EditPolygonDialog.h b/src/plugins/render/annotate/EditPolygonDialog.h
index 6f07648..0dbb089 100644
--- a/src/plugins/render/annotate/EditPolygonDialog.h
+++ b/src/plugins/render/annotate/EditPolygonDialog.h
@@ -36,12 +36,12 @@ public:
public slots:
void handleAddingNode( const GeoDataCoordinates &node );
void handleItemMoving( GeoDataPlacemark *item );
+ void updatePolygon();
signals:
void polygonUpdated( GeoDataFeature *feature );
private slots:
- void updatePolygon();
void updateLinesDialog( const QColor &color );
void updatePolyDialog( const QColor &color );
void checkFields();
diff --git a/src/plugins/render/annotate/EditPolygonDialog.ui b/src/plugins/render/annotate/EditPolygonDialog.ui
index 0bfa86e..563ca2d 100644
--- a/src/plugins/render/annotate/EditPolygonDialog.ui
+++ b/src/plugins/render/annotate/EditPolygonDialog.ui
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>350</width>
+ <width>403</width>
<height>390</height>
</rect>
</property>
@@ -38,7 +38,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
- <number>1</number>
+ <number>2</number>
</property>
<widget class="QWidget" name="m_descriptionTab">
<attribute name="title">
@@ -230,7 +230,6 @@
<zorder>m_filledColor</zorder>
<zorder>label_7</zorder>
<zorder>m_polyColorButton</zorder>
- <zorder>horizontalSpacer</zorder>
</widget>
</item>
<item>
diff --git a/src/plugins/render/annotate/NodeItemDelegate.cpp b/src/plugins/render/annotate/NodeItemDelegate.cpp
new file mode 100644
index 0000000..bed78aa
--- /dev/null
+++ b/src/plugins/render/annotate/NodeItemDelegate.cpp
@@ -0,0 +1,138 @@
+//
+// This file is part of the Marble Virtual Globe.
+//
+// This program is free software licensed under the GNU LGPL. You can
+// find a copy of this license in LICENSE.txt in the top directory of
+// the source code.
+//
+// Copyright 2015 Stanciu Marius-Valeriu <[email protected]>
+//
+
+// Self
+#include "NodeItemDelegate.h"
+
+// Qt
+#include <QSize>
+#include <QStyleOptionViewItem>
+
+// Marble
+#include "LatLonEdit.h"
+
+namespace Marble
+{
+
+QSize NodeItemDelegate::sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const
+{
+ Q_UNUSED( option );
+ Q_UNUSED( index );
+ return QSize( 25, 25 );
+}
+
+NodeItemDelegate::NodeItemDelegate( GeoDataPlacemark* placemark, EditPolygonDialog* dialog, QTreeView* view ):
+ m_placemark( placemark ), m_dialog( dialog ), m_view( view )
+{
+}
+
+QWidget* NodeItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const
+{
+ Q_UNUSED( option );
+ Q_UNUSED( index );
+ LatLonEdit *editor = new LatLonEdit( parent );
+ connect( this, SIGNAL( closeEditor( QWidget* ) ),
+ this, SLOT( unsetCurrentEditor(QWidget*) ) );
+ return editor;
+}
+
+void NodeItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
+{
+ LatLonEdit *latLonEditWidget = static_cast<LatLonEdit*>(editor);
+
+ GeoDataPolygon *polygon = static_cast<GeoDataPolygon*>( m_placemark->geometry() );
+ GeoDataLinearRing outerBoundary = polygon->outerBoundary();
+ qreal value;
+
+ // Setting the latlonedit spinboxes values
+ if( index.column() == 1 ) {
+ latLonEditWidget->setDimension( Marble::Latitude );
+ value = outerBoundary.at( index.row() ).longitude( GeoDataCoordinates::Degree );
+ }
+ else {
+ latLonEditWidget->setDimension( Marble::Longitude );
+ value = outerBoundary.at( index.row() ).latitude(GeoDataCoordinates::Degree );
+ }
+
+ latLonEditWidget->setValue( value );
+
+ connect( latLonEditWidget, SIGNAL( valueChanged( qreal ) ),
+ this, SLOT( previewNodeMove( qreal ) ) );
+ m_indexBeingEdited = index;
+
+}
+
+void NodeItemDelegate::setModelData( QWidget* editor, QAbstractItemModel *model, const QModelIndex &index ) const
+{
+ Q_UNUSED( editor );
+ Q_UNUSED( model );
+ Q_UNUSED( index );
+ // The EditPolygonDialog already has a function that updates the NodeModel
+ m_dialog->handleItemMoving( m_placemark );
+}
+
+void NodeItemDelegate::previewNodeMove( qreal value )
+{
+
+ GeoDataPolygon *polygon = static_cast<GeoDataPolygon*>( m_placemark->geometry() );
+ GeoDataLinearRing outerBoundary = polygon->outerBoundary();
+
+ GeoDataCoordinates* coordinates = new GeoDataCoordinates( outerBoundary[m_indexBeingEdited.row()] );
+
+ if( m_indexBeingEdited.column() == 1) {
+ coordinates->setLongitude( value, GeoDataCoordinates::Degree );
+ }
+ else {
+ coordinates->setLatitude( value, GeoDataCoordinates::Degree );
+ }
+
+ outerBoundary[ m_indexBeingEdited.row() ] = *coordinates;
+ polygon->setOuterBoundary( outerBoundary );
+
+ // Updating chagnes ( repainting graphics )
+
+ m_dialog->updatePolygon();
+}
+
+void NodeItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+ if( index.column() == 1) {
+ m_view->setColumnWidth( 1, 200 );
+ m_view->setColumnWidth( 2, 100 );
+ }
+ else {
+ m_view->setColumnWidth( 2, 200 );
+ m_view->setColumnWidth( 1, 100 );
+ }
+
+ editor->setGeometry( option.rect );
+}
+
+void NodeItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+ drawBackground( painter, option, index );
+
+ // The LatLonEdit widget is transparent, so we have to disable the text behind it
+ // for esthetic reasons.
+ if ( !( index == m_indexBeingEdited ) || !( index == m_view->currentIndex() ) ) {
+ drawDisplay( painter, option, option.rect, index.data().toString() );
+ }
+}
+
+void NodeItemDelegate::unsetCurrentEditor(QWidget* widget)
+{
+ Q_UNUSED( widget );
+ m_indexBeingEdited = QModelIndex();
+ m_view->viewport()->update();
+}
+
+}
+
+#include "NodeItemDelegate.moc"
diff --git a/src/plugins/render/annotate/NodeItemDelegate.h b/src/plugins/render/annotate/NodeItemDelegate.h
new file mode 100644
index 0000000..aaa8084
--- /dev/null
+++ b/src/plugins/render/annotate/NodeItemDelegate.h
@@ -0,0 +1,51 @@
+//
+// This file is part of the Marble Virtual Globe.
+//
+// This program is free software licensed under the GNU LGPL. You can
+// find a copy of this license in LICENSE.txt in the top directory of
+// the source code.
+//
+// Copyright 2015 Stanciu Marius-Valeriu <[email protected]>
+//
+
+#ifndef NODEITEMDELEGATE_H
+#define NODEITEMDELEGATE_H
+
+// Qt
+#include <QItemDelegate>
+#include <QTreeView>
+
+// Marble
+#include "GeoDataPlacemark.h"
+#include "EditPolygonDialog.h"
+
+namespace Marble
+{
+
+class NodeItemDelegate : public QItemDelegate
+{
+
+Q_OBJECT
+
+public:
+ NodeItemDelegate( GeoDataPlacemark* placemark, EditPolygonDialog* dialog, 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;
+ void setEditorData(QWidget *editor, const QModelIndex &index) const;
+ void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
+ void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
+
+private:
+ GeoDataPlacemark* m_placemark;
+ EditPolygonDialog* m_dialog;
+ mutable QModelIndex m_indexBeingEdited;
+ QTreeView* m_view;
+
+private slots:
+ void previewNodeMove( qreal value);
+ void unsetCurrentEditor( QWidget* widget );
+};
+
+}
+#endif
diff --git a/src/plugins/render/annotate/NodeModel.cpp b/src/plugins/render/annotate/NodeModel.cpp
index 984a2be..3e3be8f 100644
--- a/src/plugins/render/annotate/NodeModel.cpp
+++ b/src/plugins/render/annotate/NodeModel.cpp
@@ -112,6 +112,15 @@ int NodeModel::addNode( const GeoDataCoordinates &node )
return row;
}
+Qt::ItemFlags NodeModel::flags(const QModelIndex & index) const
+{
+ if ( index.column() == 1 || index.column() == 2 ) {
+ return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
+ }
+ else
+ return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
+}
+
}
#include "NodeModel.moc"
diff --git a/src/plugins/render/annotate/NodeModel.h b/src/plugins/render/annotate/NodeModel.h
index 4586eea..36fd631 100644
--- a/src/plugins/render/annotate/NodeModel.h
+++ b/src/plugins/render/annotate/NodeModel.h
@@ -28,6 +28,7 @@ public:
QVariant data( const QModelIndex &index, int role ) const;
QVariant headerData( int section, Qt::Orientation orientation, int role ) const;
void clear();
+ Qt::ItemFlags flags(const QModelIndex & index) const ;
public slots:
int addNode( const GeoDataCoordinates &node );
private: