diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2019-04-04 12:43:23 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2019-04-04 12:43:23 +0000 |
| commit | cb4e0f299acf0842db9c185c15158b96c1dacbd2 (patch) | |
| tree | 786288e97f43c54c1e38def95b3c472ed10c5c77 /src | |
| parent | Attempt to fix Mac CI (missing double-conversion) (diff) | |
| download | inkscape-cb4e0f299acf0842db9c185c15158b96c1dacbd2.tar.gz inkscape-cb4e0f299acf0842db9c185c15158b96c1dacbd2.zip | |
Reorganize document.h.
Diffstat (limited to 'src')
| -rw-r--r-- | src/document.cpp | 14 | ||||
| -rw-r--r-- | src/document.h | 374 | ||||
| -rw-r--r-- | src/extension/dbus/document-interface.cpp | 2 | ||||
| -rw-r--r-- | src/io/resource-manager.cpp | 1 |
4 files changed, 228 insertions, 163 deletions
diff --git a/src/document.cpp b/src/document.cpp index 1fc32d8a0..8c6ba7c86 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -218,11 +218,6 @@ SPDocument::~SPDocument() { collectOrphans(); } -sigc::connection SPDocument::connectDestroy(sigc::signal<void>::slot_type slot) -{ - return destroySignal.connect(slot); -} - SPDefs *SPDocument::getDefs() { if (!root) { @@ -974,6 +969,11 @@ void SPDocument::emitResizedSignal(gdouble width, gdouble height) this->resized_signal.emit(width, height); } +sigc::connection SPDocument::connectDestroy(sigc::signal<void>::slot_type slot) +{ + return destroySignal.connect(slot); +} + sigc::connection SPDocument::connectModified(SPDocument::ModifiedSignal::slot_type slot) { return modified_signal.connect(slot); @@ -1868,11 +1868,11 @@ void SPDocument::importDefs(SPDocument *source) prevent_id_clashes(source, this); for (auto & defsNode : defsNodes) { - importDefsNode(source, const_cast<Inkscape::XML::Node *>(defsNode), target_defs); + _importDefsNode(source, const_cast<Inkscape::XML::Node *>(defsNode), target_defs); } } -void SPDocument::importDefsNode(SPDocument *source, Inkscape::XML::Node *defs, Inkscape::XML::Node *target_defs) +void SPDocument::_importDefsNode(SPDocument *source, Inkscape::XML::Node *defs, Inkscape::XML::Node *target_defs) { int stagger=0; diff --git a/src/document.h b/src/document.h index b3fa7da4d..d1d822f2e 100644 --- a/src/document.h +++ b/src/document.h @@ -18,20 +18,25 @@ * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ + #include <cstddef> #include <deque> -#include <set> +#include <map> #include <vector> #include <boost/ptr_container/ptr_list.hpp> -#include <sigc++/sigc++.h> + #include <glibmm/ustring.h> +#include <sigc++/sigc++.h> + #include <2geom/forward.h> #include "3rdparty/libcroco/cr-cascade.h" + #include "event.h" #include "gc-anchored.h" #include "gc-finalized.h" + #include "inkgc/gc-managed.h" #include "composite-undo-stack-observer.h" @@ -60,8 +65,8 @@ namespace Avoid { class Router; } -class SPItem; -class SPObject; +class SPItem; +class SPObject; class SPGroup; class SPRoot; @@ -92,76 +97,82 @@ namespace Proj { /// Typed SVG document implementation. class SPDocument : public Inkscape::GC::Managed<>, - public Inkscape::GC::Finalized, - public Inkscape::GC::Anchored + public Inkscape::GC::Finalized, + public Inkscape::GC::Anchored { + // Note: multiple public and private sections is not a good practice, but happens // in this class as transitional to fixing encapsulation: public: - typedef sigc::signal<void, SPObject *> IDChangedSignal; - typedef sigc::signal<void> ResourcesChangedSignal; - typedef sigc::signal<void, unsigned> ModifiedSignal; - typedef sigc::signal<void, char const *> URISetSignal; - typedef sigc::signal<void, double, double> ResizedSignal; - typedef sigc::signal<void> ReconstructionStart; - typedef sigc::signal<void> ReconstructionFinish; - typedef sigc::signal<void> CommitSignal; + /************ Functions *****************/ + + // Fundamental ------------------------ SPDocument(); ~SPDocument() override; + SPDocument(SPDocument const &) = delete; // no copy + void operator=(SPDocument const &) = delete; // no assign - sigc::connection connectDestroy(sigc::signal<void>::slot_type slot); + // Document creation ------------------ + static SPDocument *createNewDoc(char const*uri, unsigned int keepalive, + bool make_new = false, SPDocument *parent=nullptr ); + static SPDocument *createNewDocFromMem(char const*buffer, int length, unsigned int keepalive); + SPDocument *createChildDoc(std::string const &uri); - unsigned int keepalive : 1; - unsigned int virgin : 1; ///< Has the document never been touched? - unsigned int modified_since_save : 1; + static SPDocument *createDoc(Inkscape::XML::Document *rdoc, char const *uri, + char const *base, char const *name, unsigned int keepalive, + SPDocument *parent); - Inkscape::XML::Document *rdoc; ///< Our Inkscape::XML::Document - Inkscape::XML::Node *rroot; ///< Root element of Inkscape::XML::Document -private: - SPRoot *root; ///< Our SPRoot + // Document status -------------------- + SPDocument *doRef(); + SPDocument *doUnref(); -public: - CRCascade *style_cascade; - CRStyleSheet *style_sheet; + bool isModifiedSinceSave() const { return modified_since_save; } + void setModifiedSinceSave(bool const modified = true); -protected: - char *document_uri; ///< A filename (not a URI yet), or NULL - char *document_base; ///< To be used for resolving relative hrefs. - char *document_name; ///< basename(uri) or other human-readable label for the document. + void requestModified(); + int ensureUpToDate(); -public: + bool addResource(char const *key, SPObject *object); + bool removeResource(char const *key, SPObject *object); + std::vector<SPObject *> const getResourceList(char const *key); - /// Last action key - Glib::ustring actionkey; + void do_change_uri(char const *const filename, bool const rebase); + void changeUriAndHrefs(char const *uri); - /// Handler ID - unsigned modified_id; - - /// Connector rerouting handler ID - unsigned rerouting_handler_id; + bool _updateDocument(); // Used by stand-alone sp_document_idle_handler - Inkscape::ProfileManager* profileManager; +private: + void _importDefsNode(SPDocument *source, Inkscape::XML::Node *defs, Inkscape::XML::Node *target_defs); + +public: + void importDefs(SPDocument *source); - // Instance of the connector router - Avoid::Router *router; + unsigned int vacuumDocument(); - std::vector<SPObject *> _collection_queue; + /******** Getters and Setters **********/ - bool oldSignalsConnected; + // Document structure ----------------- /** Returns our SPRoot */ SPRoot *getRoot() { return root; } SPRoot const *getRoot() const { return root; } + /** Return the main defs object for the document. */ + SPDefs *getDefs(); + Inkscape::XML::Node *getReprRoot() { return rroot; } /** Our Inkscape::XML::Document. */ Inkscape::XML::Document *getReprDoc() { return rdoc; } Inkscape::XML::Document const *getReprDoc() const { return rdoc; } + Glib::ustring getLanguage() const; + + // File information -------------------- + /** A filename (not a URI yet), or NULL */ char const *getDocumentURI() const { return document_uri; } void setDocumentUri(char const *document_uri); @@ -173,65 +184,115 @@ public: /** basename(uri) or other human-readable label for the document. */ char const* getDocumentName() const { return document_name; } - /** Return the main defs object for the document. */ - SPDefs *getDefs(); + // Document geometry ------------------------ + Inkscape::Util::Unit const* getDisplayUnit() const; + void setDocumentScale( const double scaleX, const double scaleY ); + void setDocumentScale( const double scale ); + Geom::Scale getDocumentScale() const; + + void setWidthAndHeight(const Inkscape::Util::Quantity &width, const Inkscape::Util::Quantity &height, bool changeSize=true); + Geom::Point getDimensions() const; + + void setWidth(const Inkscape::Util::Quantity &width, bool changeSize=true); + void setHeight(const Inkscape::Util::Quantity &height, bool changeSize=true); + Inkscape::Util::Quantity getWidth() const; + Inkscape::Util::Quantity getHeight() const; + + void setViewBox(); + void setViewBox(const Geom::Rect &viewBox); + Geom::Rect getViewBox() const; + + Geom::OptRect preferredBounds() const; + void fitToRect(Geom::Rect const &rect, bool with_margins = false); + void setupViewport(SPItemCtx *ctx); + + + // Find items ----------------------------- + void bindObjectToId(char const *id, SPObject *object); + SPObject *getObjectById(Glib::ustring const &id) const; + SPObject *getObjectById(char const *id) const; + + void bindObjectToRepr(Inkscape::XML::Node *repr, SPObject *object); + SPObject *getObjectByRepr(Inkscape::XML::Node *repr) const; + + std::vector<SPObject *> getObjectsByClass(Glib::ustring const &klass) const; + std::vector<SPObject *> getObjectsByElement(Glib::ustring const &element) const; + std::vector<SPObject *> getObjectsBySelector(Glib::ustring const &selector) const; + + + // Find items by geometry -------------------- + void build_flat_item_list(unsigned int dkey, SPGroup *group, gboolean into_groups) const; + + std::vector<SPItem*> getItemsInBox (unsigned int dkey, Geom::Rect const &box, bool take_hidden = false, bool take_insensitive = false, bool take_groups = true, bool enter_groups = false) const; + std::vector<SPItem*> getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box, bool take_hidden = false, bool take_insensitive = false, bool take_groups = true, bool enter_groups = false) const; + SPItem *getItemAtPoint(unsigned int key, Geom::Point const &p, bool into_groups, SPItem *upto = nullptr) const; + std::vector<SPItem*> getItemsAtPoints(unsigned const key, std::vector<Geom::Point> points, bool all_layers = true, size_t limit = 0) const ; + SPItem *getGroupAtPoint(unsigned int key, Geom::Point const &p) const; + + /** + * Returns the bottommost item from the list which is at the point, or NULL if none. + */ + static SPItem *getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, const std::vector<SPItem*> &list, Geom::Point const &p, bool take_insensitive = false); + + + + // Box tool ------------------------------- void setCurrentPersp3D(Persp3D * const persp); - inline void setCurrentPersp3DImpl(Persp3DImpl * const persp_impl) { current_persp3d_impl = persp_impl; } /* * getCurrentPersp3D returns current_persp3d (if non-NULL) or the first * perspective in the defs. If no perspective exists, returns NULL. */ Persp3D * getCurrentPersp3D(); + + void setCurrentPersp3DImpl(Persp3DImpl * const persp_impl) { current_persp3d_impl = persp_impl; } Persp3DImpl * getCurrentPersp3DImpl(); void getPerspectivesInDefs(std::vector<Persp3D*> &list) const; - unsigned int numPerspectivesInDefs() const { std::vector<Persp3D*> list; getPerspectivesInDefs(list); return list.size(); } - sigc::connection connectModified(ModifiedSignal::slot_type slot); - sigc::connection connectURISet(URISetSignal::slot_type slot); - sigc::connection connectResized(ResizedSignal::slot_type slot); - sigc::connection connectCommit(CommitSignal::slot_type slot); + // Document undo/redo ---------------------- + unsigned long serial() const; // Returns document's unique number. - void bindObjectToId(char const *id, SPObject *object); - SPObject *getObjectById(Glib::ustring const &id) const; - SPObject *getObjectById(char const *id) const; - sigc::connection connectIdChanged(const char *id, IDChangedSignal::slot_type slot); + /// Are we currently in a transition between two "known good" states of the document? + bool isSeeking() const; - std::vector<SPObject *> getObjectsByClass(Glib::ustring const &klass) const; - std::vector<SPObject *> getObjectsByElement(Glib::ustring const &element) const; - std::vector<SPObject *> getObjectsBySelector(Glib::ustring const &selector) const; - - void bindObjectToRepr(Inkscape::XML::Node *repr, SPObject *object); - SPObject *getObjectByRepr(Inkscape::XML::Node *repr) const; - Glib::ustring getLanguage() const; + // Document undo/redo ---------------------- + void reset_key(void *dummy); + + // Garbage collecting ---------------------- void queueForOrphanCollection(SPObject *object); void collectOrphans(); - void _emitModified(); - void addUndoObserver(Inkscape::UndoStackObserver& observer); - void removeUndoObserver(Inkscape::UndoStackObserver& observer); - bool _updateDocument(); + /************* Data ***************/ - /// Are we currently in a transition between two "known good" states of the document? - bool isSeeking() const; + // Document ------------------------------ + Inkscape::ProfileManager* profileManager; + Avoid::Router *router; // Instance of the connector router - bool isModifiedSinceSave() const { return modified_since_save; } - void setModifiedSinceSave(bool const modified = true); + // Document status ----------------------- + int ref_count; // Temp to check refcounting + + unsigned int keepalive : 1; + unsigned int virgin : 1; ///< Has the document never been touched? + unsigned int modified_since_save : 1; + unsigned modified_id; /// Handler id + + // Document structure -------------------- + Inkscape::XML::Document *rdoc; ///< Our Inkscape::XML::Document + Inkscape::XML::Node *rroot; ///< Root element of Inkscape::XML::Document private: - Persp3D *current_persp3d; /**< Currently 'active' perspective (to which, e.g., newly created boxes are attached) */ - Persp3DImpl *current_persp3d_impl; + SPRoot *root; ///< Our SPRoot // A list of svg documents being used or shown within this document boost::ptr_list<SPDocument> _child_documents; @@ -239,120 +300,123 @@ private: SPDocument *_parent_document; public: - SPDocument(SPDocument const &) = delete; // no copy - void operator=(SPDocument const &) = delete; // no assign + /// Connector rerouting handler ID + unsigned rerouting_handler_id; - sigc::connection connectReconstructionStart(ReconstructionStart::slot_type slot); - sigc::connection connectReconstructionFinish(ReconstructionFinish::slot_type slot); - void emitReconstructionStart(); - void emitReconstructionFinish(); + CRCascade *style_cascade; + CRStyleSheet *style_sheet; - unsigned long serial() const; - void reset_key(void *dummy); - sigc::connection _selection_changed_connection; - sigc::connection _desktop_activated_connection; + // File information ---------------------- +protected: + char *document_uri; ///< A filename (not a URI yet), or NULL + char *document_base; ///< To be used for resolving relative hrefs. + char *document_name; ///< basename(uri) or other human-readable label for the document. - sigc::connection connectResourcesChanged(char const *key, SPDocument::ResourcesChangedSignal::slot_type slot); + // Find items ---------------------------- +private: + std::map<std::string, SPObject *> iddef; + std::map<Inkscape::XML::Node *, SPObject *> reprdef; - void fitToRect(Geom::Rect const &rect, bool with_margins = false); - static SPDocument *createNewDoc(char const*uri, unsigned int keepalive, - bool make_new = false, SPDocument *parent=nullptr ); - static SPDocument *createNewDocFromMem(char const*buffer, int length, unsigned int keepalive); - SPDocument *createChildDoc(std::string const &uri); + // Find items by geometry -------------------- + mutable std::deque<SPItem*> _node_cache; // Used to speed up search. + mutable bool _node_cache_valid; - /** - * Returns the bottommost item from the list which is at the point, or NULL if none. - */ - static SPItem *getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, const std::vector<SPItem*> &list, Geom::Point const &p, bool take_insensitive = false); + // Box tool ---------------------------- +private: + Persp3D *current_persp3d; /**< Currently 'active' perspective (to which, e.g., newly created boxes are attached) */ + Persp3DImpl *current_persp3d_impl; - static SPDocument *createDoc(Inkscape::XML::Document *rdoc, char const *uri, - char const *base, char const *name, unsigned int keepalive, - SPDocument *parent); + // Document undo/redo ---------------------- +public: - int ref_count; - SPDocument *doRef(); - SPDocument *doUnref(); - Inkscape::Util::Unit const* getDisplayUnit() const; - void setDocumentScale( const double scaleX, const double scaleY ); - void setDocumentScale( const double scale ); - Geom::Scale getDocumentScale() const; - Inkscape::Util::Quantity getWidth() const; - Inkscape::Util::Quantity getHeight() const; - Geom::Rect getViewBox() const; - Geom::Point getDimensions() const; - Geom::OptRect preferredBounds() const; - void setWidthAndHeight(const Inkscape::Util::Quantity &width, const Inkscape::Util::Quantity &height, bool changeSize=true); - void setWidth(const Inkscape::Util::Quantity &width, bool changeSize=true); - void setHeight(const Inkscape::Util::Quantity &height, bool changeSize=true); - void setViewBox(); - void setViewBox(const Geom::Rect &viewBox); - void requestModified(); - int ensureUpToDate(); - bool addResource(char const *key, SPObject *object); - bool removeResource(char const *key, SPObject *object); - std::vector<SPObject *> const getResourceList(char const *key); - std::vector<SPItem*> getItemsInBox (unsigned int dkey, Geom::Rect const &box, bool take_hidden = false, bool take_insensitive = false, bool take_groups = true, bool enter_groups = false) const; - std::vector<SPItem*> getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box, bool take_hidden = false, bool take_insensitive = false, bool take_groups = true, bool enter_groups = false) const; - SPItem *getItemAtPoint(unsigned int key, Geom::Point const &p, bool into_groups, SPItem *upto = nullptr) const; - std::vector<SPItem*> getItemsAtPoints(unsigned const key, std::vector<Geom::Point> points, bool all_layers = true, size_t limit = 0) const ; - SPItem *getGroupAtPoint(unsigned int key, Geom::Point const &p) const; + /* Undo/Redo state */ + bool sensitive; /* If we save actions to undo stack */ + Inkscape::XML::Event * partial; /* partial undo log when interrupted */ + int history_size; + std::vector<Inkscape::Event *> undo; /* Undo stack of reprs */ + std::vector<Inkscape::Event *> redo; /* Redo stack of reprs */ - void changeUriAndHrefs(char const *uri); - void emitResizedSignal(double width, double height); - - unsigned int vacuumDocument(); + /* Undo listener */ + Inkscape::CompositeUndoStackObserver undoStackObservers; - void importDefs(SPDocument *source); + // XXX only for testing! + Inkscape::ConsoleOutputUndoObserver console_output_undo_observer; + bool seeking; // Related to undo/redo/unique id private: - void do_change_uri(char const *const filename, bool const rebase); - void setupViewport(SPItemCtx *ctx); - void importDefsNode(SPDocument *source, Inkscape::XML::Node *defs, Inkscape::XML::Node *target_defs); - void build_flat_item_list(unsigned int dkey, SPGroup *group, gboolean into_groups) const; - mutable std::deque<SPItem*> _node_cache; - mutable bool _node_cache_valid; + unsigned long _serial; // Unique document number (used by undo/redo). - // The following were in document-private.h and despite being called "private", they weren't. public: - typedef std::map<GQuark, SPDocument::IDChangedSignal> IDChangedSignalMap; - typedef std::map<GQuark, SPDocument::ResourcesChangedSignal> ResourcesChangedSignalMap; + Glib::ustring actionkey; // Last action key, used to combine actions in undo. - std::map<std::string, SPObject *> iddef; - std::map<Inkscape::XML::Node *, SPObject *> reprdef; - unsigned long _serial; + // Garbage collecting ---------------------- + std::vector<SPObject *> _collection_queue; ///< Orphans + + + /*********** Signals **************/ + + void addUndoObserver(Inkscape::UndoStackObserver& observer); + void removeUndoObserver(Inkscape::UndoStackObserver& observer); + + typedef sigc::signal<void, SPObject *> IDChangedSignal; + typedef sigc::signal<void> ResourcesChangedSignal; + typedef sigc::signal<void, unsigned> ModifiedSignal; + typedef sigc::signal<void, char const *> URISetSignal; + typedef sigc::signal<void, double, double> ResizedSignal; + typedef sigc::signal<void> ReconstructionStart; + typedef sigc::signal<void> ReconstructionFinish; + typedef sigc::signal<void> CommitSignal; + + typedef std::map<GQuark, SPDocument::IDChangedSignal> IDChangedSignalMap; + typedef std::map<GQuark, SPDocument::ResourcesChangedSignal> ResourcesChangedSignalMap; /** Dictionary of signals for id changes */ IDChangedSignalMap id_changed_signals; - /* Resources */ - std::map<std::string, std::vector<SPObject *> > resources; - ResourcesChangedSignalMap resources_changed_signals; - - sigc::signal<void> destroySignal; SPDocument::ModifiedSignal modified_signal; SPDocument::URISetSignal uri_set_signal; SPDocument::ResizedSignal resized_signal; SPDocument::ReconstructionStart _reconstruction_start_signal; SPDocument::ReconstructionFinish _reconstruction_finish_signal; +public: SPDocument::CommitSignal commit_signal; - /* Undo/Redo state */ - bool sensitive; /* If we save actions to undo stack */ - Inkscape::XML::Event * partial; /* partial undo log when interrupted */ - int history_size; - std::vector<Inkscape::Event *> undo; /* Undo stack of reprs */ - std::vector<Inkscape::Event *> redo; /* Redo stack of reprs */ - - /* Undo listener */ - Inkscape::CompositeUndoStackObserver undoStackObservers; +private: + bool oldSignalsConnected; - // XXX only for testing! - Inkscape::ConsoleOutputUndoObserver console_output_undo_observer; +public: + sigc::connection connectDestroy(sigc::signal<void>::slot_type slot); + sigc::connection connectModified(ModifiedSignal::slot_type slot); + sigc::connection connectURISet(URISetSignal::slot_type slot); + sigc::connection connectResized(ResizedSignal::slot_type slot); + sigc::connection connectCommit(CommitSignal::slot_type slot); + sigc::connection connectIdChanged(const char *id, IDChangedSignal::slot_type slot); + sigc::connection connectResourcesChanged(char const *key, SPDocument::ResourcesChangedSignal::slot_type slot); + sigc::connection connectReconstructionStart(ReconstructionStart::slot_type slot); + sigc::connection connectReconstructionFinish(ReconstructionFinish::slot_type slot); - bool seeking; +private: + sigc::connection _selection_changed_connection; + sigc::connection _desktop_activated_connection; sigc::connection selChangeConnection; sigc::connection desktopActivatedConnection; + + /* Resources */ + std::map<std::string, std::vector<SPObject *> > resources; +public: + ResourcesChangedSignalMap resources_changed_signals; +private: + + sigc::signal<void> destroySignal; + +public: + void _emitModified(); // Used by SPItem + +public: + void emitReconstructionStart(); + void emitReconstructionFinish(); + void emitResizedSignal(double width, double height); }; /* diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index a22585cb4..be391f08d 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -1071,7 +1071,7 @@ void document_interface_update(DocumentInterface *doc_interface, GError ** error doc->getRoot()->uflags = TRUE; doc->getRoot()->mflags = TRUE; desk->enableInteraction(); - doc->_updateDocument(); + doc->ensureUpToDate(); desk->disableInteraction(); doc->getRoot()->uflags = FALSE; doc->getRoot()->mflags = FALSE; diff --git a/src/io/resource-manager.cpp b/src/io/resource-manager.cpp index 308aca8a9..406157ebd 100644 --- a/src/io/resource-manager.cpp +++ b/src/io/resource-manager.cpp @@ -9,6 +9,7 @@ #include <string> #include <vector> +#include <set> #include <algorithm> #include <gtkmm/recentmanager.h> |
