File indexing completed on 2024-05-05 04:05:48
0001 /* 0002 SPDX-FileCopyrightText: 2009, 2010 Stefan Majewsky <majewsky@gmx.net> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "slicer.h" 0008 #include "slicerjob.h" 0009 #include "slicermode.h" 0010 #include "slicerproperty.h" 0011 0012 //BEGIN Pala::SlicerPrivate 0013 0014 class Pala::SlicerPrivate 0015 { 0016 public: 0017 QList<const Pala::SlicerMode*> m_modes; 0018 QList<const Pala::SlicerProperty*> m_properties; 0019 Pala::Slicer::SlicerFlags m_flags; 0020 }; 0021 0022 //END Pala::SlicerPrivate 0023 0024 Pala::Slicer::Slicer(QObject* parent, const QVariantList& /*args*/) 0025 : QObject(parent) 0026 , d_ptr(new SlicerPrivate) 0027 { 0028 Q_D(Slicer); 0029 d->m_flags = NoFlags; 0030 } 0031 0032 Pala::Slicer::~Slicer() 0033 { 0034 Q_D(Slicer); 0035 qDeleteAll(d->m_modes); 0036 qDeleteAll(d->m_properties); 0037 } 0038 0039 QList<const Pala::SlicerMode*> Pala::Slicer::modes() const 0040 { 0041 Q_D(const Slicer); 0042 return d->m_modes; 0043 } 0044 0045 QMap<QByteArray, const Pala::SlicerProperty*> Pala::Slicer::properties() const 0046 { 0047 Q_D(const Slicer); 0048 QMap<QByteArray, const Pala::SlicerProperty*> result; 0049 for (const Pala::SlicerProperty* property : d->m_properties) 0050 result.insert(property->key(), property); 0051 return result; 0052 } 0053 0054 QList<const Pala::SlicerProperty*> Pala::Slicer::propertyList() const 0055 { 0056 Q_D(const Slicer); 0057 return d->m_properties; 0058 } 0059 0060 Pala::Slicer::SlicerFlags Pala::Slicer::flags() const 0061 { 0062 Q_D(const Slicer); 0063 return d->m_flags; 0064 } 0065 0066 void Pala::Slicer::addProperty(const QByteArray& key, Pala::SlicerProperty* property) 0067 { 0068 Q_D(Slicer); 0069 //NOTE: This function is done such that it retains the insertion order in the list. 0070 for (int i = 0; i < d->m_properties.size(); ++i) 0071 { 0072 if (d->m_properties[i] == property) 0073 return; 0074 if (d->m_properties[i]->key() == key) 0075 { 0076 delete d->m_properties.takeAt(i); 0077 break; 0078 } 0079 } 0080 d->m_properties << property; 0081 property->setKey(key); 0082 } 0083 0084 void Pala::Slicer::addMode(Pala::SlicerMode* mode) 0085 { 0086 Q_D(Slicer); 0087 //NOTE: This one too. ;-) 0088 for (int i = 0; i < d->m_modes.size(); ++i) 0089 { 0090 if (d->m_modes[i] == mode) 0091 return; 0092 if (d->m_modes[i]->key() == mode->key()) 0093 { 0094 delete d->m_modes.takeAt(i); 0095 break; 0096 } 0097 } 0098 d->m_modes << mode; 0099 } 0100 0101 void Pala::Slicer::setFlags(Pala::Slicer::SlicerFlags flags) 0102 { 0103 Q_D(Slicer); 0104 d->m_flags = flags; 0105 } 0106 0107 bool Pala::Slicer::process(Pala::SlicerJob* job) 0108 { 0109 Q_D(Slicer); 0110 job->respectSlicerFlags(d->m_flags); 0111 return run(job); 0112 } 0113 0114 #include "moc_slicer.cpp"