No Description

blockdata.cpp 911B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "blockdata.h"
  2. Blockdata::Blockdata(QObject *parent) : QObject(parent)
  3. {
  4. blocks = new QList<Block>;
  5. }
  6. void Blockdata::addBlock(uint16_t word) {
  7. Block block(word);
  8. blocks->append(block);
  9. }
  10. void Blockdata::addBlock(Block block) {
  11. blocks->append(block);
  12. }
  13. QByteArray Blockdata::serialize() {
  14. QByteArray data;
  15. for (int i = 0; i < blocks->length(); i++) {
  16. Block block = blocks->value(i);
  17. uint16_t word = block.rawValue();
  18. data.append(word & 0xff);
  19. data.append((word >> 8) & 0xff);
  20. }
  21. return data;
  22. }
  23. void Blockdata::copyFrom(Blockdata* other) {
  24. blocks->clear();
  25. for (int i = 0; i < other->blocks->length(); i++) {
  26. addBlock(other->blocks->value(i));
  27. }
  28. }
  29. Blockdata* Blockdata::copy() {
  30. Blockdata* blockdata = new Blockdata;
  31. blockdata->copyFrom(this);
  32. return blockdata;
  33. }