Bug 143748 - when a function depends on another, propose to delete both instead of refusing to delete the latter
Summary: when a function depends on another, propose to delete both instead of refusin...
Status: RESOLVED FIXED
Alias: None
Product: kmplot
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR wishlist
Target Milestone: ---
Assignee: Klaus-Dieter M
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-02 18:53 UTC by koxinga
Modified: 2007-04-03 00:08 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
simple patch (502 bytes, patch)
2007-04-02 18:54 UTC, koxinga
Details

Note You need to log in before you can comment on or make changes to this bug.
Description koxinga 2007-04-02 18:53:23 UTC
Version:            (using KDE Devel)
Compiler:          gcc 4.1.2 
OS:                Linux

If I create a new file with functions f(x)=x and g(x)=f(x), I can't delete f because g depends on it. IMHO, it would be better to have a dialog box offering to delete both.

I made a simple patch to present the kind of behaviour I would like. It is rather crude, especially if there are several dependances, there will be several dialogs.

(if you don't use my patch, the label of the box should be changed from "This function is depending on another function" to "another function depends on this function". It seems more logical.)
Comment 1 koxinga 2007-04-02 18:54:58 UTC
Created attachment 20156 [details]
simple patch
Comment 2 David Saxton 2007-04-03 00:08:47 UTC
SVN commit 649628 by saxton:

If the user trys to delete a function, and other functions depend on this function, then give the option of deleting these other functions in addition.
Thanks for the good bug report, koxinga.
BUG: 143748


 M  +42 -10    parser.cpp  


--- trunk/KDE/kdeedu/kmplot/kmplot/parser.cpp #649627:649628
@@ -604,23 +604,55 @@
 
 bool Parser::removeFunction( Function * item )
 {
-	foreach ( Function * it, m_ufkt )
+	// Build up a list of functions that need to be removed is this function is removed
+	QList<Function *> toRemove;
+	QStringList otherRemoveNames;
+	QList<Function *> newFunctions; // Added since the last iteration
+	
+	toRemove << item;
+	newFunctions << item;
+	
+	while ( ! newFunctions.isEmpty() )
 	{
-		if ( it == item )
-			continue;
+		QList<Function *> currentFunctions = newFunctions;
+		newFunctions.clear();
 		
-		if ( it->dependsOn( item ) )
+		foreach ( Function *f, currentFunctions )
 		{
-			KMessageBox::sorry(0,i18n("This function is depending on an other function"));
-			return false;
+			foreach ( Function *other, m_ufkt )
+			{
+				if ( (other==f) || toRemove.contains(other) )
+					continue;
+				
+				if ( other->dependsOn( f ) )
+				{
+					toRemove << other;
+					otherRemoveNames << other->name();
+					newFunctions << other;
+				}
+			}
 		}
 	}
 	
-	uint const id = item->id();
-	m_ufkt.remove(id);
-	delete item;
+	if ( toRemove.size() > 1 )
+	{
+		KGuiItem buttonContinue = KStandardGuiItem::cont();
+		buttonContinue.setText( i18n("Remove all") );
+		
+		int answer = KMessageBox::warningContinueCancel( 0, i18n( "The function %1 is depended upon by the following functions: %2. These must be removed in addition.", item->name(), otherRemoveNames.join(", ") ), QString(), buttonContinue );
+		
+		if ( answer == KMessageBox::Cancel )
+			return false;
+	}
 	
-	emit functionRemoved( id );
+	foreach ( Function *f, toRemove )
+	{
+		uint id = f->id();
+		m_ufkt.remove( id );
+		delete f;
+		emit functionRemoved( id );
+	}
+	
 	return true;
 }