* Reduce compilation time by removing the shared_ptr (which is not

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
This commit is contained in:
Stefan Schimanski 2008-02-21 23:36:02 +00:00
parent 45bcfce52d
commit 6eb72bd1f2
8 changed files with 33 additions and 61 deletions

View File

@ -72,8 +72,11 @@ protected:
class GuiCompletionModel : public QAbstractListModel { class GuiCompletionModel : public QAbstractListModel {
public: public:
/// ///
GuiCompletionModel(QObject * parent, Inset::CompletionListPtr l) GuiCompletionModel(QObject * parent, Inset::CompletionList const * l)
: QAbstractListModel(parent), list(l) {} : QAbstractListModel(parent), list_(l) {}
///
~GuiCompletionModel()
{ delete list_; }
/// ///
int columnCount(const QModelIndex & /*parent*/ = QModelIndex()) const int columnCount(const QModelIndex & /*parent*/ = QModelIndex()) const
{ {
@ -82,16 +85,16 @@ public:
/// ///
int rowCount(const QModelIndex & /*parent*/ = QModelIndex()) const int rowCount(const QModelIndex & /*parent*/ = QModelIndex()) const
{ {
if (list.get() == 0) if (list_ == 0)
return 0; return 0;
else else
return list->size(); return list_->size();
} }
/// ///
QVariant data(const QModelIndex & index, int role) const QVariant data(const QModelIndex & index, int role) const
{ {
if (list.get() == 0) if (list_ == 0)
return QVariant(); return QVariant();
if (index.row() < 0 || index.row() >= rowCount()) if (index.row() < 0 || index.row() >= rowCount())
@ -101,11 +104,11 @@ public:
return QVariant(); return QVariant();
if (index.column() == 0) if (index.column() == 0)
return toqstr(list->data(index.row())); return toqstr(list_->data(index.row()));
else if (index.column() == 1) { else if (index.column() == 1) {
// get icon from cache // get icon from cache
QPixmap scaled; QPixmap scaled;
QString const name = ":" + toqstr(list->icon(index.row())); QString const name = ":" + toqstr(list_->icon(index.row()));
if (!QPixmapCache::find("completion" + name, scaled)) { if (!QPixmapCache::find("completion" + name, scaled)) {
// load icon from disk // load icon from disk
QPixmap p = QPixmap(name); QPixmap p = QPixmap(name);
@ -125,7 +128,7 @@ public:
private: private:
/// ///
Inset::CompletionListPtr list; Inset::CompletionList const * list_;
}; };
@ -133,7 +136,7 @@ GuiCompleter::GuiCompleter(GuiWorkArea * gui, QObject * parent)
: QCompleter(parent), gui_(gui), updateLock_(0) : QCompleter(parent), gui_(gui), updateLock_(0)
{ {
// Setup the completion popup // Setup the completion popup
setModel(new GuiCompletionModel(this, Inset::CompletionListPtr())); setModel(new GuiCompletionModel(this, 0));
setCompletionMode(QCompleter::PopupCompletion); setCompletionMode(QCompleter::PopupCompletion);
setWidget(gui_); setWidget(gui_);

View File

@ -297,7 +297,6 @@ public:
/// returns the resource string used to load an icon. /// returns the resource string used to load an icon.
virtual std::string icon(size_t /*idx*/) const { return std::string(); } virtual std::string icon(size_t /*idx*/) const { return std::string(); }
}; };
typedef boost::shared_ptr<CompletionList> CompletionListPtr;
/// Returns true if the inset supports completions. /// Returns true if the inset supports completions.
virtual bool completionSupported(Cursor const &) const { return false; } virtual bool completionSupported(Cursor const &) const { return false; }
@ -312,8 +311,9 @@ public:
virtual bool automaticPopupCompletion() const { return true; } virtual bool automaticPopupCompletion() const { return true; }
/// Returns completion suggestions at cursor position. Return an /// Returns completion suggestions at cursor position. Return an
/// null pointer if no completion is a available or possible. /// null pointer if no completion is a available or possible.
virtual CompletionListPtr completionList(Cursor const &) const /// The caller is responsible to free the return object!
{ return CompletionListPtr(); } virtual CompletionList const * completionList(Cursor const &) const
{ return 0; }
/// Returns the completion prefix to filter the suggestions for completion. /// Returns the completion prefix to filter the suggestions for completion.
/// This is only called if completionList returned a non-null list. /// This is only called if completionList returned a non-null list.
virtual docstring completionPrefix(Cursor const &) const virtual docstring completionPrefix(Cursor const &) const

View 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)) if (!completionSupported(cur))
return CompletionListPtr(); return 0;
return CompletionListPtr(new TextCompletionList(cur)); return new TextCompletionList(cur);
} }

View File

@ -150,7 +150,7 @@ public:
/// ///
bool automaticPopupCompletion() const; bool automaticPopupCompletion() const;
/// ///
CompletionListPtr completionList(Cursor const & cur) const; CompletionList const * completionList(Cursor const & cur) const;
/// ///
docstring completionPrefix(Cursor const & cur) const; docstring completionPrefix(Cursor const & cur) const;
/// ///

View File

@ -58,7 +58,6 @@
#include "support/docstream.h" #include "support/docstream.h"
#include <algorithm> #include <algorithm>
#include <deque>
#include <sstream> #include <sstream>
using namespace std; 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()) 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 size_type MathCompletionList::size() const
{ {
return favorites.size() + locals.size() + globals.size(); return locals.size() + globals.size();
} }
docstring MathCompletionList::data(size_t idx) const docstring MathCompletionList::data(size_t idx) const
{ {
size_t fsize = favorites.size();
size_t lsize = locals.size(); size_t lsize = locals.size();
if (idx >= fsize + lsize) if (idx >= lsize)
return globals[idx - lsize - fsize]; return globals[idx - lsize];
else if (idx >= fsize)
return locals[idx - fsize];
else else
return favorites[idx]; return locals[idx];
} }
@ -1826,39 +1822,16 @@ std::string MathCompletionList::icon(size_t idx) const
{ {
// get the latex command // get the latex command
docstring cmd; docstring cmd;
size_t fsize = favorites.size();
size_t lsize = locals.size(); size_t lsize = locals.size();
if (idx >= fsize + lsize) if (idx >= lsize)
cmd = globals[idx - lsize - fsize]; cmd = globals[idx - lsize];
else if (idx >= fsize)
cmd = locals[idx - fsize];
else else
cmd = favorites[idx]; cmd = locals[idx];
// get the icon resource name by stripping the backslash // get the icon resource name by stripping the backslash
return "images/math/" + to_utf8(cmd.substr(1)) + ".png"; 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::vector<docstring> MathCompletionList::globals;
std::deque<docstring> MathCompletionList::favorites;
} // namespace lyx } // namespace lyx

View File

@ -14,8 +14,6 @@
#include "InsetMath.h" #include "InsetMath.h"
#include <deque>
namespace lyx { namespace lyx {
class MathCompletionList : public Inset::CompletionList { class MathCompletionList : public Inset::CompletionList {
@ -40,8 +38,6 @@ private:
static std::vector<docstring> globals; static std::vector<docstring> globals;
/// ///
std::vector<docstring> locals; std::vector<docstring> locals;
///
static std::deque<docstring> favorites;
}; };
/** Abstract base class for all math objects that contain nested items. /** Abstract base class for all math objects that contain nested items.
@ -146,7 +142,7 @@ public:
/// ///
bool automaticPopupCompletion() const; bool automaticPopupCompletion() const;
/// ///
CompletionListPtr completionList(Cursor const & cur) const; CompletionList const * completionList(Cursor const & cur) const;
/// ///
docstring completionPrefix(Cursor const & cur) const; docstring completionPrefix(Cursor const & cur) const;
/// ///

View 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) if (displayMode() != DISPLAY_UNFOLDED)
return InsetMathNest::completionList(cur); return InsetMathNest::completionList(cur);
return CompletionListPtr(new MathCompletionList(cur.bv().cursor())); return new MathCompletionList(cur.bv().cursor());
} }

View File

@ -186,7 +186,7 @@ public:
/// ///
bool automaticPopupCompletion() const; bool automaticPopupCompletion() const;
/// ///
CompletionListPtr completionList(Cursor const & cur) const; CompletionList const * completionList(Cursor const & cur) const;
/// ///
docstring completionPrefix(Cursor const & cur) const; docstring completionPrefix(Cursor const & cur) const;
/// ///