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

List:       koffice-devel
Subject:    suspending screen updates
From:       John Dailey <dailey () vt ! edu>
Date:       2001-12-07 6:04:43
[Download RAW message or body]

Hi,

I've got a patch here that I'd like people to take a look at.  I'm pretty new 
to KOffice/KDE/QT development so I'm sure there's lots of issues I'm 
trampling over without realizing it.

I wanted to shorten the time it takes KSpread to sort by preventing the screen 
from repeatedly refreshing after each cell data is copied in the sort.  Then 
I figured why not put it in the kofficecore classes in a generic way.

I added signals in the KoDocument class so that any document can signal its 
views that "hey, don't update for a while" and then "ok, I'm done -- now you 
can refresh the screen".

It ended up not doing a great deal to reduce the sort time (my test case went 
from 14-15 seconds to about 11 or 12) but it seems like this would be useful 
for any KOffice application.

Does this look reasonable? (patch is from the koffice base directory)

John Dailey
dailey@vt.edu
["refresh_patch.txt" (text/plain)]

? koffice.kdevelop
? kspread/kspread.kdevelop
? kword/kwdoc.loT
Index: kspread/kspread_table.cc
===================================================================
RCS file: /home/kde/koffice/kspread/kspread_table.cc,v
retrieving revision 1.306
diff -u -3 -p -u -r1.306 kspread_table.cc
--- kspread/kspread_table.cc	2001/12/05 08:15:49	1.306
+++ kspread/kspread_table.cc	2001/12/07 06:24:19
@@ -2838,9 +2838,11 @@ void KSpreadTable::sortByRow( int ref_ro
             return;
     }
 
+   doc()->emitBeginOperation();
     // Sorting algorithm: David's :). Well, I guess it's called minmax or so.
     // For each column, we look for all cells right hand of it and we find the one to swap with it.
     // Much faster than the awful bubbleSort...
+    
     for ( int d = r.left();  d <= r.right(); d++ )
     {
         KSpreadCell *cell1 = cellAt( d, ref_row  );
@@ -2887,8 +2889,8 @@ void KSpreadTable::sortByRow( int ref_ro
         }
 
     }
-
-    emit sig_updateView( this, r );
+   doc()->emitEndOperation();
+   
 }
 
 void KSpreadTable::sortByColumn(int ref_column,SortingOrder mode)
@@ -2933,12 +2935,14 @@ void KSpreadTable::sortByColumn(int ref_
         if ( r.bottom() < r.top() )
             return;
     }
-
+   doc()->emitBeginOperation();
     // Sorting algorithm: David's :). Well, I guess it's called minmax or so.
     // For each row, we look for all rows under it and we find the one to swap with it.
     // Much faster than the awful bubbleSort...
     // Torben: Asymptotically it is alltogether O(n^2) :-)
-    for ( int d = r.top(); d <= r.bottom(); d++ )
+
+
+   for ( int d = r.top(); d <= r.bottom(); d++ )
     {
         // Look for which row we want to swap with the one number d
         KSpreadCell *cell1 = cellAt( ref_column, d );
@@ -2983,8 +2987,7 @@ void KSpreadTable::sortByColumn(int ref_
                 swapCells( x, d, x, bestY );
         }
     }
-
-    emit sig_updateView( this, r );
+   doc()->emitEndOperation();
 }
 
 void KSpreadTable::swapCells( int x1, int y1, int x2, int y2 )
Index: lib/kofficecore/koDocument.h
===================================================================
RCS file: /home/kde/koffice/lib/kofficecore/koDocument.h,v
retrieving revision 1.98
diff -u -3 -p -u -r1.98 koDocument.h
--- lib/kofficecore/koDocument.h	2001/10/25 16:39:02	1.98
+++ lib/kofficecore/koDocument.h	2001/12/07 06:24:20
@@ -441,7 +441,10 @@ public:
 
   void emitProgress( int value ) { emit sigProgress( value ); }
 
-  /**
+  void emitBeginOperation() {emit sigBeginOperation(); }
+  void emitEndOperation() {emit sigEndOperation(); }
+
+   /**
    * Return true if url() is a real filename, false if url() is
    * an internal url in the store, like "tar:/..."
    */
@@ -459,6 +462,9 @@ signals:
   void childChanged( KoDocumentChild *child );
 
   void sigProgress(int value);
+
+  void sigBeginOperation();
+  void sigEndOperation();
 
 protected:
 
Index: lib/kofficecore/koView.cc
===================================================================
RCS file: /home/kde/koffice/lib/kofficecore/koView.cc,v
retrieving revision 1.69
diff -u -3 -p -u -r1.69 koView.cc
--- lib/kofficecore/koView.cc	2001/10/12 12:45:27	1.69
+++ lib/kofficecore/koView.cc	2001/12/07 06:24:20
@@ -25,11 +25,13 @@
 #include <koDocumentChild.h>
 
 #include <klocale.h>
+#include <kglobal.h>
 #include <kdebug.h>
 #include <kparts/partmanager.h>
 #include <kparts/event.h>
 #include <assert.h>
 #include <kstatusbar.h>
+#include <qapplication.h>
 
 class KoViewPrivate
 {
@@ -104,6 +106,8 @@ KoView::KoView( KoDocument *document, QW
 {
   Q_ASSERT( document );
 
+  inOperation = false;
+   
   //kdDebug(30003) << "KoView::KoView " << this << endl;
   d = new KoViewPrivate;
   d->m_doc = document;
@@ -116,6 +120,13 @@ KoView::KoView( KoDocument *document, QW
   connect( d->m_doc, SIGNAL( childChanged( KoDocumentChild * ) ),
            this, SLOT( slotChildChanged( KoDocumentChild * ) ) );
 
+  connect( d->m_doc, SIGNAL( sigBeginOperation() ),
+           this, SLOT( beginOperation() ) );
+
+  connect( d->m_doc, SIGNAL( sigEndOperation() ),
+           this, SLOT( endOperation() ) );
+  
+
   setupGlobalActions();
   QValueList<KAction*> docActions = document->actionCollection()->actions();
   QValueList<KAction*>::ConstIterator it = docActions.begin();
@@ -540,6 +551,23 @@ void KoView::newView() {
     KoMainWindow *shell = new KoMainWindow( thisDocument->instance() );
     shell->setRootDocument(thisDocument);
     shell->show();
+}
+
+void KoView::beginOperation()
+{
+   
+   QApplication::setOverrideCursor(waitCursor);
+   inOperation = true;
+   canvas()->setUpdatesEnabled(FALSE);
+}
+
+void KoView::endOperation()
+{
+   canvas()->setUpdatesEnabled(TRUE);
+   inOperation = false;
+   QApplication::restoreOverrideCursor();
+
+   canvas()->update();
 }
 
 KoMainWindow * KoView::shell() const
Index: lib/kofficecore/koView.h
===================================================================
RCS file: /home/kde/koffice/lib/kofficecore/koView.h,v
retrieving revision 1.38
diff -u -3 -p -u -r1.38 koView.h
--- lib/kofficecore/koView.h	2001/10/11 15:56:20	1.38
+++ lib/kofficecore/koView.h	2001/12/07 06:24:21
@@ -296,9 +296,22 @@ public:
    */
   virtual void updateReadWrite( bool readwrite ) = 0;
 
+  bool isInOperation() const { return inOperation; }
 public slots:
 
     virtual void newView();
+   
+    /*
+     * Slot to allow code to signal the beginning of an operation where the screen should
+     * not update until it is done (see @ref KoView::endOperation)
+     */
+    virtual void beginOperation();
+   
+    /*
+     * Slot to allow code to signal the end of an operation where the screen should
+     * not have been updating.  So now it will update. (see @ref KoView::beginOperation)
+     */
+    virtual void endOperation();
 
 protected:
   /**
@@ -351,6 +364,9 @@ private:
   KAction *actionNewView;
   virtual void setupGlobalActions( void );
   KoViewPrivate *d;
+   
+  /* indicates whether the view is in the process of being updated. */
+  bool inOperation;
 };
 
 class KoViewChild : public KoChild

_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://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