Commit 32087a1d authored by Ralf Habacker's avatar Ralf Habacker

Fix 'Umbrello raises confirmation dialog for deleting an association where no...

Fix 'Umbrello raises confirmation dialog for deleting an association where no association is involved'

BUG:393996
FIXED-IN: 2.25.80 (KDE Applications 18.07.80)
parent ad1f29b9
......@@ -1257,8 +1257,8 @@ QRectF UMLScene::diagramRect()
/**
* Returns a list of selected widgets
* QGraphicsScene calls widgets isSelected() to determine selection state.
* @return list of selected widgets based on class UMLWidget
* @note This method returns widgets including message widgets, but no association widgets
*/
UMLWidgetList UMLScene::selectedWidgets() const
{
......@@ -1273,6 +1273,40 @@ UMLWidgetList UMLScene::selectedWidgets() const
return widgets;
}
/**
* Returns a list of selected association widgets
* @return list of selected widgets based on class AssociationWidget
*/
AssociationWidgetList UMLScene::selectedAssociationWidgets() const
{
QList<QGraphicsItem *> items = selectedItems();
AssociationWidgetList widgets;
foreach(QGraphicsItem *item, items) {
AssociationWidget *w = dynamic_cast<AssociationWidget*>(item);
if (w)
widgets.append(w);
}
return widgets;
}
/**
* Returns a list of selected message widgets
* @return list of selected widgets based on class MessageWidget
*/
UMLWidgetList UMLScene::selectedMessageWidgets() const
{
QList<QGraphicsItem *> items = selectedItems();
UMLWidgetList widgets;
foreach(QGraphicsItem *item, items) {
MessageWidget *w = dynamic_cast<MessageWidget*>(item);
if (w)
widgets.append(w);
}
return widgets;
}
/**
* Clear the selected widgets list.
*/
......@@ -1421,12 +1455,27 @@ void UMLScene::unselectChildrenOfSelectedWidgets()
*/
void UMLScene::deleteSelection()
{
int selectionCount = selectedWidgets().count() + associationList().count();
AssociationWidgetList selectedAssociations = selectedAssociationWidgets();
int selectionCount = selectedWidgets().count() + selectedAssociations.count();
if (selectionCount > 1) {
UMLApp::app()->beginMacro(i18n("Delete widgets"));
if (selectionCount == 0)
return;
// check related associations
bool hasAssociations = false;
foreach(UMLWidget* widget, selectedWidgets()) {
if (widget->isTextWidget() && widget->asFloatingTextWidget()->textRole() != Uml::TextRole::Floating) {
continue;
}
if (widget->isMessageWidget() || widget->associationWidgetList().size() > 0)
hasAssociations = true;
}
if (hasAssociations && !Dialog_Utils::askDeleteAssociation())
return;
UMLApp::app()->beginMacro(i18n("Delete widgets"));
unselectChildrenOfSelectedWidgets();
foreach(UMLWidget* widget, selectedWidgets()) {
......@@ -1442,35 +1491,20 @@ void UMLScene::deleteSelection()
}
}
if ((associationList().size() > 0 || messageList().size()) > 0
&& Dialog_Utils::askDeleteAssociation()) {
// Delete any selected associations.
foreach(AssociationWidget* assocwidget, associationList()) {
if (assocwidget->isSelected()) {
removeWidgetCmd(assocwidget);
}
}
// we also have to remove selected messages from sequence diagrams
// loop through all messages and check the selection state
foreach(MessageWidget* cur_msgWgt, messageList()) {
if (cur_msgWgt->isSelected()) {
removeWidget(cur_msgWgt); // Remove message - it is selected.
}
}
// Delete any selected associations.
foreach(AssociationWidget* assocwidget, selectedAssociations) {
removeWidgetCmd(assocwidget);
}
// sometimes we miss one widget, so call this function again to remove it as well
//if (selectedWidgets().count() != 0)
// deleteSelection();
// we also have to remove selected messages from sequence diagrams
foreach(UMLWidget* cur_msgWgt, selectedMessageWidgets()) {
removeWidget(cur_msgWgt);
}
//make sure list empty - it should be anyway, just a check.
clearSelected();
if (selectionCount > 1) {
UMLApp::app()->endMacro();
}
UMLApp::app()->endMacro();
}
/**
......
......@@ -182,6 +182,8 @@ private:
public:
UMLWidgetList selectedWidgets() const;
AssociationWidgetList selectedAssociationWidgets() const;
UMLWidgetList selectedMessageWidgets() const;
void clearSelected();
void moveSelectedBy(qreal dX, qreal dY);
......
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