examples/qvdesigner0.2/facade/itemproperties.cpp

00001 /*
00002  *      Copyright (C) 2008. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *      GNU Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with QVision. If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00021 
00022 #include "itemproperties.h"
00023 #include "qvcore/qvpropertycontainer.h"
00024 
00025 
00026 // genera un item properties vacio
00027 ItemProperties::ItemProperties(QString type): containerType(type)
00028 {
00029 }
00030 
00031 // genera un item properties a partir de un qvpropertycontainer
00032 ItemProperties::ItemProperties(QString type, QVPropertyContainer *container): containerType(type)
00033 {
00034         QList<QString> prop( container->getPropertyList() );
00035 
00036         for (int i = 0; i < prop.size(); i++)
00037         { // para cada propiedad
00038                 QVPropertyContainer::PropertyFlags flags = container->getPropertyFlags(prop[i]);
00039                 if ( !(flags & (QVPropertyContainer::guiInvisible | QVPropertyContainer::internalProp)) )
00040                 { // solo la incluyo si no es ni guiinvisible ni internalprop
00041                         properties.append( prop[i] );
00042                         types.append( container->getPropertyType(prop[i]) );
00043                         inputs.append( container->isInput(prop[i]) );
00044                         outputs.append( container->isOutput(prop[i]) );
00045                 }
00046         }
00047 }
00048 
00049 QString ItemProperties::getType() const
00050 {
00051         return containerType;
00052 }
00053 
00054 QList<QString> ItemProperties::getProperties() const
00055 {
00056         return properties;
00057 }
00058 
00059 int ItemProperties::propertyType(const uint i) const
00060 {
00061         if (i >= (uint)types.size()) return 0;
00062         return types[i];
00063 }
00064 
00065 bool ItemProperties::isInput(const uint i) const
00066 {
00067         if (i >= (uint)inputs.size()) return false;
00068         return inputs[i];
00069 }
00070 
00071 bool ItemProperties::isOutput(const uint i) const
00072 {
00073         if (i >= (uint)outputs.size()) return false;
00074         return outputs[i];
00075 }
00076 
00077 void ItemProperties::insertProperty(int pos, QString name, int type, bool input, bool output)
00078 {
00079         if ( (pos >= 0) && (pos <= properties.size()) )
00080         {
00081                 properties.insert(pos, name);
00082                 types.insert(pos, type);
00083                 inputs.insert(pos, input);
00084                 outputs.insert(pos, output);
00085         }
00086 }
00087 
00088 void ItemProperties::deleteProperty(int pos)
00089 {
00090         if ( (pos >= 0) && (pos <= properties.size()) )
00091         {
00092                 properties.removeAt(pos);
00093                 types.removeAt(pos);
00094                 inputs.removeAt(pos);
00095                 outputs.removeAt(pos);
00096         }
00097 }
00098 
00099 void ItemProperties::deleteProperty(QString name)
00100 {
00101         deleteProperty(properties.indexOf(name));
00102 }
00103