dialogselect.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "dialogselect.h"
  2. #include "ui_dialogselect.h"
  3. #include <QGroupBox>
  4. #include <QScrollArea>
  5. DialogSelect::DialogSelect(std::vector<std::string> xvectorlist, std::vector<std::string> &xvectorused,QWidget *parent) :
  6. QDialog(parent),
  7. ui(new Ui::DialogSelect)
  8. {
  9. ui->setupUi(this);
  10. mpvectorused = &xvectorused;
  11. QGroupBox * pGroup = new QGroupBox();
  12. pGroup->setGeometry(50,100,560,3000);
  13. QScrollArea * pScroll = new QScrollArea(this);
  14. pScroll->setWidget(pGroup);
  15. pScroll->setGeometry(30,100,600,300);
  16. int ntotalwidth = 560;
  17. int ncheckwidth = 80;
  18. int ncheckheight = 23;
  19. int nhospace = 100;
  20. int nvespace = 30;
  21. unsigned int i;
  22. int ipos = 0;
  23. int jpos = 0;
  24. for(i=0;i<xvectorlist.size();i++)
  25. {
  26. QCheckBox * pcheck = new QCheckBox(pGroup);
  27. pcheck->setGeometry(30+ipos*nhospace,30+jpos*nvespace,ncheckwidth,ncheckheight);
  28. pcheck->setText(xvectorlist[i].data());
  29. mvectorcheck.push_back(pcheck);
  30. unsigned int j;
  31. bool bused = false;
  32. for(j=0;j<xvectorused.size();j++)
  33. {
  34. if(xvectorused[j] == xvectorlist[i])
  35. {
  36. bused = true;
  37. break;
  38. }
  39. }
  40. pcheck->setChecked(bused);
  41. ipos++;
  42. if(ipos>=((ntotalwidth -30)/nhospace))
  43. {
  44. ipos = 0;
  45. jpos++;
  46. }
  47. }
  48. setWindowTitle("Select Chart Item");
  49. }
  50. DialogSelect::~DialogSelect()
  51. {
  52. delete ui;
  53. }
  54. void DialogSelect::on_pushButton_Select_clicked()
  55. {
  56. mpvectorused->clear();
  57. unsigned int i;
  58. for(i=0;i<mvectorcheck.size();i++)
  59. {
  60. if(mvectorcheck[i]->isChecked())
  61. {
  62. mpvectorused->push_back(mvectorcheck[i]->text().toStdString());
  63. }
  64. }
  65. this->accept();
  66. }