printerthreadhandle.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  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::printerBox1,manger,&PrinterManger::printerBox1,Qt::QueuedConnection);
  21. connect(this,&PrinterThreadHandle::printerBoxModel,manger,&PrinterManger::printerBoxModel,Qt::QueuedConnection);
  22. connect(this,&PrinterThreadHandle::printerPack,manger,&PrinterManger::printerPack,Qt::QueuedConnection);
  23. connect(this,&PrinterThreadHandle::printerPackModel,manger,&PrinterManger::printerPackModel,Qt::QueuedConnection);
  24. auto config = GlobalInfo::this_()->config();
  25. connect(config,&ConfigInfo::configUpdate,this,&PrinterThreadHandle::updateConfig,Qt::QueuedConnection);
  26. manger->setPrinter(QSharedPointer<BaseBoxPrinter>(new BoxTemlateOne()),QSharedPointer<BasePackinfoPrinter>(new PackTemlateOne()));
  27. this->moveToThread(thread);
  28. thread->start();
  29. }
  30. }