Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #ifndef DATAMODEL_H
  2. #define DATAMODEL_H
  3.  
  4. #include <QAbstractItemModel>
  5. #include <QList>
  6. #include <QMap>
  7. #include <QModelIndex>
  8. #include <QObject>
  9.  
  10. class StationData;
  11.  
  12. namespace DataRole {
  13. static const int DisplayName = Qt::DisplayRole;
  14. static const int StationName = Qt::UserRole + 1;
  15. static const int TransferFunction = Qt::UserRole +1;
  16. }
  17.  
  18. class Station
  19. {
  20. public:
  21.  
  22. QMap<QString, StationData> data_;
  23.  
  24. QString station_id_;
  25.  
  26. void printAll() const;
  27. int id;
  28. };
  29.  
  30. class StationData
  31. {
  32. public:
  33. StationData() : x(3.14159) {}
  34. StationData(double xx) : x(xx) { }
  35. double x;
  36. };
  37.  
  38. class DataModel : public QAbstractItemModel
  39. {
  40. Q_OBJECT
  41. public:
  42. explicit DataModel(QObject *parent = 0);
  43.  
  44. virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
  45. virtual QModelIndex parent(const QModelIndex &child) const;
  46. virtual int rowCount(const QModelIndex &parent = QModelIndex() ) const;
  47. virtual int columnCount(const QModelIndex &parent = QModelIndex() ) const;
  48. virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
  49.  
  50. void addItem(const Station &station);
  51. void printModel();
  52.  
  53. signals:
  54.  
  55. public slots:
  56.  
  57. private:
  58.  
  59. QList<Station> stations_;
  60. };
  61.  
  62.  
  63. //// Example:
  64.  
  65. //Station: 001
  66. // Ex: -2
  67. // Ey: -3
  68. // Hx: -100
  69. // Hy: 100
  70. // Hz: 200
  71.  
  72. //Station: 002
  73. // Ex: 1
  74. // Ey: 10
  75. // Hz: 3.14159
  76.  
  77. #endif // DATAMODEL_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement