$search
00001 /* 00002 Aseba - an event-based framework for distributed robot control 00003 Copyright (C) 2007--2012: 00004 Stephane Magnenat <stephane at magnenat dot net> 00005 (http://stephane.magnenat.net) 00006 and other contributors, see authors.txt for details 00007 00008 This program is free software: you can redistribute it and/or modify 00009 it under the terms of the GNU Lesser General Public License as published 00010 by the Free Software Foundation, version 3 of the License. 00011 00012 This program 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 License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #ifndef TARGET_MODELS_H 00022 #define TARGET_MODELS_H 00023 00024 #include <QAbstractTableModel> 00025 #include <QAbstractItemModel> 00026 #include <QVector> 00027 #include <QList> 00028 #include <QString> 00029 #include <QRegExp> 00030 #include "../compiler/compiler.h" 00031 00032 00033 namespace Aseba 00034 { 00037 00038 struct TargetDescription; 00039 class TargetVariablesModel; 00040 00042 class VariableListener 00043 { 00044 protected: 00045 TargetVariablesModel *variablesModel; 00046 00047 public: 00048 VariableListener(TargetVariablesModel* variablesModel); 00049 virtual ~VariableListener(); 00050 00051 bool subscribeToVariableOfInterest(const QString& name); 00052 void unsubscribeToVariableOfInterest(const QString& name); 00053 void unsubscribeToVariablesOfInterest(); 00054 void invalidateVariableModel(); 00055 00056 protected: 00057 friend class TargetVariablesModel; 00059 virtual void variableValueUpdated(const QString& name, const VariablesDataVector& values) = 0; 00060 }; 00061 00062 class TargetVariablesModel: public QAbstractItemModel 00063 { 00064 Q_OBJECT 00065 00066 // FIXME: uses map for fast variable access 00067 00068 public: 00069 // variables 00070 struct Variable 00071 { 00072 QString name; 00073 unsigned pos; 00074 VariablesDataVector value; 00075 }; 00076 00077 public: 00078 TargetVariablesModel() { setSupportedDragActions(Qt::CopyAction); } 00079 virtual ~TargetVariablesModel(); 00080 00081 int rowCount(const QModelIndex &parent = QModelIndex()) const; 00082 int columnCount(const QModelIndex &parent = QModelIndex()) const; 00083 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; 00084 QModelIndex parent(const QModelIndex &index) const; 00085 00086 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 00087 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; 00088 Qt::ItemFlags flags(const QModelIndex & index) const; 00089 00090 bool setData(const QModelIndex &index, const QVariant &value, int role); 00091 00092 QStringList mimeTypes () const; 00093 QMimeData * mimeData ( const QModelIndexList & indexes ) const; 00094 00095 const QList<Variable>& getVariables() const { return variables; } 00096 unsigned getVariablePos(const QString& name) const; 00097 unsigned getVariableSize(const QString& name) const; 00098 VariablesDataVector getVariableValue(const QString& name) const; 00099 00100 public slots: 00101 void updateVariablesStructure(const Compiler::VariablesMap *variablesMap); 00102 void setVariablesData(unsigned start, const VariablesDataVector &data); 00103 bool setVariableValues(const QString& name, const VariablesDataVector& values); 00104 00105 signals: 00107 void variableValuesChanged(unsigned index, const VariablesDataVector &values); 00108 00109 private: 00110 friend class VariableListener; 00111 // VariableListener API 00112 00114 void unsubscribeViewPlugin(VariableListener* plugin); 00116 bool subscribeToVariableOfInterest(VariableListener* plugin, const QString& name); 00118 void unsubscribeToVariableOfInterest(VariableListener* plugin, const QString& name); 00120 void unsubscribeToVariablesOfInterest(VariableListener* plugin); 00121 00122 private: 00123 QList<Variable> variables; 00124 00125 // VariablesViewPlugin API 00126 typedef QMap<VariableListener*, QStringList> VariableListenersNameMap; 00127 VariableListenersNameMap variableListenersMap; 00128 }; 00129 00130 class TargetFunctionsModel: public QAbstractItemModel 00131 { 00132 Q_OBJECT 00133 00134 public: 00135 struct TreeItem; 00136 00137 public: 00138 TargetFunctionsModel(const TargetDescription *descriptionRead, QObject *parent = 0); 00139 ~TargetFunctionsModel(); 00140 00141 int rowCount(const QModelIndex &parent = QModelIndex()) const; 00142 int columnCount(const QModelIndex &parent = QModelIndex()) const; 00143 00144 QModelIndex parent(const QModelIndex &index) const; 00145 QModelIndex index(int row, int column, const QModelIndex &parent) const; 00146 00147 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 00148 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; 00149 Qt::ItemFlags flags(const QModelIndex & index) const; 00150 00151 QStringList mimeTypes () const; 00152 QMimeData * mimeData ( const QModelIndexList & indexes ) const; 00153 00154 public slots: 00155 void recreateTreeFromDescription(bool showHidden); 00156 00157 private: 00158 friend class AeslEditor; 00159 TreeItem *getItem(const QModelIndex &index) const; 00160 QString getToolTip(const TargetDescription::NativeFunction& function) const; 00161 00162 TreeItem* root; 00163 const TargetDescription *descriptionRead; 00164 QRegExp regExp; 00165 }; 00166 00168 }; // Aseba 00169 00170 #endif