[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    [patch]auto-select SUM cells in kspread
From:       Martin Koller <m.koller () surfeu ! at>
Date:       2005-12-10 20:04:08
Message-ID: 200512102104.08314.m.koller () surfeu ! at
[Download RAW message or body]

Hi folks,

attached you find a patch which implements a nice feature found also in "the 
other" spreadsheet programs:
Clicking on the SUM icon automagically selects the cell range to sum up and 
puts this into the SUM formula.
It first checks the numeric cells above the current one, and if there is none, 
it checks the cells to the left.

What do you think ?
Is it ok to commit ?

-- 
Best regards/Schöne Grüße

Martin    ()  ascii ribbon campaign - against html mail 
          /\                        - against microsoft attachments

Computers and Internet gave you freedom.
TCPA would TAKE your FREEDOM!  http://www.againsttcpa.com

["autosum.patch" (text/x-diff)]

Index: kspread_view.cc
===================================================================
--- kspread_view.cc	(revision 486289)
+++ kspread_view.cc	(working copy)
@@ -2481,6 +2481,50 @@
     else
     {
       sel=QRect();
+
+      // only 1 cell selected
+      // try to automagically find cells the user wants to sum up
+
+      int start = -1, end = -1;
+
+      if ( (marker().y() > 1) && activeSheet()->cellAt(marker().x(), \
marker().y()-1)->value().isNumber() ) +      {
+        // check cells above the current one
+        start = end = marker().y()-1;
+        for (start--; (start > 0) && activeSheet()->cellAt(marker().x(), \
start)->value().isNumber(); start--) ; +
+        Point startPoint, endPoint;
+        startPoint.setRow(start+1);
+        startPoint.setColumn(marker().x());
+        endPoint.setRow(end);
+        endPoint.setColumn(marker().x());
+
+        QString str = Range(startPoint, endPoint).toString();
+
+        d->canvas->createEditor( Canvas::CellEditor , true , true );
+        d->canvas->editor()->setText("=SUM(" + str + ")");
+        d->canvas->editor()->setCursorPosition(5 + str.length());
+        return;
+      }
+      else if ( (marker().x() > 1) && \
activeSheet()->cellAt(marker().x()-1, marker().y())->value().isNumber() ) + \
{ +        // check cells to the left of the current one
+        start = end = marker().x()-1;
+        for (start--; (start > 0) && activeSheet()->cellAt(start, \
marker().y())->value().isNumber(); start--) ; +
+        Point startPoint, endPoint;
+        startPoint.setColumn(start+1);
+        startPoint.setRow(marker().y());
+        endPoint.setColumn(end);
+        endPoint.setRow(marker().y());
+
+        QString str = Range(startPoint, endPoint).toString();
+
+        d->canvas->createEditor( Canvas::CellEditor , true , true );
+        d->canvas->editor()->setText("=SUM(" + str + ")");
+        d->canvas->editor()->setCursorPosition(5 + str.length());
+        return;
+      }
     }
   }
 
@@ -2494,13 +2538,13 @@
 
   if ( (rg.range().isValid() ) && (!rg.range().isEmpty()) )
   {
-        d->canvas->editor()->setText( "=SUM("+rg.toString()+")" );
+    d->canvas->editor()->setText( "=SUM("+rg.toString()+")" );
     d->canvas->deleteEditor(true);
   }
   else
   {
-    d->canvas->editor()->setText( "=SUM( )" );
-        d->canvas->editor()->setCursorPosition( 5 );
+    d->canvas->editor()->setText( "=SUM()" );
+    d->canvas->editor()->setCursorPosition( 5 );
   }
 }
 



_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic