From: Abdelrazak Younes Date: Mon, 1 Oct 2007 08:18:14 +0000 (+0000) Subject: Potentially fix slowness issue with Selection. Cache the Selection status when the... X-Git-Tag: 1.6.10~8101 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=16f4f20fcaac89ceb3b487b962f01b010ccada70;p=features.git 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 --- diff --git a/src/frontends/qt4/GuiSelection.cpp b/src/frontends/qt4/GuiSelection.cpp index f4d9051148..29cb8951e7 100644 --- a/src/frontends/qt4/GuiSelection.cpp +++ b/src/frontends/qt4/GuiSelection.cpp @@ -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" diff --git a/src/frontends/qt4/GuiSelection.h b/src/frontends/qt4/GuiSelection.h index d1fa749a8d..7e77da715a 100644 --- a/src/frontends/qt4/GuiSelection.h +++ b/src/frontends/qt4/GuiSelection.h @@ -16,15 +16,19 @@ #include "frontends/Selection.h" +#include + 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 diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index 26f410cacd..4f9ebf6b1d 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -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 \