]> git.lyx.org Git - features.git/commitdiff
* Reduce compilation time by removing the shared_ptr (which is not
authorStefan Schimanski <sts@lyx.org>
Thu, 21 Feb 2008 23:36:02 +0000 (23:36 +0000)
committerStefan Schimanski <sts@lyx.org>
Thu, 21 Feb 2008 23:36:02 +0000 (23:36 +0000)
  really important because the ownership of the CompletionLists is
  easy enough) and by removing the deque for the half finished
  favorites implemention in InsetMathNest. I think this fits better
  into the GuiCompleter anyway.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23114 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiCompleter.cpp
src/insets/Inset.h
src/insets/InsetText.cpp
src/insets/InsetText.h
src/mathed/InsetMathNest.cpp
src/mathed/InsetMathNest.h
src/mathed/MathMacro.cpp
src/mathed/MathMacro.h

index ff9b92d7f752bea07f1727c6e5f0f152190c03cc..ed8813e131e20ff0fd14d135374a11c09a95a2e5 100644 (file)
@@ -72,8 +72,11 @@ protected:
 class GuiCompletionModel : public QAbstractListModel {
 public:
        ///
-       GuiCompletionModel(QObject * parent, Inset::CompletionListPtr l)
-       : QAbstractListModel(parent), list(l) {}
+       GuiCompletionModel(QObject * parent, Inset::CompletionList const * l)
+       : QAbstractListModel(parent), list_(l) {}
+       ///
+       ~GuiCompletionModel()
+               { delete list_; }
        ///
        int columnCount(const QModelIndex & /*parent*/ = QModelIndex()) const
        {
@@ -82,16 +85,16 @@ public:
        ///
        int rowCount(const QModelIndex & /*parent*/ = QModelIndex()) const
        {
-               if (list.get() == 0)
+               if (list_ == 0)
                        return 0;
                else
-                       return list->size();
+                       return list_->size();
        }
 
        ///
        QVariant data(const QModelIndex & index, int role) const
        {
-               if (list.get() == 0)
+               if (list_ == 0)
                        return QVariant();
 
                if (index.row() < 0 || index.row() >= rowCount())
@@ -101,11 +104,11 @@ public:
                    return QVariant();
                    
                if (index.column() == 0)
-                       return toqstr(list->data(index.row()));
+                       return toqstr(list_->data(index.row()));
                else if (index.column() == 1) {
                        // get icon from cache
                        QPixmap scaled;
-                       QString const name = ":" + toqstr(list->icon(index.row()));
+                       QString const name = ":" + toqstr(list_->icon(index.row()));
                        if (!QPixmapCache::find("completion" + name, scaled)) {
                                // load icon from disk
                                QPixmap p = QPixmap(name);
@@ -125,7 +128,7 @@ public:
 
 private:
        ///
-       Inset::CompletionListPtr list;
+       Inset::CompletionList const * list_;
 };
 
 
@@ -133,7 +136,7 @@ GuiCompleter::GuiCompleter(GuiWorkArea * gui, QObject * parent)
        : QCompleter(parent), gui_(gui), updateLock_(0)
 {
        // Setup the completion popup
-       setModel(new GuiCompletionModel(this, Inset::CompletionListPtr()));
+       setModel(new GuiCompletionModel(this, 0));
        setCompletionMode(QCompleter::PopupCompletion);
        setWidget(gui_);
        
index 4e7fc0d9a1a753e67562dd039d198ddb8ef5be74..33a633f48410606a23dc08c0fedcb0ab83b3525e 100644 (file)
@@ -297,7 +297,6 @@ public:
                /// returns the resource string used to load an icon.
                virtual std::string icon(size_t /*idx*/) const { return std::string(); }
        };
-       typedef boost::shared_ptr<CompletionList> CompletionListPtr;
 
        /// Returns true if the inset supports completions.
        virtual bool completionSupported(Cursor const &) const { return false; }
@@ -312,8 +311,9 @@ public:
        virtual bool automaticPopupCompletion() const { return true; }
        /// Returns completion suggestions at cursor position. Return an
        /// null pointer if no completion is a available or possible.
-       virtual CompletionListPtr completionList(Cursor const &) const 
-               { return CompletionListPtr(); }
+       /// The caller is responsible to free the return object!
+       virtual CompletionList const * completionList(Cursor const &) const 
+               { return 0; }
        /// Returns the completion prefix to filter the suggestions for completion.
        /// This is only called if completionList returned a non-null list.
        virtual docstring completionPrefix(Cursor const &) const 
index 3b9060c7e0ad436151c6db98491939d6699c0143..9a36bc14b8678b1aab3860b68fbe1253cf56fdb5 100644 (file)
@@ -504,12 +504,12 @@ bool InsetText::automaticPopupCompletion() const
 }
 
 
-Inset::CompletionListPtr InsetText::completionList(Cursor const & cur) const
+Inset::CompletionList const * InsetText::completionList(Cursor const & cur) const
 {
        if (!completionSupported(cur))
-               return CompletionListPtr();
+               return 0;
 
-       return CompletionListPtr(new TextCompletionList(cur));
+       return new TextCompletionList(cur);
 }
 
 
index 94b3baebc21730523bc0cd168d2ffab3cee5e25a..ccb7301474e953025e62e096d8528bcb35f96388 100644 (file)
@@ -150,7 +150,7 @@ public:
        ///
        bool automaticPopupCompletion() const;
        ///
-       CompletionListPtr completionList(Cursor const & cur) const;
+       CompletionList const * completionList(Cursor const & cur) const;
        ///
        docstring completionPrefix(Cursor const & cur) const;
        ///
index 30e82c5b67f60f34fd6e14536952bf4b509f22d3..14ec77cfd005027bae184ba56c065c7baeee7d88 100644 (file)
@@ -58,7 +58,6 @@
 #include "support/docstream.h"
 
 #include <algorithm>
-#include <deque>
 #include <sstream>
 
 using namespace std;
@@ -1612,12 +1611,12 @@ bool InsetMathNest::automaticPopupCompletion() const
 }
 
 
-Inset::CompletionListPtr InsetMathNest::completionList(Cursor const & cur) const
+Inset::CompletionList const * InsetMathNest::completionList(Cursor const & cur) const
 {
        if (!cur.inMacroMode())
-               return CompletionListPtr();
+               return 0;
        
-       return CompletionListPtr(new MathCompletionList(cur));
+       return new MathCompletionList(cur);
 }
 
 
@@ -1805,20 +1804,17 @@ MathCompletionList::~MathCompletionList()
 
 size_type MathCompletionList::size() const
 {
-       return favorites.size() + locals.size() + globals.size();
+       return locals.size() + globals.size();
 }
 
 
 docstring MathCompletionList::data(size_t idx) const
 {
-       size_t fsize = favorites.size();
        size_t lsize = locals.size();
-       if (idx >= fsize + lsize)
-               return globals[idx - lsize - fsize];
-       else if (idx >= fsize)
-               return locals[idx - fsize];
+       if (idx >= lsize)
+               return globals[idx - lsize];
        else
-               return favorites[idx];
+               return locals[idx];
 }
 
 
@@ -1826,39 +1822,16 @@ std::string MathCompletionList::icon(size_t idx) const
 {
        // get the latex command
        docstring cmd;
-       size_t fsize = favorites.size();
        size_t lsize = locals.size();
-       if (idx >= fsize + lsize)
-               cmd = globals[idx - lsize - fsize];
-       else if (idx >= fsize)
-               cmd = locals[idx - fsize];
+       if (idx >= lsize)
+               cmd = globals[idx - lsize];
        else
-               cmd = favorites[idx];
+               cmd = locals[idx];
        
        // get the icon resource name by stripping the backslash
        return "images/math/" + to_utf8(cmd.substr(1)) + ".png";
 }
 
-
-
-void MathCompletionList::addToFavorites(docstring const & completion)
-{
-       // remove old occurrence
-       std::deque<docstring>::iterator it;
-       for (it = favorites.begin(); it != favorites.end(); ++it) {
-               if (*it == completion) {
-                       favorites.erase(it);
-                       break;
-               }
-       }
-
-       // put it to the front
-       favorites.push_front(completion);
-       favorites.resize(min(int(favorites.size()), 10));
-}
-
-
 std::vector<docstring> MathCompletionList::globals;
-std::deque<docstring> MathCompletionList::favorites;
 
 } // namespace lyx
index 3d990b273921b63d579d9995f6e98be4b2cb5dbc..d164fe752558e9ed3d5ec131c14a75f3ebc3f434 100644 (file)
@@ -14,8 +14,6 @@
 
 #include "InsetMath.h"
 
-#include <deque>
-
 namespace lyx {
 
 class MathCompletionList : public Inset::CompletionList {
@@ -40,8 +38,6 @@ private:
        static std::vector<docstring> globals;
        ///
        std::vector<docstring> locals;
-       ///
-       static std::deque<docstring> favorites;
 };
 
 /** Abstract base class for all math objects that contain nested items.
@@ -146,7 +142,7 @@ public:
        ///
        bool automaticPopupCompletion() const;
        ///
-       CompletionListPtr completionList(Cursor const & cur) const;
+       CompletionList const * completionList(Cursor const & cur) const;
        ///
        docstring completionPrefix(Cursor const & cur) const;
        ///
index 3d84c65e9c7f201ade563bf2a2b14cb16f6ddbbc..821ba2326d7027044e3ad65a5b6d6f1d5fe010be 100644 (file)
@@ -763,12 +763,12 @@ bool MathMacro::automaticPopupCompletion() const
 }
 
 
-Inset::CompletionListPtr MathMacro::completionList(Cursor const & cur) const
+Inset::CompletionList const * MathMacro::completionList(Cursor const & cur) const
 {
        if (displayMode() != DISPLAY_UNFOLDED)
                return InsetMathNest::completionList(cur);
 
-       return CompletionListPtr(new MathCompletionList(cur.bv().cursor()));
+       return new MathCompletionList(cur.bv().cursor());
 }
 
 
index b74d383033943fcc92b1acba2c66c3cf5b05f760..e0567a6468bbf327b58c75561133aed08350e4d3 100644 (file)
@@ -186,7 +186,7 @@ public:
        ///
        bool automaticPopupCompletion() const;
        ///
-       CompletionListPtr completionList(Cursor const & cur) const;
+       CompletionList const * completionList(Cursor const & cur) const;
        ///
        docstring completionPrefix(Cursor const & cur) const;
        ///