Fix slowness issue with Clipboard. Cache the Clipboard status when the data is changed.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20617 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-09-30 20:28:15 +00:00
parent dba88f4ae6
commit e3e83d1c65
3 changed files with 36 additions and 5 deletions

View File

@ -36,6 +36,15 @@ static char const * const mime_type = "application/x-lyx";
namespace lyx {
namespace frontend {
GuiClipboard::GuiClipboard()
{
connect(qApp->clipboard(), SIGNAL(dataChanged()),
this, SLOT(on_dataChanged()));
// initialize clipboard status.
on_dataChanged()
}
string const GuiClipboard::getAsLyX() const
{
LYXERR(Debug::ACTION) << "GuiClipboard::getAsLyX(): `";
@ -110,16 +119,27 @@ bool GuiClipboard::isInternal() const
}
void GuiClipboard::on_dataChanged()
{
text_clipboard_empty_ = qApp->clipboard()->
text(QClipboard::Clipboard).isEmpty();
has_lyx_contents_ = hasLyXContents();
}
bool GuiClipboard::empty() const
{
// We need to check both the plaintext and the LyX version of the
// clipboard. The plaintext version is empty if the LyX version
// contains only one inset, and the LyX version is empry if the
// contains only one inset, and the LyX version is empty if the
// clipboard does not come from LyX.
if (!qApp->clipboard()->text(QClipboard::Clipboard).isEmpty())
if (!text_clipboard_empty_)
return false;
return !hasLyXContents();
return !has_lyx_contents_;
}
} // namespace frontend
} // namespace lyx
#include "GuiClipboard_moc.cpp"

View File

@ -16,15 +16,19 @@
#include "frontends/Clipboard.h"
#include <QObject>
namespace lyx {
namespace frontend {
/**
* The Qt4 version of the Clipboard.
*/
class GuiClipboard : public Clipboard
class GuiClipboard: public QObject, public Clipboard
{
Q_OBJECT
public:
GuiClipboard();
virtual ~GuiClipboard() {}
/** Clipboard overloaded methods
@ -37,6 +41,13 @@ public:
bool isInternal() const;
bool empty() const;
//@}
private Q_SLOTS:
void on_dataChanged();
private:
bool text_clipboard_empty_;
bool has_lyx_contents_;
};
} // namespace frontend

View File

@ -117,7 +117,6 @@ SOURCEFILES = \
NOMOCHEADER = \
ButtonController.h \
GuiClipboard.h \
GuiFontLoader.h \
GuiFontMetrics.h \
GuiSelection.h \
@ -143,6 +142,7 @@ MOCHEADER = \
GuiChanges.h \
GuiCharacter.h \
GuiCitation.h \
GuiClipboard.h \
GuiCommandBuffer.h \
GuiCommandEdit.h \
GuiDelimiter.h \