1 /* 2 Scan Tailor - Interactive post-processing tool for scanned pages. 3 Copyright (C) 2007-2009 Joseph Artsimovich <joseph_a@mail.ru> 4 5 This program is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #include "PropertySet.h" 20 #include <QDomDocument> 21 #include "PropertyFactory.h" 22 PropertySet(const QDomElement & el,const PropertyFactory & factory)23PropertySet::PropertySet(const QDomElement& el, const PropertyFactory& factory) { 24 const QString property_str("property"); 25 QDomNode node(el.firstChild()); 26 27 for (; !node.isNull(); node = node.nextSibling()) { 28 if (!node.isElement()) { 29 continue; 30 } 31 if (node.nodeName() != property_str) { 32 continue; 33 } 34 35 QDomElement prop_el(node.toElement()); 36 intrusive_ptr<Property> prop(factory.construct(prop_el)); 37 if (prop) { 38 m_props.push_back(prop); 39 } 40 } 41 } 42 PropertySet(const PropertySet & other)43PropertySet::PropertySet(const PropertySet& other) { 44 m_props.reserve(other.m_props.size()); 45 46 for (const intrusive_ptr<Property>& prop : other.m_props) { 47 m_props.push_back(prop->clone()); 48 } 49 } 50 operator =(const PropertySet & other)51PropertySet& PropertySet::operator=(const PropertySet& other) { 52 PropertySet(other).swap(*this); 53 54 return *this; 55 } 56 swap(PropertySet & other)57void PropertySet::swap(PropertySet& other) { 58 m_props.swap(other.m_props); 59 } 60 toXml(QDomDocument & doc,const QString & name) const61QDomElement PropertySet::toXml(QDomDocument& doc, const QString& name) const { 62 const QString property_str("property"); 63 QDomElement props_el(doc.createElement(name)); 64 65 for (const intrusive_ptr<Property>& prop : m_props) { 66 props_el.appendChild(prop->toXml(doc, property_str)); 67 } 68 69 return props_el; 70 } 71