Tulip  4.6.0
Better Visualization Through Research
library/tulip-gui/include/tulip/cxx/PropertyToQVariantMapper.cxx
00001 /*
00002  *
00003  * This file is part of Tulip (www.tulip-software.org)
00004  *
00005  * Authors: David Auber and the Tulip development Team
00006  * from LaBRI, University of Bordeaux
00007  *
00008  * Tulip is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation, either version 3
00011  * of the License, or (at your option) any later version.
00012  *
00013  * Tulip is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  * See the GNU General Public License for more details.
00017  *
00018  */
00019 
00020 namespace tlp {
00021 
00022 template<typename PropertyClass, typename NodeType, typename EdgeType>
00023 QVariant StandardPropertyToQVariantConverter<PropertyClass,NodeType,EdgeType>::getValue(unsigned int id,tlp::ElementType elementType,tlp::PropertyInterface* property) const {
00024   if(elementType == tlp::NODE) {
00025     return QVariant::fromValue<NodeType>(static_cast<PropertyClass*>(property)->getNodeValue(tlp::node(id)));
00026   }
00027   else {
00028     return QVariant::fromValue<EdgeType>(static_cast<PropertyClass*>(property)->getEdgeValue(tlp::edge(id)));
00029   }
00030 }
00031 
00032 template<typename PropertyClass, typename NodeType, typename EdgeType>
00033 QVariant StandardPropertyToQVariantConverter<PropertyClass,NodeType,EdgeType>::getNormalizedValue(unsigned int,tlp::ElementType,tlp::PropertyInterface*,tlp::Graph*)const {
00034   return QVariant();
00035 }
00036 
00037 template<typename PropertyClass, typename NodeType, typename EdgeType>
00038 bool StandardPropertyToQVariantConverter<PropertyClass,NodeType,EdgeType>::setValue(unsigned int id,tlp::ElementType elementType,tlp::PropertyInterface* property,const QVariant& data) const {
00039   PropertyClass* p = static_cast<PropertyClass*>(property);
00040 
00041   if(elementType == tlp::NODE) {
00042     const NodeType& oldValue = p->getNodeValue(tlp::node(id));
00043     NodeType newValue = data.value<NodeType>();
00044 
00045     if(oldValue != newValue) {
00046       p->setNodeValue(tlp::node(id),newValue);
00047       return true;
00048     }
00049   }
00050   else {
00051     const EdgeType& oldValue = p->getEdgeValue(tlp::edge(id));
00052     EdgeType newValue = data.value<EdgeType>();
00053 
00054     if(oldValue != newValue) {
00055       p->setEdgeValue(tlp::edge(id),data.value<EdgeType>());
00056       return true;
00057     }
00058   }
00059 
00060   return false;
00061 }
00062 
00063 template<typename PropertyClass, typename NodeType, typename EdgeType>
00064 bool StandardPropertyToQVariantConverter<PropertyClass,NodeType,EdgeType>::setAllValue(tlp::ElementType elementType,tlp::PropertyInterface* property,const QVariant& data) const {
00065   PropertyClass* p = static_cast<PropertyClass*>(property);
00066 
00067   if(elementType == tlp::NODE) {
00068     p->setAllNodeValue(data.value<NodeType>());
00069   }
00070   else {
00071     p->setAllEdgeValue(data.value<EdgeType>());
00072   }
00073 
00074   return true;
00075 }
00076 
00077 }
00078 
 All Classes Files Functions Variables Enumerations Enumerator Properties