numberbuild.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #include "numberbuild.h"
  2. NumberBuild::NumberBuild()
  3. {
  4. this->stop =false;
  5. this->relation = 0;//0:and 1:or
  6. }
  7. NumberBuild::~NumberBuild()
  8. {
  9. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  10. <<"NumberBuild Destroyed.";
  11. }
  12. void NumberBuild::setList(QStringList list)
  13. {
  14. this->segments = list;
  15. }
  16. void NumberBuild::setRelation(int relation)
  17. {
  18. this->relation = relation;
  19. }
  20. void NumberBuild::setRegList(QStringList regList)
  21. {
  22. this->regList = regList;
  23. }
  24. void NumberBuild::abort()
  25. {
  26. this->stop = true;
  27. }
  28. void NumberBuild::run()
  29. {
  30. switch(relation)
  31. {
  32. case 0:
  33. buildByAnd();
  34. break;
  35. case 1:
  36. buildByOr();
  37. break;
  38. default:
  39. break;
  40. }
  41. }
  42. //void NumberBuild::run()
  43. //{
  44. // QStringList tails;
  45. // emit progressMaxUpdated(9999);
  46. // for(int j=0; j<10000; j++)
  47. // {
  48. // QString tail = "000"+QString::number(j);
  49. // bool allmatch = true;
  50. // for(int k=0;k<this->regList.size();k++)
  51. // {
  52. // QRegExp rx(regList.at(k));
  53. // if(!rx.exactMatch(tail.right(4)))
  54. // {
  55. // allmatch = false;
  56. // break;
  57. // }
  58. // }
  59. // if(allmatch)
  60. // tails << tail.right(4);
  61. // emit progressUpdated(j);
  62. // }
  63. // int howmany = segments.size();
  64. // for(int i=0;i < howmany ; i++)
  65. // {
  66. // this->numbers.append(tails);
  67. // }
  68. // appendModel();
  69. // emit numberBuilt(newModel);
  70. //}
  71. void NumberBuild::appendModel()
  72. {
  73. newModel = new NumberListModel();
  74. newModel->setNumberList(segments,numbers);
  75. }
  76. void NumberBuild::buildByOr()
  77. {
  78. QStringList tails;
  79. emit progressMaxUpdated(9999);
  80. for(int j=0; j<10000; j++)
  81. {
  82. QString tail = "000"+QString::number(j);
  83. bool allmatch = false;
  84. for(int k=0;k<this->regList.size();k++)
  85. {
  86. QRegExp rx(regList.at(k));
  87. if(rx.exactMatch(tail.right(4)))
  88. {
  89. allmatch = true;
  90. break;
  91. }
  92. else
  93. {
  94. continue;
  95. }
  96. }
  97. if(allmatch)
  98. tails << tail.right(4);
  99. emit progressUpdated(j);
  100. }
  101. int howmany = segments.size();
  102. for(int i=0;i < howmany ; i++)
  103. {
  104. this->numbers.append(tails);
  105. }
  106. appendModel();
  107. emit numberBuilt(newModel);
  108. }
  109. void NumberBuild::buildByAnd()
  110. {
  111. QStringList tails;
  112. emit progressMaxUpdated(9999);
  113. for(int j=0; j<10000; j++)
  114. {
  115. QString tail = "000"+QString::number(j);
  116. bool allmatch = true;
  117. for(int k=0;k<this->regList.size();k++)
  118. {
  119. QRegExp rx(regList.at(k));
  120. if(!rx.exactMatch(tail.right(4)))
  121. {
  122. allmatch = false;
  123. break;
  124. }
  125. }
  126. if(allmatch)
  127. tails << tail.right(4);
  128. emit progressUpdated(j);
  129. }
  130. int howmany = segments.size();
  131. for(int i=0;i < howmany ; i++)
  132. {
  133. this->numbers.append(tails);
  134. }
  135. appendModel();
  136. emit numberBuilt(newModel);
  137. }