No Description

blockdata.cpp 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "blockdata.h"
  2. #include <QDebug>
  3. Blockdata::Blockdata(QObject *parent) : QObject(parent)
  4. {
  5. blocks = new QList<Block>;
  6. }
  7. void Blockdata::addBlock(uint16_t word) {
  8. Block block(word);
  9. blocks->append(block);
  10. }
  11. void Blockdata::addBlock(Block block) {
  12. blocks->append(block);
  13. }
  14. QByteArray Blockdata::serialize() {
  15. QByteArray data;
  16. for (int i = 0; i < blocks->length(); i++) {
  17. Block block = blocks->value(i);
  18. uint16_t word = block.rawValue();
  19. data.append(word & 0xff);
  20. data.append((word >> 8) & 0xff);
  21. }
  22. return data;
  23. }
  24. void Blockdata::copyFrom(Blockdata* other) {
  25. blocks->clear();
  26. for (int i = 0; i < other->blocks->length(); i++) {
  27. addBlock(other->blocks->value(i));
  28. }
  29. }
  30. Blockdata* Blockdata::copy() {
  31. Blockdata* blockdata = new Blockdata;
  32. blockdata->copyFrom(this);
  33. return blockdata;
  34. }
  35. bool Blockdata::equals(Blockdata *other) {
  36. if (!other) {
  37. return false;
  38. }
  39. if (blocks->length() != other->blocks->length()) {
  40. return false;
  41. }
  42. for (int i = 0; i < blocks->length(); i++) {
  43. if (blocks->value(i) != other->blocks->value(i)) {
  44. return false;
  45. }
  46. }
  47. return true;
  48. }