diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2016-10-03 20:51:05 +0000 |
|---|---|---|
| committer | jabiertxof <info@marker.es> | 2016-10-03 20:51:05 +0000 |
| commit | 4db35e8a6706ddece9e977e5f26d4a6867ff8cbe (patch) | |
| tree | f9711f260f694d96e26bf3216fb64f2b38611b2b /src/selection.h | |
| parent | update to trunk (diff) | |
| parent | Merge in jabiertxof's hover information for measure tool (diff) | |
| download | inkscape-4db35e8a6706ddece9e977e5f26d4a6867ff8cbe.tar.gz inkscape-4db35e8a6706ddece9e977e5f26d4a6867ff8cbe.zip | |
Update to trunk
(bzr r15017.1.35)
Diffstat (limited to 'src/selection.h')
| -rw-r--r-- | src/selection.h | 211 |
1 files changed, 25 insertions, 186 deletions
diff --git a/src/selection.h b/src/selection.h index bf6acb015..cf00ba1f4 100644 --- a/src/selection.h +++ b/src/selection.h @@ -5,7 +5,9 @@ * Lauris Kaplinski <lauris@kaplinski.com> * MenTaLguY <mental@rydia.net> * bulia byak <buliabyak@users.sf.net> + * Adrian Boguszewski * + * Copyright (C) 2016 Adrian Boguszewski * Copyright (C) 2004-2005 MenTaLguY * Copyright (C) 1999-2002 Lauris Kaplinski * Copyright (C) 2001-2002 Ximian, Inc. @@ -15,23 +17,16 @@ #include <vector> #include <map> -#include <list> -#include <set> #include <stddef.h> #include <sigc++/sigc++.h> #include "inkgc/gc-managed.h" #include "gc-finalized.h" #include "gc-anchored.h" -#include "inkgc/gc-soft-ptr.h" #include "sp-item.h" +#include "object-set.h" - - -class SPDesktop; class SPItem; -class SPBox3D; -class Persp3D; namespace Inkscape { class LayerModel; @@ -40,7 +35,6 @@ class Node; } } - namespace Inkscape { /** @@ -62,10 +56,10 @@ namespace Inkscape { */ class Selection : public Inkscape::GC::Managed<>, public Inkscape::GC::Finalized, - public Inkscape::GC::Anchored + public Inkscape::GC::Anchored, + public ObjectSet { public: - enum CompareSize { HORIZONTAL, VERTICAL, AREA }; /** * Constructs an selection object, bound to a particular * layer model @@ -84,12 +78,7 @@ public: */ LayerModel *layers() { return _layers; } - /** - * Returns the desktop the selection is bound to - * - * @return the desktop the selection is bound to, or NULL if in console mode - */ - SPDesktop *desktop() { return _desktop; } + /** * Returns active layer for selection (currentLayer or its parent). @@ -98,19 +87,16 @@ public: */ SPObject *activeContext(); - /** - * Add an SPObject to the set of selected objects. - * - * @param obj the SPObject to add - */ - void add(SPObject *obj, bool persist_selection_context = false); + using ObjectSet::add; /** * Add an XML node's SPObject to the set of selected objects. * * @param the xml node of the item to add */ - void add(XML::Node *repr) { add(_objectForXMLNode(repr)); } + void add(XML::Node *repr) { + add(_objectForXMLNode(repr)); + } /** * Set the selection to a single specific object. @@ -124,23 +110,11 @@ public: * * @param repr the xml node of the item to select */ - void set(XML::Node *repr) { set(_objectForXMLNode(repr)); } - - /** - * Removes an item from the set of selected objects. - * - * It is ok to call this method for an unselected item. - * - * @param item the item to unselect - */ - void remove(SPObject *obj); + void set(XML::Node *repr) { + set(_objectForXMLNode(repr)); + } - /** - * Removes an item if selected, adds otherwise. - * - * @param item the item to unselect - */ - void toggle(SPObject *obj); + using ObjectSet::remove; /** * Removes an item from the set of selected objects. @@ -149,21 +123,9 @@ public: * * @param repr the xml node of the item to remove */ - void remove(XML::Node *repr) { remove(_objectForXMLNode(repr)); } - - /** - * Selects exactly the specified objects. - * - * @param objs the objects to select - */ - void setList(std::vector<SPItem*> const &objs); - - /** - * Adds the specified objects to selection, without deselecting first. - * - * @param objs the objects to select - */ - void addList(std::vector<SPItem*> const &objs); + void remove(XML::Node *repr) { + remove(_objectForXMLNode(repr)); + } /** * Clears the selection and selects the specified objects. @@ -172,122 +134,22 @@ public: */ void setReprList(std::vector<XML::Node*> const &reprs); - /** Add items from an STL iterator range to the selection. - * \param from the begin iterator - * \param to the end iterator - */ - template <typename InputIterator> - void add(InputIterator from, InputIterator to) { - _invalidateCachedLists(); - while ( from != to ) { - _add(*from); - ++from; - } - _emitChanged(); - } - - /** - * Unselects all selected objects.. - */ - void clear(); - - /** - * Emmit modified signal - */ - void emitModified(); - - /** - * Returns true if no items are selected. - */ - bool isEmpty() const { return _objs.empty(); } - /** - * Returns true if the given object is selected. - */ - bool includes(SPObject *obj) const; + using ObjectSet::includes; /** * Returns true if the given item is selected. */ - bool includes(XML::Node *repr) const { + bool includes(XML::Node *repr) { return includes(_objectForXMLNode(repr)); } - /** - * Returns a single selected object. - * - * @return NULL unless exactly one object is selected - */ - SPObject *single(); - - /** - * Returns a single selected item. - * - * @return NULL unless exactly one object is selected - */ - SPItem *singleItem(); - - /** - * Returns the smallest item from this selection. - */ - SPItem *smallestItem(CompareSize compare); - - /** - * Returns the largest item from this selection. - */ - SPItem *largestItem(CompareSize compare); - - /** - * Returns a single selected object's xml node. - * - * @return NULL unless exactly one object is selected - */ - XML::Node *singleRepr(); - - /** Returns the list of selected objects. */ - std::vector<SPObject*> const &list(); - /** Returns the list of selected SPItems. */ - std::vector<SPItem*> const &itemList(); - /** Returns a list of the xml nodes of all selected objects. */ - /// \todo only returns reprs of SPItems currently; need a separate - /// method for that - std::vector<XML::Node*> const &reprList(); - - /** Returns a list of all perspectives which have a 3D box in the current selection. - (these may also be nested in groups) */ - std::list<Persp3D *> const perspList(); - - /** - * Returns a list of all 3D boxes in the current selection which are associated to @c - * persp. If @c pers is @c NULL, return all selected boxes. - */ - std::list<SPBox3D *> const box3DList(Persp3D *persp = NULL); - /** Returns the number of layers in which there are selected objects. */ size_t numberOfLayers(); /** Returns the number of parents to which the selected objects belong. */ size_t numberOfParents(); - /** Returns the bounding rectangle of the selection. */ - Geom::OptRect bounds(SPItem::BBoxType type) const; - Geom::OptRect visualBounds() const; - Geom::OptRect geometricBounds() const; - - /** - * Returns either the visual or geometric bounding rectangle of the selection, based on the - * preferences specified for the selector tool - */ - Geom::OptRect preferredBounds() const; - - /// Returns the bounding rectangle of the selectionin document coordinates. - Geom::OptRect documentBounds(SPItem::BBoxType type) const; - - /** - * Returns the rotation/skew center of the selection. - */ - boost::optional<Geom::Point> center() const; - /** * Compute the list of points in the selection that are to be considered for snapping from. * @@ -305,6 +167,7 @@ public: * * @return the resulting connection */ + void emitModified(){ _emitModified(this->_flags); }; sigc::connection connectChanged(sigc::slot<void, Selection *> const &slot) { return _changed_signal.connect(slot); } @@ -334,6 +197,11 @@ public: return _modified_signal.slots().insert(_modified_signal.slots().begin(), slot); } +protected: + void _emitSignals(); + void _connectSignals(SPObject* object); + void _releaseSignals(SPObject* object); + private: /** no copy. */ Selection(Selection const &); @@ -349,46 +217,17 @@ private: void _emitModified(unsigned int flags); /** Issues changed selection signal. */ void _emitChanged(bool persist_selection_context = false); - - void _invalidateCachedLists(); - - /** unselect all descendants of the given item. */ - void _removeObjectDescendants(SPObject *obj); - /** unselect all ancestors of the given item. */ - void _removeObjectAncestors(SPObject *obj); - /** clears the selection (without issuing a notification). */ - void _clear(); - /** adds an object (without issuing a notification). */ - void _add(SPObject *obj); - /** removes an object (without issuing a notification). */ - void _remove(SPObject *obj); /** returns the SPObject corresponding to an xml node (if any). */ SPObject *_objectForXMLNode(XML::Node *repr) const; /** Releases an active layer object that is being removed. */ void _releaseContext(SPObject *obj); - mutable std::list<SPObject*> _objs; //to more efficiently remove arbitrary elements - mutable std::vector<SPObject*> _objs_vector; // to be returned by list(); - mutable std::set<SPObject*> _objs_set; //to efficiently test if object is selected - mutable std::vector<XML::Node*> _reprs; - mutable std::vector<SPItem*> _items; - - void add_box_perspective(SPBox3D *box); - void add_3D_boxes_recursively(SPObject *obj); - void remove_box_perspective(SPBox3D *box); - void remove_3D_boxes_recursively(SPObject *obj); - SPItem *_sizeistItem(bool sml, CompareSize compare); - - std::list<SPBox3D *> _3dboxes; - LayerModel *_layers; - GC::soft_ptr<SPDesktop> _desktop; SPObject* _selection_context; unsigned int _flags; unsigned int _idle; std::map<SPObject *, sigc::connection> _modified_connections; - std::map<SPObject *, sigc::connection> _release_connections; sigc::connection _context_release_connection; sigc::signal<void, Selection *> _changed_signal; |
