blobpartitionrectangle.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #include "blobpartitionrectangle.h"
  2. #include "ui_blobpartitionrectangle.h"
  3. #include "../ToolDialog.h"
  4. class ToolDialogImpl;
  5. BlobPartitionRectangle::BlobPartitionRectangle(QWidget *parent , ToolDialogImpl* p) : ToolInterface(parent), ui(new Ui::BlobPartitionRectangle)
  6. {
  7. ui->setupUi(this);
  8. m_pToolDialogImpl = p;
  9. ui->lineEdit_width->setText("5");
  10. ui->lineEdit_height->setText("5");
  11. ui->lineEdit_width->setValidator(new QIntValidator(1, 16777215, this));
  12. ui->lineEdit_height->setValidator(new QIntValidator(1, 16777215, this));
  13. ui->comboBox_index->setView(new QListView());
  14. if(m_pToolDialogImpl->m_LinkProcess.size() > 0)
  15. {
  16. ui->comboBox_index->setVisible(true);
  17. ui->label_index->setVisible(true);
  18. }
  19. else
  20. {
  21. ui->comboBox_index->setVisible(false);
  22. ui->label_index->setVisible(false);
  23. }
  24. for(int i = 0; i < m_pToolDialogImpl->m_LinkProcess.size(); i++)
  25. {
  26. ui->comboBox_index->addItem(QString::number(i));
  27. }
  28. }
  29. BlobPartitionRectangle::~BlobPartitionRectangle()
  30. {
  31. delete ui;
  32. }
  33. bool BlobPartitionRectangle::Serialized(QDataStream& ar, bool bIsOut)
  34. {
  35. int paranum;//参数数量
  36. if (bIsOut)//保存参数流程
  37. {
  38. paranum = 3;
  39. ar << paranum;//先保存参数数量
  40. ar << (int)1 << m_nWidth;
  41. ar << (int)2 << m_nHeight;
  42. ar << (int)3 << ui->comboBox_index->currentIndex();
  43. }
  44. else//加载参数流程,参数加载顺序一定要跟保存顺序一致
  45. {
  46. int nCurrentIndex1 = 0;
  47. int nCurrentIndex2 = 0;
  48. int para;
  49. ar >> paranum;//读取参数数量
  50. for (int i = 0; i < paranum; i++)
  51. {
  52. ar >> para;
  53. switch (para)
  54. {
  55. case 1: ar >> m_nWidth; break;
  56. case 2: ar >> m_nHeight; break;
  57. case 3: ar >> nCurrentIndex1; break;
  58. default:
  59. {
  60. qWarning() << "Serialized(In) Error";
  61. return false;
  62. }
  63. break;
  64. }
  65. }
  66. {
  67. ui->comboBox_index->setCurrentIndex(nCurrentIndex1);
  68. ui->lineEdit_width->setText(QString::number(m_nWidth));
  69. ui->lineEdit_height->setText(QString::number(m_nHeight));
  70. emit updateParameter(ShowParameter());
  71. }
  72. }
  73. return true;
  74. }
  75. QString BlobPartitionRectangle::ShowParameter()
  76. {
  77. QString str;
  78. m_nWidth = ui->lineEdit_width->text().toInt();
  79. m_nHeight = ui->lineEdit_height->text().toInt();
  80. str += QString::number(m_nWidth);
  81. str += ",";
  82. str += QString::number(m_nHeight);
  83. return str;
  84. }
  85. int BlobPartitionRectangle::Execute()
  86. {
  87. int result = 1;
  88. m_nWidth = ui->lineEdit_width->text().toInt();
  89. m_nHeight = ui->lineEdit_height->text().toInt();
  90. try
  91. {
  92. if(ui->comboBox_index->currentIndex() == 0)
  93. {
  94. PartitionRectangle (m_InImage, &m_OutImage, m_nWidth, m_nHeight);
  95. }
  96. else
  97. {
  98. int index = ui->comboBox_index->currentIndex() - 1;
  99. HObject inputimage = m_pToolDialogImpl->m_LinkProcess[index].p_dlg->GetResult();
  100. PartitionRectangle (inputimage, &m_OutImage, m_nWidth, m_nHeight);
  101. }
  102. }
  103. catch(...)
  104. {
  105. }
  106. return result;
  107. }
  108. void BlobPartitionRectangle::on_BTN_Add1_clicked()
  109. {
  110. ui->lineEdit_width->setText(QString::number(ui->lineEdit_width->text().toInt() + 1));
  111. emit updateParameter(ShowParameter());
  112. }
  113. void BlobPartitionRectangle::on_BTN_Sub1_clicked()
  114. {
  115. if(ui->lineEdit_width->text().toInt() >= 2)
  116. {
  117. ui->lineEdit_width->setText(QString::number(ui->lineEdit_width->text().toInt() - 1));
  118. emit updateParameter(ShowParameter());
  119. }
  120. }
  121. void BlobPartitionRectangle::on_BTN_Add2_clicked()
  122. {
  123. ui->lineEdit_height->setText(QString::number(ui->lineEdit_height->text().toInt() + 1));
  124. emit updateParameter(ShowParameter());
  125. }
  126. void BlobPartitionRectangle::on_BTN_Sub2_clicked()
  127. {
  128. if(ui->lineEdit_height->text().toInt() >= 2)
  129. {
  130. ui->lineEdit_height->setText(QString::number(ui->lineEdit_height->text().toInt() - 1));
  131. emit updateParameter(ShowParameter());
  132. }
  133. }
  134. void BlobPartitionRectangle::on_lineEdit_width_editingFinished()
  135. {
  136. emit updateParameter(ShowParameter());
  137. }
  138. void BlobPartitionRectangle::on_lineEdit_height_editingFinished()
  139. {
  140. emit updateParameter(ShowParameter());
  141. }
  142. void BlobPartitionRectangle::on_comboBox_index_currentIndexChanged(int index)
  143. {
  144. if(index > 0)
  145. {
  146. emit updateParameterIndex(QString::number(index - 1));
  147. }
  148. emit updateParameter(ShowParameter());
  149. }