datetimehelp.cpp
Go to the documentation of this file.
1 #include "datetimehelp.h"
2 #include "ui_datetimehelp.h"
3 
4 #include <QScrollBar>
5 
6 // Source: https://stackoverflow.com/a/42458736
7 void verticalResizeTableViewToContents(QTableView* tableView)
8 {
9  int count = tableView->verticalHeader()->count();
10  int scrollBarHeight = 0;
11  if (tableView->horizontalScrollBar()->isVisible())
12  {
13  scrollBarHeight = tableView->horizontalScrollBar()->height();
14  }
15  int horizontalHeaderHeight = tableView->horizontalHeader()->height();
16  int rowTotalHeight = 0;
17  for (int i = 0; i < count; ++i)
18  {
19  // 2018-03 edit: only account for row if it is visible
20  if (!tableView->verticalHeader()->isSectionHidden(i))
21  {
22  rowTotalHeight += tableView->verticalHeader()->sectionSize(i);
23  }
24  }
25  tableView->setMinimumHeight(horizontalHeaderHeight + rowTotalHeight + scrollBarHeight);
26 }
27 
29  : QDialog(parent), ui(new Ui::DateTimeHelp), _parent(parent)
30 {
31  ui->setupUi(this);
32 
33  verticalResizeTableViewToContents(ui->dateFormatTable);
34  verticalResizeTableViewToContents(ui->timeFormatTable);
35 
37 
38  connect(ui->exampleDateTimeDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this,
39  [this]() { refreshExample(); });
40 
41  connect(ui->exampleFormatStringLineEdit, &QLineEdit::textChanged, this,
42  [this]() { refreshExample(); });
43 
44  connect(_parent, &QDialog::finished, this, [this]() {
45  if (ui->autoCloseCheckBox->isChecked())
46  {
47  accept();
48  }
49  });
50 }
51 
53 {
54  delete ui;
55 }
56 
58 {
59  auto dateTime = ui->exampleDateTimeDateTimeEdit->dateTime();
60  auto formatString = ui->exampleFormatStringLineEdit->text();
61  ui->resultLineEdit->setText(dateTime.toString(formatString));
62 }
DateTimeHelp::refreshExample
void refreshExample()
Definition: datetimehelp.cpp:57
verticalResizeTableViewToContents
void verticalResizeTableViewToContents(QTableView *tableView)
Definition: datetimehelp.cpp:7
DateTimeHelp::_parent
QDialog * _parent
Definition: datetimehelp.h:24
DateTimeHelp
Definition: datetimehelp.h:11
datetimehelp.h
DateTimeHelp::ui
Ui::DateTimeHelp * ui
Definition: datetimehelp.h:22
detail::count
constexpr auto count() -> size_t
Definition: core.h:1222
Ui
Definition: cheatsheet_dialog.h:6
DateTimeHelp::DateTimeHelp
DateTimeHelp(QDialog *parent=nullptr)
Definition: datetimehelp.cpp:28
DateTimeHelp::~DateTimeHelp
~DateTimeHelp()
Definition: datetimehelp.cpp:52


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:44