[Uml-devel] Please review this patch

Sebastian Stein s5228 at informatik.htw-dresden.de
Tue Oct 15 13:43:02 UTC 2002


I'm working on feature request #622957:

"clicking delete/backspace key should delete objects if there is something
selected.  now it is only possible to delte by right clicking."

The attached patch should solve this problem.

I'm also working on feature request #616896:

"Most wanted:
[delete] in diasgram view delets the current selection
[ctrl-A] selects everything in the current diagram

give tools a shortcut key, which shows up in the tooltip."

So ignoring the last line, only ctrl-a is missing. The attached patch solves
this problem as well, but there is one point missing:

I added a function void UMLView::selectAll() and I added a "shortcut" in
uml.cpp to call this function. This works fine, but UMLListView also catches
the Ctrl-A key event and selects all items. I think UMLListView catches
first.

How can I prevent UMLListView from doing this? I mean it would be good if
only the window with the focus is catching key events. I think I missed
something in the source. (And yes the other way around it should work as
well: UMLView shouldn't catch key event if it hasn't the focus)

Who can help?

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/uml.cpp new/uml.cpp
--- old/uml.cpp	Tue Oct 15 21:36:00 2002
+++ new/uml.cpp	Tue Oct 15 21:05:09 2002
@@ -54,6 +54,7 @@
 	ldict.setAutoDelete(true);
 	langSelect = new QPopupMenu(this);
 	loading = false;
+	ctrl_pressed = false;
 	m_clipTimer = 0;
 	m_copyTimer = 0;
 	///////////////////////////////////////////////////////////////////
@@ -1188,7 +1189,9 @@
 			//toolsbar->setOldTool();
 			e->accept();
 			break;
-
+		case Qt::Key_Control:
+			ctrl_pressed = true;
+			break;
 		default:
 			e->ignore();
 	}
@@ -1197,13 +1200,32 @@
 
 void UMLApp::keyReleaseEvent(QKeyEvent *e) {
 	switch(e->key()) {
+		/* toggle between the current and last tool */
 		case Qt::Key_Shift:
 			toolsbar->setOldTool();
 			e->accept();
 			break;
+		/* reset the tools to the arrow */
 		case Qt::Key_Escape:
 			toolsbar->setDefaultTool();
 			e->accept();
+			break;
+		/* delete currently selected objects */
+		case Qt::Key_Delete:
+		case Qt::Key_Backspace:
+			toolsbar->setOldTool();
+			doc->getCurrentView()->deleteSelection();
+			e->accept();
+			break;
+		case Qt::Key_Control:
+			ctrl_pressed = false;
+			break;
+		case Qt::Key_A:
+			if (ctrl_pressed == true)
+			{
+				doc->getCurrentView()->selectAll();
+				e->accept();
+			}
 			break;
 		default:
 			e->ignore();
diff -u old/uml.h new/uml.h
--- old/uml.h	Tue Oct 15 21:36:02 2002
+++ new/uml.h	Tue Oct 15 20:44:56 2002
@@ -136,7 +136,12 @@
 
 protected:
 	virtual void keyPressEvent(QKeyEvent* e);
+
+	/**
+	 * some keyboard shortcuts are filtered to perform the right action
+	 */
 	virtual void keyReleaseEvent(QKeyEvent* e);
+
 	/**
 	 *	Carries out the cut/copy command with different action performed
 	 *	depending on if from view or list view.
@@ -557,6 +562,11 @@
 	 */
 	bool loading;
 	SettingsDlg::OptionState optionState;
+
+	/**
+	 * True, if the CTRL-key is pressed but not yet released
+	 */
+	bool ctrl_pressed;
 public:
 	/**
 	 *  splitter used to split main window
diff -u old/umlview.cpp new/umlview.cpp
--- old/umlview.cpp	Tue Oct 15 21:35:55 2002
+++ new/umlview.cpp	Tue Oct 15 21:19:08 2002
@@ -856,6 +856,29 @@
 	//make sure list empty - it should be anyway, just a check.
 	m_SelectedList.clear();
 }
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+void UMLView::selectAll()
+{
+	clearSelected();
+	UMLWidget * temp;
+
+	QObjectList * l = queryList( "UMLWidget");
+	QObjectListIt it( *l );
+
+	while ( (temp=(UMLWidget*)it.current()) != 0 )
+	{
+		if ( temp -> isVisible() )
+		{
+				//just make sure hasn't already been added automatically
+				m_SelectedList.remove(temp);
+				m_SelectedList.append(temp);
+				temp -> setSelected(true);
+		}
+		++it;
+	}
+}
+
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 void UMLView::contentsMousePressEvent(QMouseEvent* mouseEvent) {
 	getDocument()->setModified(true);
@@ -1052,6 +1075,7 @@
 	}//end while
 	delete lw;
 }
+
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 void  UMLView::getDiagram(const QRect &rect, QPixmap & diagram) {
 	//unselect all before grab
diff -u old/umlview.h new/umlview.h
--- old/umlview.h	Tue Oct 15 21:35:56 2002
+++ new/umlview.h	Tue Oct 15 21:18:18 2002
@@ -257,6 +257,11 @@
 	void deleteSelection();
 
 	/**
+	 * Selects all widgets
+	 */
+	void selectAll();
+
+	/**
 	 *	Return a unique ID for the diagram.  Used by the @ref ObjectWidget class.
 	 *
 	 *	@return Return a unique ID for the diagram.
@@ -727,6 +732,7 @@
 	 *	Selects all the widgets within an internally kept rectangle.
 	 */
 	void selectWidgets();
+
 
 	QPoint m_Pos, m_LineToPos;
 	bool m_bCreateObject, m_bDrawRect, m_bDrawSelectedOnly, m_bPaste;


More information about the umbrello-devel mailing list