openrecentdialog.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "openrecentdialog.h"
  2. #include "ui_openrecentdialog.h"
  3. OpenRecentDialog::OpenRecentDialog(QWidget *parent) : QDialog(parent), ui(new Ui::OpenRecentDialog)
  4. {
  5. ui->setupUi(this);
  6. setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);
  7. m_pid = -1;
  8. }
  9. OpenRecentDialog::~OpenRecentDialog()
  10. {
  11. delete ui;
  12. }
  13. void OpenRecentDialog::setMyDao(MyDao *mydao)
  14. {
  15. m_mydao = mydao;
  16. QSqlQuery qry;
  17. QString sql = "select b.name,a.pid from mind_history a left join mind_data b on a.pid=b.id where b.name is not "
  18. "null order by a.id desc";
  19. m_mydao->sqliteWrapper->select(sql, qry);
  20. QSet<int> ids;
  21. while (qry.next()) {
  22. int pid = qry.value(1).toInt();
  23. if (!ids.contains(pid)) {
  24. QListWidgetItem *item = new QListWidgetItem();
  25. item->setText(qry.value(0).toString());
  26. item->setData(Qt::UserRole, qry.value(1).toInt());
  27. ui->lvData->addItem(item);
  28. ids << pid;
  29. }
  30. }
  31. }
  32. int OpenRecentDialog::pid()
  33. {
  34. return m_pid;
  35. }
  36. void OpenRecentDialog::on_lvData_itemClicked(QListWidgetItem *item)
  37. {
  38. m_pid = item->data(Qt::UserRole).toInt();
  39. }
  40. void OpenRecentDialog::on_btnCancel_clicked()
  41. {
  42. reject();
  43. }
  44. void OpenRecentDialog::on_btnOk_clicked()
  45. {
  46. accept();
  47. }