Tulip  4.7.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
PropertyToQVariantMapper.cxx
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 
20 namespace tlp {
21 
22 template<typename PropertyClass, typename NodeType, typename EdgeType>
23 QVariant StandardPropertyToQVariantConverter<PropertyClass,NodeType,EdgeType>::getValue(unsigned int id,tlp::ElementType elementType,tlp::PropertyInterface* property) const {
24  if(elementType == tlp::NODE) {
25  return QVariant::fromValue<NodeType>(static_cast<PropertyClass*>(property)->getNodeValue(tlp::node(id)));
26  }
27  else {
28  return QVariant::fromValue<EdgeType>(static_cast<PropertyClass*>(property)->getEdgeValue(tlp::edge(id)));
29  }
30 }
31 
32 template<typename PropertyClass, typename NodeType, typename EdgeType>
33 QVariant StandardPropertyToQVariantConverter<PropertyClass,NodeType,EdgeType>::getNormalizedValue(unsigned int,tlp::ElementType,tlp::PropertyInterface*,tlp::Graph*)const {
34  return QVariant();
35 }
36 
37 template<typename PropertyClass, typename NodeType, typename EdgeType>
38 bool StandardPropertyToQVariantConverter<PropertyClass,NodeType,EdgeType>::setValue(unsigned int id,tlp::ElementType elementType,tlp::PropertyInterface* property,const QVariant& data) const {
39  PropertyClass* p = static_cast<PropertyClass*>(property);
40 
41  if(elementType == tlp::NODE) {
42  const NodeType& oldValue = p->getNodeValue(tlp::node(id));
43  NodeType newValue = data.value<NodeType>();
44 
45  if(oldValue != newValue) {
46  p->setNodeValue(tlp::node(id),newValue);
47  return true;
48  }
49  }
50  else {
51  const EdgeType& oldValue = p->getEdgeValue(tlp::edge(id));
52  EdgeType newValue = data.value<EdgeType>();
53 
54  if(oldValue != newValue) {
55  p->setEdgeValue(tlp::edge(id),data.value<EdgeType>());
56  return true;
57  }
58  }
59 
60  return false;
61 }
62 
63 template<typename PropertyClass, typename NodeType, typename EdgeType>
64 bool StandardPropertyToQVariantConverter<PropertyClass,NodeType,EdgeType>::setAllValue(tlp::ElementType elementType,tlp::PropertyInterface* property,const QVariant& data) const {
65  PropertyClass* p = static_cast<PropertyClass*>(property);
66 
67  if(elementType == tlp::NODE) {
68  p->setAllNodeValue(data.value<NodeType>());
69  }
70  else {
71  p->setAllEdgeValue(data.value<EdgeType>());
72  }
73 
74  return true;
75 }
76 
77 }
78 
PropertyInterface describes the interface of a graph property.
ElementType
Definition: Graph.h:46
The edge struct represents an edge in a Graph object.
Definition: Edge.h:39
The node struct represents a node in a Graph object.
Definition: Node.h:39