1
0

hexcmprangewin.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "hexcmprangewin.h"
  2. #include <QLineEdit>
  3. #include <QMessageBox>
  4. HexCmpRangeWin::HexCmpRangeWin(QWidget *parent)
  5. : QDialog(parent), m_isCancel(true)
  6. {
  7. ui.setupUi(this);
  8. connect(ui.leftStartPos, &QLineEdit::textChanged, this, &HexCmpRangeWin::slot_asyncStartPos);
  9. connect(ui.leftCmpLens, &QLineEdit::textChanged, this, &HexCmpRangeWin::slot_asyncLenPos);
  10. }
  11. HexCmpRangeWin::~HexCmpRangeWin()
  12. {
  13. }
  14. void HexCmpRangeWin::slot_ok()
  15. {
  16. m_isCancel = false;
  17. close();
  18. }
  19. //通过左边的值同步右边。右边不同步左边,加速用户输入
  20. void HexCmpRangeWin::slot_asyncStartPos(const QString& text)
  21. {
  22. ui.rightStartPos->setText(text);
  23. }
  24. void HexCmpRangeWin::slot_asyncLenPos(const QString& text)
  25. {
  26. ui.rightCmpLens->setText(text);
  27. }
  28. //如果取消,则不返回任何有效范围值;错误值也是
  29. const int MAX_CMP_LENS = 1024 * 1024 * 10;
  30. void HexCmpRangeWin::getRange(bool & isCancel, qint64 & leftStartPos, int & leftCmpLen, qint64 & rightStartPos, int & rightCmpLen)
  31. {
  32. isCancel = m_isCancel;
  33. if (isCancel)
  34. {
  35. return;
  36. }
  37. bool ok = false;
  38. bool ok1 = false;
  39. bool ok2 = false;
  40. bool ok3 = false;
  41. leftStartPos = ui.leftStartPos->text().toULongLong(&ok);
  42. leftCmpLen = ui.leftCmpLens->text().toInt(&ok1);
  43. rightStartPos = ui.rightStartPos->text().toULongLong(&ok2);
  44. rightCmpLen = ui.rightCmpLens->text().toInt(&ok3);
  45. if (!ok || !ok1 || !ok2 || !ok3)
  46. {
  47. isCancel = true;
  48. leftStartPos = -1;
  49. rightStartPos = -1;
  50. leftCmpLen = 0;
  51. rightCmpLen = 0;
  52. QMessageBox::warning(this, tr("Error"), tr("StartPos or cmpare lens value error."));
  53. return;
  54. }
  55. if (leftCmpLen > MAX_CMP_LENS)
  56. {
  57. leftCmpLen = MAX_CMP_LENS;
  58. }
  59. if (rightCmpLen > MAX_CMP_LENS)
  60. {
  61. rightCmpLen = MAX_CMP_LENS;
  62. }
  63. }