summaryrefslogtreecommitdiffstats
path: root/src/selection.h
diff options
context:
space:
mode:
authorkamalpreetgrewal <grewalkamal005@gmail.com>2016-08-15 03:59:18 +0000
committerkamalpreetgrewal <grewalkamal005@gmail.com>2016-08-15 03:59:18 +0000
commit25a9ed4f38121eeb59cf15dbf19391aaef45bba3 (patch)
treee123aeae50d98a52e1ad4575b29bf3c199619e33 /src/selection.h
parentSolve crash when deleting CSS property (diff)
parentinkview: Convert to ApplicationWindow (diff)
downloadinkscape-25a9ed4f38121eeb59cf15dbf19391aaef45bba3.tar.gz
inkscape-25a9ed4f38121eeb59cf15dbf19391aaef45bba3.zip
Merge changes from trunk
(bzr r14949.1.64)
Diffstat (limited to 'src/selection.h')
-rw-r--r--src/selection.h204
1 files changed, 24 insertions, 180 deletions
diff --git a/src/selection.h b/src/selection.h
index 04bcca402..4ea70c38d 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,21 +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;
@@ -38,7 +35,6 @@ class Node;
}
}
-
namespace Inkscape {
/**
@@ -60,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
@@ -82,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).
@@ -96,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.
@@ -122,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.
@@ -147,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.
@@ -170,117 +134,21 @@ 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();
-
- /**
- * 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.
*
@@ -327,6 +195,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 &);
@@ -342,46 +215,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;