mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 18:24:48 +00:00
* 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:
parent
45bcfce52d
commit
6eb72bd1f2
@ -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_);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
///
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
///
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user