Commit 456651dd authored by Ralf Habacker's avatar Ralf Habacker

Fix of 'When editing a list view item POS1 and END key performs wrong'.

BUG: 328973
(cherry picked from commit 584f826f)

Conflicts:
	umbrello/umllistview.cpp
	umbrello/umllistview.h
parent dd4dd14e
......@@ -352,7 +352,7 @@ void UMLApp::initActions()
deleteSelectedWidget->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Delete));
deleteSelectedWidget->setText(i18nc("delete selected widget", "Delete &Selected"));
deleteSelectedWidget->setShortcut(QKeySequence(Qt::Key_Delete));
connect(deleteSelectedWidget, SIGNAL(triggered(bool)), this, SLOT(slotDeleteSelectedWidget()));
connect(deleteSelectedWidget, SIGNAL(triggered(bool)), this, SLOT(slotDeleteSelected()));
// The different views
newDiagram = actionCollection()->add<KActionMenu>("new_view");
......@@ -1447,7 +1447,7 @@ void UMLApp::slotEditCut()
if (editCutCopy(fromview)) {
emit sigCutSuccessful();
slotDeleteSelectedWidget();
slotDeleteSelected();
m_doc->setModified(true);
}
resetStatusMsg();
......@@ -2552,10 +2552,21 @@ void UMLApp::slotSelectAll()
}
/**
* Deletes the selected widget.
* Deletes selected widgets or list view items.
*/
void UMLApp::slotDeleteSelectedWidget()
void UMLApp::slotDeleteSelected()
{
// deleteSelectedWidget grabs DEL key as shortcut,
// which prevents routing DEL key through the regular
// key press event handler
QWidget *f = focusWidget();
if (f == m_listView) {
QWidgetAction *o = static_cast<QWidgetAction *>(sender());
if (o->objectName() == "delete_selected") {
m_listView->slotDeleteSelectedItems();
}
return;
}
if (currentView()) {
currentView()->umlScene()->deleteSelection();
}
......
......@@ -243,7 +243,7 @@ public slots:
void slotSnapToGridToggled(bool gridOn);
void slotShowGridToggled(bool gridOn);
void slotSelectAll();
void slotDeleteSelectedWidget();
void slotDeleteSelected();
void slotDeleteDiagram();
void slotCloseDiagram(QWidget* tab);
void slotGenerateAllCode();
......
......@@ -89,9 +89,7 @@ UMLListView::UMLListView(QWidget *parent)
m_bStartedCut(false),
m_bStartedCopy(false),
m_bCreatingChildObject(false),
m_bRenameInProgress(false),
m_dragStartPosition(QPoint()),
m_editItem(0)
m_dragStartPosition(QPoint())
{
// setup list view
setAcceptDrops(true);
......@@ -141,21 +139,6 @@ void UMLListView::setTitle(int column, const QString &text)
headerItem()->setText(column, text);
}
/**
* Handler for item changed signals.
*/
void UMLListView::slotItemChanged(QTreeWidgetItem * item, int column)
{
UMLListViewItem *lvitem = dynamic_cast<UMLListViewItem*>(item);
if (lvitem == NULL || m_editItem == NULL)
return;
QString text = item->text(column);
if (m_bRenameInProgress) {
DEBUG(DBG_SRC) << "text: " << text;
endRename(lvitem);
}
}
/**
* Handler for item selection changed signals.
*/
......@@ -164,19 +147,6 @@ void UMLListView::slotItemSelectionChanged()
UMLListViewItem* currItem = static_cast<UMLListViewItem*>(currentItem());
if (currItem && currItem->isSelected()) {
DEBUG(DBG_SRC) << currItem->text(0);
if (m_editItem && m_bRenameInProgress) {
if (m_editItem == currItem) {
// clicked on the item which is just edited
DEBUG(DBG_SRC) << "performing endRename";
endRename(currItem);
}
else {
// other item was selected during editing
cancelRename(m_editItem);
DEBUG(DBG_SRC) << "performing cancelRename";
}
}
// Update current view to selected object's view
if (Model_Utils::typeIsDiagram(currItem->type())) {
// If the user navigates to a diagram, load the diagram just like what
......@@ -305,32 +275,16 @@ void UMLListView::mouseReleaseEvent(QMouseEvent *me)
*/
void UMLListView::keyPressEvent(QKeyEvent *ke)
{
UMLView *view = UMLApp::app()->currentView();
if (view && view->umlScene()->selectedCount()) {
// Widgets have been selected in the diagram area,
// assume they handle the keypress.
ke->accept(); // munge and do nothing
}
else {
const int k = ke->key();
if (k == Qt::Key_F2) {
UMLListViewItem * currItem = static_cast<UMLListViewItem*>(currentItem());
startRename(currItem);
} else if (k == Qt::Key_Delete || k == Qt::Key_Backspace) {
// delete every selected item
UMLListViewItemList itemsSelected = selectedItemsRoot();
foreach(UMLListViewItem *item, itemsSelected) {
deleteItem(item);
}
} else if (k == Qt::Key_F3) {
// prelimary support for layout generator
LayoutGenerator r;
if (!r.generate(UMLApp::app()->currentView()->umlScene()))
return;
r.apply(UMLApp::app()->currentView()->umlScene());
} else {
QTreeWidget::keyPressEvent(ke); // let parent handle it
}
QTreeWidget::keyPressEvent(ke); // let parent handle it
const int k = ke->key();
if (k == Qt::Key_Delete || k == Qt::Key_Backspace) {
slotDeleteSelectedItems();
} else if (k == Qt::Key_F3) {
// prelimary support for layout generator
LayoutGenerator r;
if (!r.generate(UMLApp::app()->currentView()->umlScene()))
return;
r.apply(UMLApp::app()->currentView()->umlScene());
}
}
......@@ -565,7 +519,7 @@ void UMLListView::slotMenuSelection(QAction* action)
}
case ListPopupMenu::mt_Rename:
startRename(currItem);
edit(currentIndex());
break;
case ListPopupMenu::mt_Delete:
......@@ -1320,7 +1274,6 @@ void UMLListView::init()
//setup misc.
m_bStartedCut = m_bStartedCopy = false;
m_bCreatingChildObject = false;
m_bRenameInProgress = false;
headerItem()->setHidden(true);
}
......@@ -2111,6 +2064,17 @@ void UMLListView::slotCutSuccessful()
}
}
/**
* Delete every selected item
*/
void UMLListView::slotDeleteSelectedItems()
{
UMLListViewItemList itemsSelected = selectedItemsRoot();
foreach(UMLListViewItem *item, itemsSelected) {
deleteItem(item);
}
}
/**
* Adds a new item to the tree of the given type under the given parent.
* Method will take care of signalling anyone needed on creation of new item.
......@@ -2166,7 +2130,6 @@ void UMLListView::addNewItem(UMLListViewItem *parentItem, UMLListViewItem::ListV
bool UMLListView::itemRenamed(UMLListViewItem * item, int col)
{
DEBUG(DBG_SRC) << item->text(col);
m_bRenameInProgress = false;
UMLListViewItem * renamedItem = static_cast< UMLListViewItem *>(item) ;
UMLListViewItem::ListViewType type = renamedItem->type();
QString newText = renamedItem->text(col);
......@@ -2661,63 +2624,6 @@ bool UMLListView::isUnique(UMLListViewItem * item, const QString &name)
return false;
}
/**
* Renaming of an item has started.
* @param item the item which will be renamed
*/
void UMLListView::startRename(UMLListViewItem* item)
{
if (item) {
DEBUG(DBG_SRC) << item->text(0);
if (m_editItem) {
cancelRename(m_editItem);
}
m_bRenameInProgress = true;
item->startRename(0);
openPersistentEditor(item, 0);
m_editItem = item;
}
else {
uError() << "Called without an item!";
}
}
/**
* Cancel rename event has occurred for the given item.
*/
void UMLListView::cancelRename(UMLListViewItem* item)
{
m_bRenameInProgress = false;
if (item) {
DEBUG(DBG_SRC) << item->text(0);
// delete pointer first to lock slotItemChanged
m_editItem = 0;
closePersistentEditor(item, 0);
}
else {
uError() << "Called without an item!";
}
}
/**
* Renaming of an item has ended.
* @param item the item which was renamed or not
*/
void UMLListView::endRename(UMLListViewItem* item)
{
m_bRenameInProgress = false;
if (item) {
DEBUG(DBG_SRC) << item->text(0);
// delete pointer first to lock slotItemChanged
m_editItem = 0;
closePersistentEditor(item, 0);
item->okRename(0);
}
else {
uError() << "Called without an item!";
}
}
/**
*
*/
......
......@@ -95,10 +95,6 @@ public:
bool isUnique(UMLListViewItem * item, const QString &name);
void startRename(UMLListViewItem * item);
void cancelRename(UMLListViewItem * item);
void endRename(UMLListViewItem * item);
void setSelected(UMLListViewItem * item, bool state) { setItemSelected((QTreeWidgetItem*)item, state); }
void setStartedCut(bool startedCut);
void setStartedCopy(bool startedCopy);
......@@ -176,9 +172,9 @@ public slots:
void collapseAll(UMLListViewItem *item);
void slotCutSuccessful();
void slotDeleteSelectedItems();
protected slots:
void slotItemChanged(QTreeWidgetItem *, int);
void slotItemSelectionChanged();
void slotExpanded(QTreeWidgetItem* item);
void slotCollapsed(QTreeWidgetItem* item);
......@@ -196,9 +192,7 @@ private:
bool m_bStartedCut;
bool m_bStartedCopy;
bool m_bCreatingChildObject; ///< when creating an attribute or an operation to stop it adding a second listViewItem
bool m_bRenameInProgress;
QPoint m_dragStartPosition;
UMLListViewItem* m_editItem;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment