INTRODUCTION
Overview
Download and Install
Quick Start
Documentation
Publications

NONFRAMEWORK CODE
Driver Interfaces
Drivers
Libraries
Utilities

FRAMEWORK CODE
Interfaces
Components
Libraries
Utilities

Full Software Listings

DEVELOPER
Tutorials
Examples
Dev Guide
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         

ocmmodel.h

00001 /*
00002  * Orca-Robotics Project: Components for robotics 
00003  *               http://orca-robotics.sf.net/
00004  * Copyright (c) 2004-2009 Alex Brooks, Alexei Makarenko, Tobias Kaupp
00005  *
00006  * This copy of Orca is licensed to you under the terms described in
00007  * the LICENSE file included in this distribution.
00008  *
00009  */
00010 
00011 #ifndef ORCA_OCM_MODEL_H
00012 #define ORCA_OCM_MODEL_H
00013 
00014 #include <QAbstractItemModel>
00015 #include <QDateTime>
00016 #include <QStringList>
00017 #include <QIcon>
00018 
00019 namespace orcaqcm
00020 {
00021 
00022 class OcmIconProvider
00023 {
00024 public:
00025     OcmIconProvider();
00026     enum IconType { Registry, Platform, Component, Provided, Required, Operation, Result };
00027     QIcon icon(IconType type) const;
00028 
00029 private:
00030     QIcon registry;
00031     QIcon platform;
00032     QIcon component;
00033     QIcon provided;
00034     QIcon required;
00035     QIcon operation;
00036     QIcon result;
00037 };
00038 
00045 class OcmModel : public QAbstractItemModel
00046 {
00047     Q_OBJECT
00048 
00049 public:
00050     enum Roles {
00051         StatusIconRole = Qt::DecorationRole,
00052         TypeRole = Qt::UserRole + 1,
00053         ConnectionRole,
00054         SummaryRole,
00055         DetailRole
00056     };
00057 
00058     explicit OcmModel(QObject *parent = 0);
00059 
00060     // from QAbstractItemModel
00061     virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
00062     virtual QModelIndex parent(const QModelIndex &child) const;
00063     virtual int rowCount(const QModelIndex &parent) const;
00064     virtual int columnCount(const QModelIndex &parent) const;
00065     virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
00066     //bool setData(const QModelIndex &index, const QVariant &value, int role);
00067     virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
00068     virtual bool hasChildren(const QModelIndex &index) const;
00069 
00070     // from QObject
00072     virtual void customEvent( QEvent* e );
00073 
00074     // OcmModel specific API
00075     
00077     QModelIndex registryIndex( const QString& registry, bool create=false );
00078 
00081     QModelIndex platformIndex( const QString& registry, const QString &platform, bool create=false );
00082             
00085     QModelIndex componentIndex( const QString& registry, const QString& platform, 
00086                         const QString& component, bool create=false );
00087 
00090     QModelIndex interfaceIndex( const QString& registry, const QString& platform, 
00091                         const QString& component, const QString& interface, bool create=false );
00092 
00095     QModelIndex operationIndex( const QString& registry, const QString& platform, const QString& component, 
00096                        const QString& interface, const QString& operation, bool create=false );
00097 
00100     QModelIndex resultIndex( const QString& registry, const QString& platform, const QString& component, 
00101                        const QString& interface, const QString& operation, const QString& result, bool create=false );
00102 
00104     void setRegistry( const QString& registry, const QString& regAddress, bool connected );
00105 
00107     void setPlatform( const QString& registry, 
00108                       const QString &platform );
00109             
00111     void setComponent( const QString& registry, const QString& platform,
00112                        const QString& component, const QString& compAddress, bool connected );
00113 
00115     void setInterface( const QString& registry, const QString& platform, const QString& component,
00116                        const QString& interface, const bool isProvided, const QString& ids, bool isEnabled );
00117 
00119     void setOperation( const QString& registry, const QString& platform, const QString& component, 
00120                                     const QString& interface, 
00121                        const QString& operation, const QString& signature );
00122 
00124     void setResult( const QString& registry, const QString& platform, const QString& component, 
00125                                     const QString& interface, const QString& operation, 
00126                        const QString& result, const QString& text );
00127 
00131     int interfaceData( const QModelIndex& ind,
00132                        QString& registry, QString& platform, QString& component,
00133                        QString& interface, QString& id );
00134     
00138     int interfacesOnPlatform( const QModelIndex& ind,
00139                               QStringList& registries, QStringList& platforms, QStringList& components,
00140                               QStringList& interfaces, QStringList& ids );
00141     
00143     int interfacesOnComponent( const QModelIndex& ind,
00144                               QStringList& registries, QStringList& platforms, QStringList& components,
00145                               QStringList& interfaces, QStringList& ids );
00146     
00147     // OBSOLETE OcmModel specific API
00148 
00149     void setPlatform( const QString& registry, const QString& regAddress, const QString &platform )
00150             { setPlatformPrivate( registry, regAddress, platform ); };
00151             
00152     void setComponent( const QString& registry, const QString& regAddress, const QString& platform,
00153                         const QString& component, const QString& compAddress, bool connected )
00154             { setComponentPrivate( registry, regAddress, platform, component, compAddress, connected ); };
00155 
00156     void setInterface( const QString& registry, const QString& regAddress,
00157                        const QString& platform, const QString& component,
00158                        const QString& interface, const bool isProvided,
00159                        const QString& compAddress, const QString& ids,
00160                        bool connected )
00161             { setInterfacePrivate( registry, regAddress, platform, component, interface,
00162                     isProvided, compAddress, ids, connected ); };
00163 
00164 public slots:
00166     void clear();
00167 
00168 private:
00169 
00170     enum NodeType
00171     {
00172         RegistryType,
00173         PlatformType,
00174         ComponentType,
00175         InterfaceType,
00176         OperationType,
00177         ResultType
00178     };
00179 
00180     enum InterfaceSubtype
00181     {
00182         ProvidedInterfaceSubtype,
00183         RequiredInterfaceSubtype
00184     };
00185 
00186     class Node
00187     {
00188     public:
00189         virtual ~Node() {};
00190         virtual NodeType type()=0;
00191     };
00192     
00193     class RegistryNode;
00194     class PlatformNode;
00195     class ComponentNode;
00196     class InterfaceNode;
00197     class OperationNode;
00198     class ResultNode;
00199 
00200     class ResultNode : public Node
00201     {
00202     public:
00203         ResultNode( const QString &n, OperationNode* o )
00204             : name(n), operation(o) {};
00205         // to be used in list search, name is sufficient
00206         bool operator==( const ResultNode& other ) const
00207         {
00208             return name==other.name;
00209         }
00210         QString name;
00211         OperationNode* operation;
00212         QString result;
00213         virtual NodeType type() { return ResultType; };
00214     };
00215 
00216     class OperationNode : public Node
00217     {
00218     public:
00219         OperationNode( const QString &n, InterfaceNode* i )
00220             : name(n), interface(i) {};
00221         // to be used in list search, name is sufficient
00222         bool operator==( const OperationNode& other ) const
00223         {
00224             return name==other.name;
00225         }
00226         QString name;
00227         QString signature;
00228         InterfaceNode* interface;
00229         QList<ResultNode> results;
00230         virtual NodeType type() { return OperationType; };
00231     };
00232 
00233     class InterfaceNode : public Node
00234     {
00235     public:
00236         InterfaceNode( const QString &n, ComponentNode* c )
00237             : name(n), component(c) {};
00238         // to be used in list search, name is sufficient
00239         bool operator==( const InterfaceNode& other ) const
00240         {
00241             return name==other.name;
00242         }
00243         QString name;
00244         ComponentNode* component;
00245         InterfaceSubtype subtype;
00246         // not very clean: only provided interfaces can have operations 
00247         QList<OperationNode> operations;
00248         QString ids;
00249         bool isEnabled;
00250         virtual NodeType type() { return InterfaceType; };
00251     };
00252     
00253     class ComponentNode : public Node
00254     {
00255     public:
00256         ComponentNode( const QString &n, PlatformNode* p, 
00257             const QString &a="", bool connected=true );
00258         // to be used in list search, name is sufficient
00259         bool operator==( const ComponentNode& other ) const
00260         {
00261             return name==other.name;
00262         }
00263         QString name;
00264         PlatformNode* platform;
00265         QList<InterfaceNode> interfaces;
00266         QString address;
00267         bool isEnabled;
00268 //         int daysUp;
00269 //         QTime timeUp;
00270         virtual NodeType type() { return ComponentType; };
00271     };
00272     
00273     class PlatformNode : public Node
00274     {
00275     public:
00276         PlatformNode( const QString &n, RegistryNode* r )
00277             : name(n), registry(r) {};
00278         // to be used in list search, name is sufficient
00279         bool operator==( const PlatformNode& other ) const
00280         {
00281             return name==other.name;
00282         }
00283         QString name;
00284         RegistryNode* registry;
00285         QList<ComponentNode> components;
00286         bool isEnabled;
00287         virtual NodeType type() { return PlatformType; };
00288     };
00289 
00290     class RegistryNode : public Node
00291     {
00292     public:
00293         RegistryNode( const QString &n, const QString &a="", bool connected=true )
00294             : name(n), address(a), isEnabled(connected) {};
00295         // to be used in list search, name is sufficient
00296         bool operator==( const RegistryNode& other ) const
00297         {
00298             return name==other.name;
00299         }
00300         QString name;
00301         QList<PlatformNode> platforms;
00302         QString address;
00303         bool isEnabled;
00304         virtual NodeType type() { return RegistryType; };
00305     };
00306 
00307     // top level of data storage
00308     QList<RegistryNode> registries_;
00309 
00310     QStringList headers_;
00311 
00312     OcmIconProvider iconProvider_;
00313 
00314     // OBSOLETE
00315     QModelIndex setPlatformPrivate( const QString& registry, const QString& regAddress,
00316                                     const QString &platform );
00317     
00318     QModelIndex setComponentPrivate( const QString& registry, const QString& regAddress,
00319                                 const QString& platform, const QString& component,
00320                                 const QString& compAddress, bool connected );
00321 
00322     QModelIndex setInterfacePrivate( const QString& registry, const QString& regAddress,
00323                                 const QString& platform, const QString& component, const QString& interface,
00324                                 const bool isProvided, const QString& compAddress, const QString& ids,
00325                                 bool connected );
00326 
00327 };
00328 
00329 } // namespace
00330 
00331 #endif
 

Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)


Generated for Orca Robotics by  doxygen 1.4.5