Potentially fix slowness issue with Selection. Cache the Selection status when the data is changed.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20622 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-10-01 08:18:14 +00:00
parent bb62da8d11
commit 16f4f20fca
3 changed files with 34 additions and 4 deletions

View File

@ -30,6 +30,16 @@ using std::endl;
namespace lyx {
namespace frontend {
GuiSelection::GuiSelection()
: selection_supported_(qApp->clipboard()->supportsSelection())
{
connect(qApp->clipboard(), SIGNAL(dataChanged()),
this, SLOT(on_dataChanged()));
// initialize clipboard status.
on_dataChanged();
}
void GuiSelection::haveSelection(bool own)
{
if (!qApp->clipboard()->supportsSelection())
@ -78,13 +88,22 @@ void GuiSelection::put(docstring const & str)
}
void GuiSelection::on_dataChanged()
{
text_selection_empty_ = qApp->clipboard()->
text(QClipboard::Selection).isEmpty();
}
bool GuiSelection::empty() const
{
if (!qApp->clipboard()->supportsSelection())
if (!selection_supported_)
return true;
return qApp->clipboard()->text(QClipboard::Selection).isEmpty();
return text_selection_empty_;
}
} // namespace frontend
} // namespace lyx
#include "GuiSelection_moc.cpp"

View File

@ -16,15 +16,19 @@
#include "frontends/Selection.h"
#include <QObject>
namespace lyx {
namespace frontend {
/**
* The Qt4 version of the Selection.
*/
class GuiSelection : public Selection
class GuiSelection : public QObject, public Selection
{
Q_OBJECT
public:
GuiSelection();
virtual ~GuiSelection() {}
/** Selection overloaded methods
@ -35,6 +39,13 @@ public:
void put(docstring const & str);
bool empty() const;
//@}
private Q_SLOTS:
void on_dataChanged();
private:
bool text_selection_empty_;
bool const selection_supported_;
};
} // namespace frontend

View File

@ -119,7 +119,6 @@ NOMOCHEADER = \
ButtonController.h \
GuiFontLoader.h \
GuiFontMetrics.h \
GuiSelection.h \
GuiImage.h \
GuiPainter.h \
qt_helpers.h
@ -171,6 +170,7 @@ MOCHEADER = \
GuiPrint.h \
GuiRef.h \
GuiSearch.h \
GuiSelection.h \
GuiSelectionManager.h \
GuiSendto.h \
GuiSetBorder.h \