Remove the inset and view member functions from PreviewedInset.

Ensuing changes elsewhere.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7887 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-10-09 19:27:07 +00:00
parent 8ddfa9d784
commit 97a1af408e
13 changed files with 115 additions and 95 deletions

View File

@ -1,3 +1,11 @@
2003-10-09 Angus Leeming <leeming@lyx.org>
* PreviewedInset.[Ch]: move PreviewedInset out of namespace lyx::graphics.
Remove the inset and view member functions.
Add a new connect member function and preview_ready_signal_ member
variable, to enable the class to tell an arbirary connectee that the
preview is ready.
2003-10-09 Angus Leeming <leeming@lyx.org>
* PreviewedInset.[Ch] (removePreview, previewReady): these functions

View File

@ -15,53 +15,47 @@
#include "PreviewLoader.h"
#include "Previews.h"
#include "BufferView.h"
#include "insets/inset.h"
#include "support/lstrings.h"
#include <boost/bind.hpp>
namespace graphics = lyx::graphics;
namespace support = lyx::support;
namespace lyx {
namespace graphics {
bool PreviewedInset::activated()
{
return Previews::activated();
return graphics::Previews::activated();
}
PreviewedInset::PreviewedInset(InsetOld & inset)
: inset_(inset), pimage_(0)
PreviewedInset::PreviewedInset()
: pimage_(0)
{}
BufferView * PreviewedInset::view() const
boost::signals::connection PreviewedInset::connect(slot_type const & slot)
{
return inset_.view();
return preview_ready_signal_.connect(slot);
}
void PreviewedInset::generatePreview(Buffer const & buffer)
{
if (!Previews::activated() || !previewWanted(buffer))
if (!activated() || !previewWanted(buffer))
return;
Previews & previews = Previews::get();
PreviewLoader & loader = previews.loader(buffer);
graphics::Previews & previews = graphics::Previews::get();
graphics::PreviewLoader & loader = previews.loader(buffer);
addPreview(loader);
if (!snippet_.empty())
loader.startLoading();
}
void PreviewedInset::addPreview(PreviewLoader & ploader)
void PreviewedInset::addPreview(graphics::PreviewLoader & ploader)
{
if (!Previews::activated() || !previewWanted(ploader.buffer()))
if (!activated() || !previewWanted(ploader.buffer()))
return;
snippet_ = support::trim(latexString(ploader.buffer()));
@ -89,8 +83,8 @@ void PreviewedInset::removePreview(Buffer const & buffer)
if (snippet_.empty())
return;
Previews & previews = Previews::get();
PreviewLoader & loader = previews.loader(buffer);
graphics::Previews & previews = graphics::Previews::get();
graphics::PreviewLoader & loader = previews.loader(buffer);
loader.remove(snippet_);
snippet_.erase();
pimage_ = 0;
@ -99,11 +93,12 @@ void PreviewedInset::removePreview(Buffer const & buffer)
bool PreviewedInset::previewReady(Buffer const & buffer) const
{
if (!Previews::activated() || !previewWanted(buffer))
if (!activated() || !previewWanted(buffer))
return false;
if (!pimage_ || snippet_ != pimage_->snippet()) {
PreviewLoader & ploader = Previews::get().loader(buffer);
graphics::PreviewLoader & ploader =
graphics::Previews::get().loader(buffer);
pimage_ = ploader.preview(snippet_);
}
@ -111,17 +106,12 @@ bool PreviewedInset::previewReady(Buffer const & buffer) const
}
void PreviewedInset::imageReady(PreviewImage const & pimage) const
void PreviewedInset::imageReady(graphics::PreviewImage const & pimage) const
{
// Check the current snippet is the same as that previewed.
if (snippet_ != pimage.snippet())
return;
pimage_ = &pimage;
if (view())
view()->updateInset(&inset());
preview_ready_signal_();
}
} // namespace graphics
} // namespace lyx

View File

@ -16,12 +16,12 @@
#ifndef PREVIEWEDINSET_H
#define PREVIEWEDINSET_H
#include <boost/signals/signal0.hpp>
#include <boost/signals/trackable.hpp>
#include <boost/signals/connection.hpp>
class Buffer;
class BufferView;
class InsetOld;
namespace lyx {
@ -30,13 +30,16 @@ namespace graphics {
class PreviewImage;
class PreviewLoader;
} // namespace graphics
} // namespace lyx
class PreviewedInset : public boost::signals::trackable {
public:
/// a wrapper for Previews::activated()
static bool activated();
///
PreviewedInset(InsetOld & inset);
PreviewedInset();
/** Find the PreviewLoader, add a LaTeX snippet to it and
* start the loading process.
@ -46,7 +49,7 @@ public:
/** Add a LaTeX snippet to the PreviewLoader but do not start the
* loading process.
*/
void addPreview(PreviewLoader & ploader);
void addPreview(lyx::graphics::PreviewLoader & ploader);
/** Remove a snippet from the cache of previews.
* Useful if previewing the contents of a file that has changed.
@ -56,54 +59,39 @@ public:
/// The preview has been generated and is ready to use.
bool previewReady(Buffer const &) const;
/// If !previewReady() returns 0.
PreviewImage const * pimage() const;
/// If the preview is not ready, returns 0.
lyx::graphics::PreviewImage const * const pimage() const { return pimage_; }
/// Connect and you'll be informed when the preview is ready.
typedef boost::signal0<void>::slot_type slot_type;
boost::signals::connection connect(slot_type const &);
protected:
///
virtual ~PreviewedInset() {}
/// Allow the daughter classes to cast up to the parent inset.
InsetOld const & inset() const;
///
BufferView * view() const;
private:
/// This method is connected to the PreviewLoader::imageReady signal.
void imageReady(PreviewImage const &) const;
void imageReady(lyx::graphics::PreviewImage const &) const;
/// Does the owning inset want a preview?
virtual bool previewWanted(Buffer const &) const = 0;
/// a wrapper to Inset::latex
virtual std::string const latexString(Buffer const &) const = 0;
///
InsetOld & inset_;
///
/// The thing that we're trying to generate a preview of.
std::string snippet_;
/// We don't own this. Cached for efficiency reasons.
mutable PreviewImage const * pimage_;
mutable lyx::graphics::PreviewImage const * pimage_;
/** Store the connection to the preview loader so that we connect
* only once.
*/
boost::signals::connection ploader_connection_;
/// This signal is emitted when the preview is ready for display.
boost::signal0<void> preview_ready_signal_;
};
inline
PreviewImage const * PreviewedInset::pimage() const
{
return pimage_;
}
inline
InsetOld const & PreviewedInset::inset() const
{
return inset_;
}
} // namespace graphics
} // namespace lyx
#endif // PREVIEWEDINSET_H

View File

@ -1,3 +1,11 @@
2003-10-09 Angus Leeming <leeming@lyx.org>
* insetexternal.[Ch] (statusChanged):
* insetgraphics.[Ch] (statusChanged): make a const member function.
* insetinclude.[Ch]: mods to PreviewImpl due to the changes to
PreviewedInset.
2003-10-09 Angus Leeming <leeming@lyx.org>
* insetinclude.C (metrics, draw, restartLoading): pass a buffer arg

View File

@ -387,7 +387,7 @@ InsetExternal::~InsetExternal()
}
void InsetExternal::statusChanged()
void InsetExternal::statusChanged() const
{
BufferView * const bv = renderer_->view();
if (bv)

View File

@ -131,7 +131,7 @@ private:
/** This method is connected to the graphics loader, so we are
* informed when the image has been loaded.
*/
void statusChanged();
void statusChanged() const;
/// The current params
InsetExternalParams params_;

View File

@ -181,7 +181,7 @@ InsetGraphics::~InsetGraphics()
}
void InsetGraphics::statusChanged()
void InsetGraphics::statusChanged() const
{
BufferView * bv = graphic_->view();
if (bv)

View File

@ -85,7 +85,7 @@ private:
/** This method is connected to the graphics loader, so we are
* informed when the image has been loaded.
*/
void statusChanged();
void statusChanged() const;
/// Read the inset native format
void readInsetGraphics(LyXLex & lex, std::string const & bufpath);

View File

@ -65,20 +65,16 @@ using std::ostringstream;
extern BufferList bufferlist;
class InsetInclude::PreviewImpl : public lyx::graphics::PreviewedInset {
class InsetInclude::PreviewImpl : public PreviewedInset {
public:
///
PreviewImpl(InsetInclude & p) : PreviewedInset(p) {}
PreviewImpl(InsetInclude const & p) : parent_(p) {}
///
bool previewWanted(Buffer const &) const;
///
string const latexString(Buffer const &) const;
///
InsetInclude const & parent() const {
return dynamic_cast<InsetInclude const &>(inset());
}
///
bool monitoring() const { return monitor_.get(); }
///
@ -91,6 +87,8 @@ private:
void restartLoading();
///
boost::scoped_ptr<FileMonitor> monitor_;
///
InsetInclude const & parent_;
};
@ -109,7 +107,9 @@ InsetInclude::InsetInclude(InsetCommandParams const & p)
: params_(p), include_label(uniqueID()),
preview_(new PreviewImpl(*this)),
set_label_(false)
{}
{
preview_->connect(boost::bind(&InsetInclude::statusChanged, this));
}
InsetInclude::InsetInclude(InsetInclude const & other)
@ -118,7 +118,9 @@ InsetInclude::InsetInclude(InsetInclude const & other)
include_label(other.include_label),
preview_(new PreviewImpl(*this)),
set_label_(other.set_label_)
{}
{
preview_->connect(boost::bind(&InsetInclude::statusChanged, this));
}
InsetInclude::~InsetInclude()
@ -210,8 +212,7 @@ void InsetInclude::set(InsetCommandParams const & p, Buffer const & buffer)
if (preview_->monitoring())
preview_->stopMonitoring();
if (lyx::graphics::PreviewedInset::activated() &&
type(params_) == INPUT)
if (PreviewedInset::activated() && type(params_) == INPUT)
preview_->generatePreview(buffer);
}
@ -593,6 +594,13 @@ BufferView * InsetInclude::view() const
// preview stuff
//
void InsetInclude::statusChanged() const
{
if (view())
view()->updateInset(this);
}
void InsetInclude::addPreview(lyx::graphics::PreviewLoader & ploader) const
{
preview_->addPreview(ploader);
@ -601,10 +609,10 @@ void InsetInclude::addPreview(lyx::graphics::PreviewLoader & ploader) const
bool InsetInclude::PreviewImpl::previewWanted(Buffer const & buffer) const
{
string const included_file = includedFilename(buffer, parent().params());
string const included_file = includedFilename(buffer, parent_.params());
return type(parent().params_) == INPUT &&
parent().params_.preview() &&
return type(parent_.params_) == INPUT &&
parent_.params_.preview() &&
IsFileReadable(included_file);
}
@ -614,7 +622,7 @@ string const InsetInclude::PreviewImpl::latexString(Buffer const & buffer) const
ostringstream os;
LatexRunParams runparams;
runparams.flavor = LatexRunParams::LATEX;
parent().latex(buffer, os, runparams);
parent_.latex(buffer, os, runparams);
return os.str();
}
@ -630,11 +638,12 @@ void InsetInclude::PreviewImpl::startMonitoring(string const & file)
void InsetInclude::PreviewImpl::restartLoading()
{
if (!view())
BufferView * const view = parent_.view();
if (!view)
return;
view()->updateInset(&parent());
if (view()->buffer()) {
Buffer const & buffer = *view()->buffer();
view->updateInset(&parent_);
if (view->buffer()) {
Buffer const & buffer = *view->buffer();
removePreview(buffer);
generatePreview(buffer);
}

View File

@ -83,6 +83,9 @@ public:
void addPreview(lyx::graphics::PreviewLoader &) const;
private:
/// Slot receiving a signal that the preview is ready to display.
void statusChanged() const;
friend class InsetIncludeMailer;
/// set the parameters

View File

@ -1,3 +1,8 @@
2003-10-09 Angus Leeming <leeming@lyx.org>
* formula.[Ch]: mods to PreviewImpl due to the changes to
PreviewedInset.
2003-10-09 Angus Leeming <leeming@lyx.org>
* formula.C (metrics, draw): pass a buffer arg to PreviewedInset's

View File

@ -30,6 +30,7 @@
#include "support/std_sstream.h"
#include <boost/bind.hpp>
using std::string;
using std::ostream;
@ -39,10 +40,10 @@ using std::auto_ptr;
using std::endl;
class InsetFormula::PreviewImpl : public lyx::graphics::PreviewedInset {
class InsetFormula::PreviewImpl : public PreviewedInset {
public:
///
PreviewImpl(InsetFormula & p) : PreviewedInset(p) {}
PreviewImpl(InsetFormula const & p) : parent_(p) {}
private:
///
@ -50,18 +51,15 @@ private:
///
string const latexString(Buffer const &) const;
///
InsetFormula const & parent() const
{
return dynamic_cast<InsetFormula const &>(inset());
}
InsetFormula const & parent_;
};
InsetFormula::InsetFormula(bool chemistry)
: par_(MathAtom(new MathHullInset)),
preview_(new PreviewImpl(*this))
{
preview_->connect(boost::bind(&InsetFormula::statusChanged, this));
if (chemistry)
mutate("chemistry");
}
@ -71,14 +69,16 @@ InsetFormula::InsetFormula(InsetFormula const & other)
: InsetFormulaBase(other),
par_(other.par_),
preview_(new PreviewImpl(*this))
{}
{
preview_->connect(boost::bind(&InsetFormula::statusChanged, this));
}
InsetFormula::InsetFormula(BufferView *)
: par_(MathAtom(new MathHullInset)),
preview_(new PreviewImpl(*this))
{
//view_ = bv->owner()->view();
preview_->connect(boost::bind(&InsetFormula::statusChanged, this));
}
@ -86,6 +86,7 @@ InsetFormula::InsetFormula(string const & data)
: par_(MathAtom(new MathHullInset)),
preview_(new PreviewImpl(*this))
{
preview_->connect(boost::bind(&InsetFormula::statusChanged, this));
if (!data.size())
return;
if (!mathed_parse_normal(par_, data))
@ -93,7 +94,6 @@ InsetFormula::InsetFormula(string const & data)
}
InsetFormula::~InsetFormula()
{}
@ -300,6 +300,13 @@ void InsetFormula::mutate(string const & type)
// preview stuff
//
void InsetFormula::statusChanged() const
{
if (view())
view()->updateInset(this);
}
void InsetFormula::addPreview(lyx::graphics::PreviewLoader & ploader) const
{
preview_->addPreview(ploader);
@ -314,7 +321,7 @@ void InsetFormula::generatePreview(Buffer const & buffer) const
bool InsetFormula::PreviewImpl::previewWanted(Buffer const &) const
{
return !parent().par_->asNestInset()->editing();
return !parent_.par_->asNestInset()->editing();
}
@ -322,6 +329,6 @@ string const InsetFormula::PreviewImpl::latexString(Buffer const &) const
{
ostringstream ls;
WriteStream wi(ls, false, false);
parent().par_->write(wi);
parent_.par_->write(wi);
return ls.str();
}

View File

@ -74,6 +74,8 @@ public:
void mutate(std::string const & type);
private:
/// Slot receiving a signal that the preview is ready to display.
void statusChanged() const;
/// available in AMS only?
bool ams() const;