ELVE  1
ELVE Logic Visualization Explorer
/home/travis/build/stdgregwar/elve/Core/Selection.cpp
00001 #include "Selection.h"
00002 
00003 #include <QJsonArray>
00004 #include <QDebug>
00005 
00006 namespace Elve {
00007 
00008 Selection::Selection(const NodeIDSet &set) : NodeIDSet(set)
00009 {
00010 
00011 }
00012 
00013 Selection::Selection() {
00014 
00015 }
00016 
00017 void Selection::add(const NodeID& id)
00018 {
00019     insert(id);
00020 }
00021 
00022 void Selection::add(const Selection& other)
00023 {
00024     for(const auto& i : other) {
00025         add(i);
00026     }
00027 }
00028 
00029 void Selection::sub(const Selection& other)
00030 {
00031     for(const auto& i : other) {
00032         sub(i);
00033     }
00034 }
00035 
00036 void Selection::sub(const NodeID& id)
00037 {
00038     erase(id);
00039 }
00040 
00041 QJsonArray Selection::json() const {
00042     QJsonArray arr;
00043     for(const auto& i : *this) {
00044         arr.append((int)i);
00045     }
00046     return arr;
00047 }
00048 
00049 Selection Selection::fromJson(const QJsonArray& arr) {
00050     NodeIDSet set; set.reserve(arr.size());
00051     for(const QJsonValue& v : arr) {
00052         set.insert(v.toInt());
00053     }
00054     return Selection(set);
00055 }
00056 
00057 QDebug operator<<(QDebug stream, const Selection& s) {
00058    for(const NodeID& i : s) {
00059        stream << QVariant(i);
00060    }
00061    return stream;
00062 }
00063 
00064 }
 All Classes Functions