printerthreadhandle.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. #include "printerthreadhandle.h"
  2. #include "globalinfo.h"
  3. #include "handle/printer/boxtemlateone.h"
  4. PrinterThreadHandle::PrinterThreadHandle(QObject *parent) : QObject(parent),manger(nullptr),thread(nullptr)
  5. {
  6. }
  7. void PrinterThreadHandle::updateConfig()
  8. {
  9. if(manger == nullptr) return;
  10. auto config = GlobalInfo::this_()->config();
  11. manger->setPrinterName(config->printerName);
  12. }
  13. void PrinterThreadHandle::start()
  14. {
  15. if(thread == nullptr){
  16. thread = new QThread(this);
  17. connect(thread,&QThread::started,this,&PrinterThreadHandle::updateConfig);
  18. manger = new PrinterManger(this);
  19. connect(this,&PrinterThreadHandle::printerBox,manger,&PrinterManger::printerBox,Qt::QueuedConnection);
  20. connect(this,&PrinterThreadHandle::printerBoxModel,manger,&PrinterManger::printerBoxModel,Qt::QueuedConnection);
  21. connect(this,&PrinterThreadHandle::printerPack,manger,&PrinterManger::printerPack,Qt::QueuedConnection);
  22. connect(this,&PrinterThreadHandle::printerPackModel,manger,&PrinterManger::printerPackModel,Qt::QueuedConnection);
  23. auto config = GlobalInfo::this_()->config();
  24. connect(config,&ConfigInfo::configUpdate,this,&PrinterThreadHandle::updateConfig,Qt::QueuedConnection);
  25. manger->setPrinter(QSharedPointer<BaseBoxPrinter>(new BoxTemlateOne()),QSharedPointer<BasePackinfoPrinter>(new PackTemlateOne()));
  26. this->moveToThread(thread);
  27. thread->start();
  28. }
  29. }