PageRenderTime 313ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/mainwindow.cpp

https://gitlab.com/refaQtor/manualLog
C++ | 188 lines | 148 code | 29 blank | 11 comment | 7 complexity | be60bbdaaed1d4bad3885f3910999170 MD5 | raw file
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QCoreApplication>
  4. #include <QDebug>
  5. #include <QDir>
  6. #include <QUrl>
  7. #include <QDesktopServices>
  8. #include "qlogevent.h"
  9. #include "csvmodelwriter.h"
  10. //TODO: (done) filter in log combo
  11. //TODO: (done) export to csv
  12. //TODO: allow unfiltered log display, blank first combo entry by default(if works) else wrap filter labels in wildcard regex *
  13. //TODO: config export location
  14. //TODO: (done) about box
  15. //TODO: help doc launch
  16. //TODO: feedback web launch
  17. //TODO: config events
  18. MainWindow::MainWindow(QWidget *parent)
  19. : QMainWindow(parent), ui(new Ui::MainWindow),
  20. Settings(new QSettings()),
  21. Qlog(new QlogApp(this)),
  22. TimeUpdater(new QTimer())
  23. {
  24. ui->setupUi(this);
  25. loadEventWidgets();
  26. loadLogTable();
  27. loadLogFilter();
  28. connect(TimeUpdater, SIGNAL(timeout()),this, SLOT(updateTime()));
  29. updateTime();
  30. TimeUpdater->start(1000*60);
  31. }
  32. MainWindow::~MainWindow()
  33. {
  34. delete TimeUpdater;
  35. delete Settings;
  36. delete Qlog;
  37. delete ui;
  38. }
  39. void MainWindow::updateTime()
  40. {
  41. ui->EventDateTime->setDateTime(QDateTime::currentDateTime());
  42. }
  43. void MainWindow::setOrientation(ScreenOrientation orientation)
  44. {
  45. #if defined(Q_OS_SYMBIAN)
  46. // If the version of Qt on the device is < 4.7.2, that attribute won't work
  47. if (orientation != ScreenOrientationAuto) {
  48. const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
  49. if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
  50. qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
  51. return;
  52. }
  53. }
  54. #endif // Q_OS_SYMBIAN
  55. Qt::WidgetAttribute attribute;
  56. switch (orientation) {
  57. #if QT_VERSION < 0x040702
  58. // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
  59. case ScreenOrientationLockPortrait:
  60. attribute = static_cast<Qt::WidgetAttribute>(128);
  61. break;
  62. case ScreenOrientationLockLandscape:
  63. attribute = static_cast<Qt::WidgetAttribute>(129);
  64. break;
  65. default:
  66. case ScreenOrientationAuto:
  67. attribute = static_cast<Qt::WidgetAttribute>(130);
  68. break;
  69. #else // QT_VERSION < 0x040702
  70. case ScreenOrientationLockPortrait:
  71. attribute = Qt::WA_LockPortraitOrientation;
  72. break;
  73. case ScreenOrientationLockLandscape:
  74. attribute = Qt::WA_LockLandscapeOrientation;
  75. break;
  76. default:
  77. case ScreenOrientationAuto:
  78. attribute = Qt::WA_AutoOrientation;
  79. break;
  80. #endif // QT_VERSION < 0x040702
  81. };
  82. setAttribute(attribute, true);
  83. }
  84. void MainWindow::showExpanded()
  85. {
  86. #if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
  87. showFullScreen();
  88. #elif defined(Q_WS_MAEMO_5)
  89. showMaximized();
  90. #else
  91. show();
  92. #endif
  93. }
  94. void MainWindow::loadEventWidgets()
  95. {
  96. loadEventCombo();
  97. }
  98. void MainWindow::on_action_Quit_triggered()
  99. {
  100. close();
  101. }
  102. void MainWindow::loadEventCombo()
  103. {
  104. ui->EventCombo->addItems(Qlog->EventList());
  105. qDebug() << "combo list should be :" << Qlog->EventList();
  106. }
  107. void MainWindow::loadLogTable()
  108. {
  109. ui->tableView->setModel(Qlog->ProxyModel());
  110. }
  111. void MainWindow::loadLogFilter()
  112. {
  113. // ui->QueryCombo->addItem("");
  114. ui->QueryCombo->addItems(Qlog->EventList());
  115. }
  116. void MainWindow::triggerLogAction(int index)
  117. {
  118. QlogEvent *tolog = new QlogEvent();
  119. tolog->setLabel(Qlog->EventList().at(index));
  120. tolog->setDateTime(ui->EventDateTime->dateTime());
  121. tolog->setValue(ui->EventValue->value());
  122. tolog->setNote(ui->EventNote->text());
  123. Qlog->logEvent(tolog);
  124. }
  125. void MainWindow::on_action_Event_triggered()
  126. {
  127. ui->pages->setCurrentIndex(1);
  128. }
  129. void MainWindow::on_action_Log_triggered()
  130. {
  131. Qlog->TableModel()->select();
  132. ui->pages->setCurrentIndex(2);
  133. }
  134. void MainWindow::on_action_About_triggered()
  135. {
  136. ui->pages->setCurrentIndex(0);
  137. }
  138. void MainWindow::on_AddEventButton_clicked()
  139. {
  140. triggerLogAction(ui->EventCombo->currentIndex());
  141. }
  142. void MainWindow::on_QueryCombo_currentIndexChanged(const QString &arg1)
  143. {
  144. Qlog->ProxyModel()->setFilterFixedString(arg1);
  145. }
  146. void MainWindow::on_ExportDataButton_clicked()
  147. {
  148. QString exportfilename(tr("%1-%2-%3%4")
  149. .arg(QCoreApplication::applicationName())
  150. .arg(ui->QueryCombo->currentText())
  151. .arg(QDateTime::currentDateTime().toString("yyyy.MM.dd.hh.mm"))
  152. .arg(".csv"));
  153. QString exportfilepath(QDir::toNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)+"/"));
  154. QString exportcomplete(exportfilepath + exportfilename);
  155. CSVModelWriter csv(exportcomplete);
  156. csv.setModel(Qlog->ProxyModel());
  157. csv.write();
  158. QDesktopServices::openUrl(QUrl("file:///" + exportfilepath));// + exportcomplete)); //just open folder, file handling app start inconsistent
  159. }