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

List:       kde-commits
Subject:    KDE/kdegraphics/kolourpaint
From:       Martin Koller <kollix () aon ! at>
Date:       2011-02-10 21:11:28
Message-ID: 20110210211128.E52AEAC8BE () svn ! kde ! org
[Download RAW message or body]

SVN commit 1219762 by mkoller:

speed up pasting/undo/redo large amount of text(lines) by not doing useless repaints \
for each line and limit size of document to not exhaust memory

BUG: 161971


 M  +3 -0      commands/kpCommandHistory.cpp  
 M  +7 -0      commands/kpCommandHistoryBase.cpp  
 M  +20 -0     commands/kpMacroCommand.cpp  
 M  +7 -4      commands/tools/selection/text/kpToolTextInsertCommand.cpp  
 M  +0 -1      commands/tools/selection/text/kpToolTextInsertCommand.h  
 M  +8 -1      layers/selections/text/kpTextSelection_Paint.cpp  
 M  +9 -13     mainWindow/kpMainWindow_Edit.cpp  
 M  +4 -4      views/kpView_Paint.cpp  


--- trunk/KDE/kdegraphics/kolourpaint/commands/kpCommandHistory.cpp #1219761:1219762
@@ -86,6 +86,7 @@
         addCommand (cmd, execute);
 }
 
+//---------------------------------------------------------------------
 
 // public slot virtual [base KCommandHistory]
 void kpCommandHistory::undo ()
@@ -104,6 +105,8 @@
         kpCommandHistoryBase::undo ();
 }
 
+//---------------------------------------------------------------------
+
 // public slot virtual [base KCommandHistory]
 void kpCommandHistory::redo ()
 {
--- trunk/KDE/kdegraphics/kolourpaint/commands/kpCommandHistoryBase.cpp \
#1219761:1219762 @@ -310,6 +310,7 @@
     updateActions ();
 }
 
+//---------------------------------------------------------------------
 
 // protected slot
 void kpCommandHistoryBase::undoInternal ()
@@ -345,6 +346,8 @@
     }
 }
 
+//---------------------------------------------------------------------
+
 // protected slot
 void kpCommandHistoryBase::redoInternal ()
 {
@@ -379,6 +382,7 @@
     }
 }
 
+//---------------------------------------------------------------------
 
 // public slot virtual
 void kpCommandHistoryBase::undo ()
@@ -391,6 +395,8 @@
     trimCommandListsUpdateActions ();
 }
 
+//---------------------------------------------------------------------
+
 // public slot virtual
 void kpCommandHistoryBase::redo ()
 {
@@ -402,6 +408,7 @@
     trimCommandListsUpdateActions ();
 }
 
+//---------------------------------------------------------------------
 
 // public slot virtual
 void kpCommandHistoryBase::undoUpToNumber (QAction *which)
--- trunk/KDE/kdegraphics/kolourpaint/commands/kpMacroCommand.cpp #1219761:1219762
@@ -30,11 +30,13 @@
 
 
 #include <kpMacroCommand.h>
+#include <kpViewManager.h>
 
 #include <climits>
 
 #include <QtAlgorithms>
 
+//---------------------------------------------------------------------
 
 struct kpMacroCommandPrivate
 {
@@ -47,12 +49,15 @@
 {
 }
 
+//---------------------------------------------------------------------
+
 kpMacroCommand::~kpMacroCommand ()
 {
     qDeleteAll (m_commandList.begin (), m_commandList.end ());
     delete d;
 }
 
+//---------------------------------------------------------------------
 
 // public virtual [base kpCommand]
 kpCommandSize::SizeType kpMacroCommand::size () const
@@ -81,6 +86,7 @@
     return s;
 }
 
+//---------------------------------------------------------------------
 
 // public virtual [base kpCommand]
 void kpMacroCommand::execute ()
@@ -88,6 +94,9 @@
 #if DEBUG_KP_COMMAND_HISTORY
     kDebug () << "kpMacroCommand::execute()";
 #endif
+
+    viewManager()->setQueueUpdates();
+
     for (QLinkedList <kpCommand *>::const_iterator it = m_commandList.begin ();
          it != m_commandList.end ();
          it++)
@@ -97,14 +106,21 @@
     #endif
         (*it)->execute ();
     }
+
+    viewManager()->restoreQueueUpdates();
 }
 
+//---------------------------------------------------------------------
+
 // public virtual [base kpCommand]
 void kpMacroCommand::unexecute ()
 {
 #if DEBUG_KP_COMMAND_HISTORY
     kDebug () << "kpMacroCommand::unexecute()";
 #endif
+
+    viewManager()->setQueueUpdates();
+
     QLinkedList <kpCommand *>::const_iterator it = m_commandList.end ();
     it--;
 
@@ -117,8 +133,11 @@
 
         it--;
     }
+
+    viewManager()->restoreQueueUpdates();
 }
 
+//---------------------------------------------------------------------
 
 // public
 void kpMacroCommand::addCommand (kpCommand *command)
@@ -126,3 +145,4 @@
     m_commandList.push_back (command);
 }
 
+//---------------------------------------------------------------------
--- trunk/KDE/kdegraphics/kolourpaint/commands/tools/selection/text/kpToolTextInsertCommand.cpp \
#1219761:1219762 @@ -35,6 +35,7 @@
 #include <kpTextSelection.h>
 #include <kpViewManager.h>
 
+//---------------------------------------------------------------------
 
 kpToolTextInsertCommand::kpToolTextInsertCommand (const QString &name,
         int row, int col, QString newText,
@@ -46,11 +47,8 @@
     addText (newText);
 }
 
-kpToolTextInsertCommand::~kpToolTextInsertCommand ()
-{
-}
+//---------------------------------------------------------------------
 
-
 // public
 void kpToolTextInsertCommand::addText (const QString &moreText)
 {
@@ -69,6 +67,7 @@
     viewManager ()->setTextCursorPosition (m_row, m_col);
 }
 
+//---------------------------------------------------------------------
 
 // public virtual [base kpCommand]
 kpCommandSize::SizeType kpToolTextInsertCommand::size () const
@@ -76,6 +75,7 @@
     return (kpCommandSize::SizeType) m_newText.length () * sizeof (QChar);
 }
 
+//---------------------------------------------------------------------
 
 // public virtual [base kpCommand]
 void kpToolTextInsertCommand::execute ()
@@ -87,6 +87,8 @@
     addText (text);
 }
 
+//---------------------------------------------------------------------
+
 // public virtual [base kpCommand]
 void kpToolTextInsertCommand::unexecute ()
 {
@@ -103,3 +105,4 @@
     viewManager ()->setTextCursorPosition (m_row, m_col);
 }
 
+//---------------------------------------------------------------------
--- trunk/KDE/kdegraphics/kolourpaint/commands/tools/selection/text/kpToolTextInsertCommand.h \
#1219761:1219762 @@ -39,7 +39,6 @@
     kpToolTextInsertCommand (const QString &name,
         int row, int col, QString newText,
         kpCommandEnvironment *environ);
-    virtual ~kpToolTextInsertCommand ();
 
     void addText (const QString &moreText);
 
--- trunk/KDE/kdegraphics/kolourpaint/layers/selections/text/kpTextSelection_Paint.cpp \
#1219761:1219762 @@ -180,6 +180,10 @@
       {
           painter.drawText (theTextAreaRect.x (), baseLine, str);
           baseLine += fontMetrics.lineSpacing ();
+
+          // if the next textline would already be below the visible text area, stop \
drawing +          if ( (baseLine - fontMetrics.ascent()) > (theTextAreaRect.y() + \
theTextAreaRect.height()) ) +            break;
       }
       // the next text drawing will now blend the text foreground color with
       // what is really below the text background
@@ -225,10 +229,13 @@
             }
             baseLine += fontMetrics.lineSpacing();
             i++;
+
+            // if the next textline would already be below the visible text area, \
stop drawing +            if ( (baseLine - fontMetrics.ascent()) > \
(theTextAreaRect.y() + theTextAreaRect.height()) ) +              break;
         }
     }
 
-
     // ... convert that into "painting" transparent pixels on top of
     // the document.
     kpPixmapFX::paintPixmapAt (destPixmap,
--- trunk/KDE/kdegraphics/kolourpaint/mainWindow/kpMainWindow_Edit.cpp \
#1219761:1219762 @@ -36,6 +36,7 @@
 #include <qimage.h>
 #include <qlist.h>
 #include <qmenu.h>
+#include <QDesktopWidget>
 
 #include <kaction.h>
 #include <kdebug.h>
@@ -70,7 +71,6 @@
 #include <kpViewScrollableContainer.h>
 #include <kpZoomedView.h>
 
-
 //---------------------------------------------------------------------
 
 // private
@@ -417,19 +417,8 @@
 
     toolEndShape ();
 
+    QStringList textLines = text.split('\n');
 
-    QList <QString> textLines;
-    textLines.append (QString ());
-
-    for (int i = 0; i < (int) text.length (); i++)
-    {
-        if (text [i] == '\n')
-            textLines.push_back (QString::null);  //krazy:exclude=nullstrassign for \
                old broken gcc
-        else
-            textLines [textLines.size () - 1].append (text [i]);
-    }
-
-
     if (!forceNewTextSelection &&
         d->document && d->document->textSelection () &&
         d->commandHistory && d->viewManager)
@@ -438,6 +427,8 @@
         kDebug () << "\treusing existing Text Selection";
     #endif
 
+        d->viewManager->setQueueUpdates();
+
         kpTextSelection *textSel = d->document->textSelection ();
         if (!textSel->hasContent ())
         {
@@ -489,6 +480,8 @@
         }
 
         d->commandHistory->addCommand (macroCmd, false/*no exec*/);
+
+        d->viewManager->restoreQueueUpdates();
     }
     else
     {
@@ -513,6 +506,9 @@
                 width = w;
         }
 
+        // limit the size to avoid memory overflow
+        width = qMin(qMax(QApplication::desktop()->width(), d->document->width()), \
width); +        height = qMin(qMax(QApplication::desktop()->height(), \
d->document->height()), height);  
         const int selWidth = qMax (kpTextSelection::MinimumWidthForTextStyle (ts),
                                    width + kpTextSelection::TextBorderSize () * 2);
--- trunk/KDE/kdegraphics/kolourpaint/views/kpView_Paint.cpp #1219761:1219762
@@ -519,7 +519,7 @@
 //
 //    We can't use QPainter::setClipRect() since it is buggy in Qt 4.3.1
 //    and clips too many pixels when used in combination with scale()
-//    [qt-bugs@trolltech.com issue N181038].
+//    [qt-bugs@trolltech.com issue N181038].  ==> MK 10.2.2011 - fixed since \
Qt-4.4.4  //
 // B. paintEventGetDocRect() may, by design, return a larger document
 //    rectangle than what <viewRect> corresponds to, if the zoom levels
@@ -564,8 +564,8 @@
         docPixmap = doc->getImageAt (docRect);
 
     #if DEBUG_KP_VIEW_RENDERER && 1
-        kDebug () << "\tdocPixmap.hasAlpha()="
-                  << docPixmap.hasAlpha () << endl;
+        kDebug () << "\tdocPixmap.hasAlphaChannel()="
+                  << docPixmap.hasAlphaChannel () << endl;
     #endif
 
         tempImageWillBeRendered =
@@ -686,7 +686,7 @@
     // part of the view (which could be quite small inside a scrollview).
     QRegion viewRegion = e->region ();
     QVector <QRect> rects = viewRegion.rects ();
-#if DEBUG_KP_VIEW_RENDERER && 1
+#if DEBUG_KP_VIEW_RENDERER
     kDebug () << "\t#rects = " << rects.count ();
 #endif
 


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

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