Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00067
00068 public:
00069
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
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
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 };
00169
00170 #endif