summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAdrian Boguszewski <adrbogus1@student.pg.gda.pl>2016-06-27 14:59:48 +0000
committerAdrian Boguszewski <adrbogus1@student.pg.gda.pl>2016-06-27 14:59:48 +0000
commita51df2ab1eb079b2588ccb9398440f403d11c34d (patch)
tree3cbf95ba7d8ac923fa3e6887319371021ec4cecd /src
parentMoved next functions, added namespace, renamed range functions (diff)
downloadinkscape-a51df2ab1eb079b2588ccb9398440f403d11c34d.tar.gz
inkscape-a51df2ab1eb079b2588ccb9398440f403d11c34d.zip
Added more tests
(bzr r14954.1.11)
Diffstat (limited to 'src')
-rw-r--r--src/object-set.cpp28
-rw-r--r--src/object-set.h26
2 files changed, 24 insertions, 30 deletions
diff --git a/src/object-set.cpp b/src/object-set.cpp
index 627544a21..518ce15a3 100644
--- a/src/object-set.cpp
+++ b/src/object-set.cpp
@@ -174,13 +174,8 @@ bool ObjectSet::isEmpty() {
return container.size() == 0;
}
-
SPObject *ObjectSet::single() {
- if (container.size() == 1) {
- return *container.begin();
- }
-
- return nullptr;
+ return container.size() == 1 ? *container.begin() : nullptr;
}
SPItem *ObjectSet::singleItem() {
@@ -257,27 +252,6 @@ void ObjectSet::set(SPObject *object) {
// _emitSignals();
}
-void ObjectSet::setList(const std::vector<SPItem *> &objs) {
- _clear();
- addList(objs);
-}
-
-void ObjectSet::addList(const std::vector<SPItem *> &objs) {
- for (std::vector<SPItem*>::const_iterator iter = objs.begin(); iter != objs.end(); ++iter) {
- SPObject *obj = *iter;
- if (!includes(obj)) {
- add(obj);
- }
- }
-}
-
-void ObjectSet::add(const std::vector<SPItem*>::iterator& from, const std::vector<SPItem*>::iterator& to) {
- for(auto it = from; it != to; ++it) {
- _add(*it);
- }
-}
-
-
Geom::OptRect ObjectSet::bounds(SPItem::BBoxType type) const
{
return (type == SPItem::GEOMETRIC_BBOX) ?
diff --git a/src/object-set.h b/src/object-set.h
index 49a875562..29083863b 100644
--- a/src/object-set.h
+++ b/src/object-set.h
@@ -21,6 +21,8 @@
#include <boost/multi_index/random_access_index.hpp>
#include <boost/range/sub_range.hpp>
#include <boost/range/any_range.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/utility/enable_if.hpp>
#include <sigc++/connection.h>
#include "sp-object.h"
#include "sp-item.h"
@@ -84,7 +86,12 @@ public:
* \param from the begin iterator
* \param to the end iterator
*/
- void add(const std::vector<SPItem*>::iterator& from, const std::vector<SPItem*>::iterator& to);
+ template <typename InputIterator>
+ void add(InputIterator from, InputIterator to) {
+ for(auto it = from; it != to; ++it) {
+ _add(*it);
+ }
+ }
/**
* Removes an item from the set of selected objects.
@@ -176,14 +183,27 @@ public:
*
* @param objs the objects to select
*/
- void setList(const std::vector<SPItem *> &objs);
+ template <class T>
+ typename boost::enable_if<boost::is_base_of<SPObject, T>, void>::type
+ setList(const std::vector<T*> &objs) {
+ _clear();
+ addList(objs);
+ }
/**
* Adds the specified objects to selection, without deselecting first.
*
* @param objs the objects to select
*/
- void addList(std::vector<SPItem*> const &objs);
+ template <class T>
+ typename boost::enable_if<boost::is_base_of<SPObject, T>, void>::type
+ addList(const std::vector<T*> &objs) {
+ for (auto obj: objs) {
+ if (!includes(obj)) {
+ add(obj);
+ }
+ }
+ }
/** Returns the bounding rectangle of the selection. */
Geom::OptRect bounds(SPItem::BBoxType type) const;