From 4f0019dfd775bb701cb7e84a283717f7b210ff30 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Tue, 16 Sep 2003 15:34:39 +0000 Subject: [PATCH] Separate interface from implementation; make GraphicsImage's pure virtual functions private. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7775 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt2/ChangeLog | 5 ++ src/frontends/qt2/QLImage.C | 16 ++-- src/frontends/qt2/QLImage.h | 34 +++----- src/frontends/xforms/ChangeLog | 5 ++ src/frontends/xforms/xformsImage.C | 34 ++++---- src/frontends/xforms/xformsImage.h | 39 ++++----- src/graphics/ChangeLog | 5 ++ src/graphics/GraphicsImage.h | 125 +++++++++++++++++++++++++---- 8 files changed, 180 insertions(+), 83 deletions(-) diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 0b555dcc0a..0e0bef6cee 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,8 @@ +2003-09-16 Angus Leeming + + * QLImage.[Ch]: separate interface from implementation. Make all the virtual + functions private. + 2003-09-16 Angus Leeming * QCharacter.C, QPrefs.C, lyx_gui.C: add #include "LColor.h". diff --git a/src/frontends/qt2/QLImage.C b/src/frontends/qt2/QLImage.C index 5ccb39d2ea..7b7d246f8b 100644 --- a/src/frontends/qt2/QLImage.C +++ b/src/frontends/qt2/QLImage.C @@ -113,25 +113,25 @@ QLImage::~QLImage() } -Image * QLImage::clone() const +Image * QLImage::clone_impl() const { return new QLImage(*this); } -unsigned int QLImage::getWidth() const +unsigned int QLImage::getWidth_impl() const { return xformed_pixmap_.width(); } -unsigned int QLImage::getHeight() const +unsigned int QLImage::getHeight_impl() const { return xformed_pixmap_.height(); } -void QLImage::load(string const & filename) +void QLImage::load_impl(string const & filename) { if (!pixmap_.isNull()) { lyxerr[Debug::GRAPHICS] @@ -151,7 +151,7 @@ void QLImage::load(string const & filename) } -bool QLImage::setPixmap(Params const & params) +bool QLImage::setPixmap_impl(Params const & params) { if (pixmap_.isNull() || params.display == NoDisplay) return false; @@ -185,7 +185,7 @@ bool QLImage::setPixmap(Params const & params) } -void QLImage::clip(Params const & params) +void QLImage::clip_impl(Params const & params) { if (xformed_pixmap_.isNull()) return; @@ -219,7 +219,7 @@ void QLImage::clip(Params const & params) } -void QLImage::rotate(Params const & params) +void QLImage::rotate_impl(Params const & params) { if (xformed_pixmap_.isNull()) return; @@ -236,7 +236,7 @@ void QLImage::rotate(Params const & params) } -void QLImage::scale(Params const & params) +void QLImage::scale_impl(Params const & params) { if (xformed_pixmap_.isNull()) return; diff --git a/src/frontends/qt2/QLImage.h b/src/frontends/qt2/QLImage.h index 9885bbc840..b4d1a1684c 100644 --- a/src/frontends/qt2/QLImage.h +++ b/src/frontends/qt2/QLImage.h @@ -30,45 +30,37 @@ public: static FormatList loadableFormats(); ~QLImage(); - - /// Create a copy - virtual Image * clone() const; - QPixmap const & qpixmap() const { return xformed_pixmap_; } +private: + /// Create a copy + virtual Image * clone_impl() const; /// Get the image width - virtual unsigned int getWidth() const; - + virtual unsigned int getWidth_impl() const; /// Get the image height - virtual unsigned int getHeight() const; - - // FIXME - virtual bool isDrawable() const { return true; } - + virtual unsigned int getHeight_impl() const; + // FIXME Is the image drawable ? + virtual bool isDrawable_impl() const { return true; } /** * Load the image file into memory. * The process is asynchronous, so this method starts the loading. * When finished, the Image::finishedLoading signal is emitted. */ - virtual void load(string const & filename); - + virtual void load_impl(string const & filename); /** * Generate the pixmap, based on the current state of * image_ (clipped, rotated, scaled etc). * Uses the params to decide on color, grayscale etc. * Returns true if the pixmap is created. */ - virtual bool setPixmap(Params const & params); - + virtual bool setPixmap_impl(Params const & params); /// Clip the image using params. - virtual void clip(Params const & params); - + virtual void clip_impl(Params const & params); /// Rotate the image using params. - virtual void rotate(Params const & params); - + virtual void rotate_impl(Params const & params); /// Scale the image using params. - virtual void scale(Params const & params); -private: + virtual void scale_impl(Params const & params); + /// Access to the class is through newImage() and clone. QLImage(); /// diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 957601669d..cb3b3440a8 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,8 @@ +2003-09-16 Angus Leeming + + * xformsImage.[Ch]: separate interface from implementation. Make all the virtual + functions private. + 2003-09-16 Lars Gullik Bjønnes * lyx_gui.C: use namespace alias for lyx::support::os diff --git a/src/frontends/xforms/xformsImage.C b/src/frontends/xforms/xformsImage.C index fb24938330..1646ea034a 100644 --- a/src/frontends/xforms/xformsImage.C +++ b/src/frontends/xforms/xformsImage.C @@ -151,13 +151,21 @@ xformsImage::~xformsImage() } -Image * xformsImage::clone() const +Pixmap xformsImage::getPixmap() const +{ + if (!pixmap_status_ == PIXMAP_SUCCESS) + return 0; + return pixmap_; +} + + +Image * xformsImage::clone_impl() const { return new xformsImage(*this); } -unsigned int xformsImage::getWidth() const +unsigned int xformsImage::getWidth_impl() const { if (!image_) return 0; @@ -166,7 +174,7 @@ unsigned int xformsImage::getWidth() const } -unsigned int xformsImage::getHeight() const +unsigned int xformsImage::getHeight_impl() const { if (!image_) return 0; @@ -174,21 +182,13 @@ unsigned int xformsImage::getHeight() const } -bool xformsImage::isDrawable() const +bool xformsImage::isDrawable_impl() const { return pixmap_; } -Pixmap xformsImage::getPixmap() const -{ - if (!pixmap_status_ == PIXMAP_SUCCESS) - return 0; - return pixmap_; -} - - -void xformsImage::load(string const & filename) +void xformsImage::load_impl(string const & filename) { if (image_) { lyxerr[Debug::GRAPHICS] @@ -216,7 +216,7 @@ void xformsImage::load(string const & filename) } -bool xformsImage::setPixmap(Params const & params) +bool xformsImage::setPixmap_impl(Params const & params) { if (!image_ || params.display == NoDisplay) return false; @@ -263,7 +263,7 @@ bool xformsImage::setPixmap(Params const & params) } -void xformsImage::clip(Params const & params) +void xformsImage::clip_impl(Params const & params) { if (!image_) return; @@ -301,7 +301,7 @@ void xformsImage::clip(Params const & params) } -void xformsImage::rotate(Params const & params) +void xformsImage::rotate_impl(Params const & params) { if (!image_) return ; @@ -327,7 +327,7 @@ void xformsImage::rotate(Params const & params) } -void xformsImage::scale(Params const & params) +void xformsImage::scale_impl(Params const & params) { if (!image_) return; diff --git a/src/frontends/xforms/xformsImage.h b/src/frontends/xforms/xformsImage.h index ebf3481ce3..4ee651894f 100644 --- a/src/frontends/xforms/xformsImage.h +++ b/src/frontends/xforms/xformsImage.h @@ -38,49 +38,42 @@ public: /// ~xformsImage(); - - /// Create a copy - Image * clone() const; - /// Pixmap getPixmap() const; - /// Get the image width - unsigned int getWidth() const; + /// Internal callbacks. + void statusCB(string const &); + void errorCB(string const &); +private: + /// Create a copy + virtual Image * clone_impl() const; + /// Get the image width + virtual unsigned int getWidth_impl() const; /// Get the image height - unsigned int getHeight() const; - - virtual bool isDrawable() const; - + virtual unsigned int getHeight_impl() const; + /// Is the image drawable ? + virtual bool isDrawable_impl() const; /** Load the image file into memory. * The process is asynchronous, so this method starts the loading. * When finished, the Image::finishedLoading signal is emitted. */ - void load(string const & filename); - + virtual void load_impl(string const & filename); /** Generate the pixmap, based on the current state of * image_ (clipped, rotated, scaled etc). * Uses the params to decide on color, grayscale etc. * Returns true if the pixmap is created. */ - bool setPixmap(Params const & params); - + bool setPixmap_impl(Params const & params); /// Clip the image using params. - void clip(Params const & params); + virtual void clip_impl(Params const & params); /// Rotate the image using params. - void rotate(Params const & params); + virtual void rotate_impl(Params const & params); /// Scale the image using params. - void scale(Params const & params); - - /// Internal callbacks. - void statusCB(string const &); - /// - void errorCB(string const &); + virtual void scale_impl(Params const & params); -private: /// Access to the class is through newImage() and clone. xformsImage(); /// diff --git a/src/graphics/ChangeLog b/src/graphics/ChangeLog index 791b8fa5db..ca84c77669 100644 --- a/src/graphics/ChangeLog +++ b/src/graphics/ChangeLog @@ -1,3 +1,8 @@ +2003-09-16 Angus Leeming + + * GraphicsImage.h: separate interface from implementation. Make all the + pure virtual functions private. + 2003-09-16 Angus Leeming * PreviewLoader.C: add #include "LColor.h". diff --git a/src/graphics/GraphicsImage.h b/src/graphics/GraphicsImage.h index ec39bc1b5a..7200a8ce34 100644 --- a/src/graphics/GraphicsImage.h +++ b/src/graphics/GraphicsImage.h @@ -52,24 +52,20 @@ public: /// static boost::function0 loadableFormats; - /// Must define default c-tor explicitly as we define a copy c-tor. - Image() {} - /// Don't copy the signal finishedLoading - Image(Image const &) {} /// virtual ~Image() {} /// Create a copy - virtual Image * clone() const = 0; + Image * clone() const; /// Get the image width - virtual unsigned int getWidth() const = 0; + unsigned int getWidth() const; /// Get the image height - virtual unsigned int getHeight() const = 0; + unsigned int getHeight() const; - /// is the image drawable ? - virtual bool isDrawable() const = 0; + /// Is the image drawable ? + bool isDrawable() const; /** At the end of the loading process inform the outside world * by emitting a signal. @@ -82,32 +78,133 @@ public: * The caller should expect this process to be asynchronous and * so should connect to the "finished" signal above. */ - virtual void load(string const & filename) = 0; + void load(string const & filename); /** Generate the pixmap. * Uses the params to decide on color, grayscale etc. * Returns true if the pixmap is created. */ - virtual bool setPixmap(Params const & params) = 0; + bool setPixmap(Params const & params); /// Clip the image using params. - virtual void clip(Params const & params) = 0; + void clip(Params const & params); /// Rotate the image using params. - virtual void rotate(Params const & params) = 0; + void rotate(Params const & params); /// Scale the image using params. - virtual void scale(Params const & params) = 0; + void scale(Params const & params); protected: + /// Must define default c-tor explicitly as we define a copy c-tor. + Image() {} + /// Don't copy the signal finishedLoading + Image(Image const &) {} + /** Uses the params to ascertain the dimensions of the scaled image. * Returned as make_pair(width, height). * If something goes wrong, returns make_pair(getWidth(), getHeight()) */ std::pair getScaledDimensions(Params const & params) const; + +private: + /// Create a copy + virtual Image * clone_impl() const = 0; + /// Get the image width + virtual unsigned int getWidth_impl() const = 0; + + /// Get the image height + virtual unsigned int getHeight_impl() const = 0; + + /// is the image drawable ? + virtual bool isDrawable_impl() const = 0; + + /** Start loading the image file. + * The caller should expect this process to be asynchronous and + * so should connect to the "finished" signal above. + */ + virtual void load_impl(string const & filename) = 0; + + /** Generate the pixmap. + * Uses the params to decide on color, grayscale etc. + * Returns true if the pixmap is created. + */ + virtual bool setPixmap_impl(Params const & params) = 0; + + /// Clip the image using params. + virtual void clip_impl(Params const & params) = 0; + + /// Rotate the image using params. + virtual void rotate_impl(Params const & params) = 0; + + /// Scale the image using params. + virtual void scale_impl(Params const & params) = 0; }; + +inline +Image * Image::clone() const +{ + return clone_impl(); +} + + +inline +unsigned int Image::getWidth() const +{ + return getWidth_impl(); +} + + +inline +unsigned int Image::getHeight() const +{ + return getHeight_impl(); +} + + +inline +bool Image::isDrawable() const +{ + return isDrawable_impl(); +} + + +inline +void Image::load(string const & filename) +{ + return load_impl(filename); +} + + +inline +bool Image::setPixmap(Params const & params) +{ + return setPixmap_impl(params); +} + + +inline +void Image::clip(Params const & params) +{ + return clip_impl(params); +} + + +inline +void Image::rotate(Params const & params) +{ + return rotate_impl(params); +} + + +inline +void Image::scale(Params const & params) +{ + return scale_impl(params); +} + } // namespace graphics } // namespace lyx -- 2.39.2