[Uml-devel] [PATCH] Double-Click to remove nodes
Sebastian Stein
s5228 at informatik.htw-dresden.de
Thu Jul 18 00:25:02 UTC 2002
Hi,
I want to contribute a little patch. It is attached to this mail an you have
to copy it to uml/uml and than do
patch -p1 < double_click_patch.diff
But I think you know this by yourself.
What it does:
In the umlview it is possible to add another node to an association by
double click. This is cool, but not enough. With the patch you can remove
a node by double clicking on it again. You don't have to point exactly at
the point, there is an area where the action will perform:
-----------
|...........|
|...........|
|...........|
|...........|
|...........|
|...........|
|.....P.....|
|...........|
|...........|
|...........|
|...........|
|...........|
-----------
Both sides have a length of 5 pixels. But this can be changed.
I had to add a removePoint() function to class linepath and a isPoint()
function to class linepath.
I also added some lines to class associationwidget function
mouseDoubleClickEvent() to handle the different double clicks.
I hope you can include the diff, I think it is really a good feature.
Steinchen
--
http://www.hpfsc.de/ - die Seite rund um:
Assembler, Bundeswehr, TFT LCDs, Halle/Saale, Fahrradtouren,
Wanderstaat Mauma, Raumschiff USS Nathan, Enemy Room, MLCAD Tutorial
-------------- next part --------------
diff -u old/associationwidget.cpp new/associationwidget.cpp
--- old/associationwidget.cpp Wed Jul 17 23:56:37 2002
+++ new/associationwidget.cpp Wed Jul 17 23:39:54 2002
@@ -688,7 +688,15 @@
}
if(me->button() == LeftButton)
{
- m_pData -> m_LinePath.insertPoint( i, me -> pos() );
+ /* if there is no point around the mouse pointer, we insert a new one */
+ if (! m_pData -> m_LinePath.isPoint(i, me -> pos(), 5 ))
+ m_pData -> m_LinePath.insertPoint( i, me -> pos() );
+ else
+ /* there was a point so we remove the point */
+ m_pData -> m_LinePath.removePoint(i);
+
+ m_pData -> m_LinePath.update();
+
calculateRoleTextSegment();
}
}
diff -u old/linepath.cpp new/linepath.cpp
--- old/linepath.cpp Wed Jul 17 23:58:33 2002
+++ new/linepath.cpp Wed Jul 17 23:37:27 2002
@@ -89,6 +89,32 @@
return true;
}
+bool LinePath::isPoint( int pointIndex, QPoint point, unsigned short delta)
+{
+ /* onLinePath doesn't return the index number we mean */
+ pointIndex--;
+ int count = m_LineList.count();
+ if ( pointIndex >= count )
+ return false;
+
+ QCanvasLine * line = m_LineList.at( pointIndex );
+
+ /* check if the given point is the start or end point of the line */
+ if ( (
+ abs( line -> endPoint().x() - point.x() ) <= delta
+ &&
+ abs( line -> endPoint().y() - point.y() ) <= delta
+ ) || (
+ abs( line -> startPoint().x() - point.x() ) <= delta
+ &&
+ abs( line -> startPoint().y() - point.y() ) <= delta
+ ) )
+ return true;
+
+ /* check if the given point is the start or end point of the line */
+ return false;
+}
+
bool LinePath::insertPoint( int pointIndex, QPoint point )
{
int count = m_LineList.count();
@@ -136,6 +162,34 @@
line -> setVisible( true );
m_LineList.insert( pointIndex, line );
setupSelected();
+ return true;
+}
+
+bool LinePath::removePoint( int pointIndex )
+{
+ int count = m_LineList.count();
+
+ /* this may be thing what the user wants */
+ if (pointIndex == count)
+ pointIndex--;
+
+ /* check if the given index is valid, we do not allow to remove the points
+ * connected directly to the widgets */
+ if ( (pointIndex < 1) || (pointIndex > count) )
+ return false;
+
+ /* the next segment will get the starting point from the current one,
+ * which is going to be removed */
+ QCanvasLine * current = m_LineList.at( pointIndex );
+ QCanvasLine * before = m_LineList.at( pointIndex - 1 );
+ QPoint ep = current -> endPoint();
+ QPoint sp = before -> startPoint();
+ before -> setPoints( sp.x(), sp.y(), ep.x(), ep.y() );
+
+ /* remove the segment from the list */
+ m_LineList.remove( pointIndex );
+ count--;
+
return true;
}
diff -u old/linepath.h new/linepath.h
--- old/linepath.h Wed Jul 17 23:58:55 2002
+++ new/linepath.h Wed Jul 17 23:27:21 2002
@@ -66,9 +66,21 @@
bool setPoint( int pointIndex, QPoint point );
/**
+ * Checks, if we are at an end of the segment or somewhere in the middle.
+ * We use the delta, because with the mouse it is hard to find the
+ * exactly point.
+ */
+ bool isPoint( int pointIndex, QPoint point, unsigned short delta = 0 );
+
+ /**
* Inserts a point at the given index.
*/
bool insertPoint( int pointIndex, QPoint point );
+
+ /**
+ * Removes the point given by the index.
+ */
+ bool removePoint( int pointIndex );
/**
* Sets the start and end points.
More information about the umbrello-devel
mailing list