DynExp
Highly flexible laboratory automation for dynamically changing experiments.
ErrorListDialog.cpp
Go to the documentation of this file.
1 // This file is part of DynExp.
2 
3 #include "stdafx.h"
4 #include "moc_ErrorListDialog.cpp"
5 #include "ErrorListDialog.h"
6 
8 {
9  return Other.Origin == Origin && Other.Text == Text && Other.ErrorType == ErrorType && Other.TreeWidgetItem == TreeWidgetItem;
10 }
11 
13  : QDialog(parent, Qt::Widget | Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint),
16 {
17  setAttribute(Qt::WA_TranslucentBackground);
18 
19  ui.setupUi(this);
20 
21  ui.TWErrorList->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeMode::Fixed);
22  ui.TWErrorList->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::ResizeToContents);
23 }
24 
26 {
27 }
28 
30 {
31  return ClosedByClickingOpenWidget && std::chrono::system_clock::now() < LastCloseTime + std::chrono::milliseconds(500);
32 }
33 
35 {
36  if (ui.TWErrorList->rowCount() && ErrorEntries == CurrentErrorEntries)
37  return;
38 
39  ui.TWErrorList->clear();
40  ui.TWErrorList->setRowCount(0);
41 
42  for (auto& ErrorEntry : ErrorEntries)
43  {
44  QIcon Icon(ErrorEntry.ErrorType == Util::ErrorType::Error ? DynExpUI::Icons::Error :
46 
47  const auto Row = ui.TWErrorList->rowCount();
48  ui.TWErrorList->insertRow(Row);
49 
50  ui.TWErrorList->setItem(Row, 0, new QTableWidgetItem(Icon, ErrorEntry.Text));
51  ui.TWErrorList->item(Row, 0)->setToolTip("Double-click to go to item.");
52  ui.TWErrorList->item(Row, 0)->setData(Qt::ItemDataRole::UserRole, QVariant::fromValue(ErrorEntry.TreeWidgetItem));
53  ui.TWErrorList->setItem(Row, 1, new QTableWidgetItem(ErrorEntry.Origin));
54  ui.TWErrorList->item(Row, 1)->setToolTip(ui.TWErrorList->item(Row, 0)->toolTip());
55  ui.TWErrorList->item(Row, 1)->setData(Qt::ItemDataRole::UserRole, QVariant::fromValue(ErrorEntry.TreeWidgetItem));
56  }
57 
58  if (ErrorEntries.empty())
59  {
60  ui.TWErrorList->insertRow(0);
61  ui.TWErrorList->setItem(0, 0, new QTableWidgetItem(QIcon(DynExpUI::Icons::Info), "No errors or warnings."));
62  ui.TWErrorList->item(0, 0)->setToolTip(ui.TWErrorList->item(0, 0)->text());
63  ui.TWErrorList->item(0, 0)->setData(Qt::ItemDataRole::UserRole, QVariant::fromValue(static_cast<decltype(ErrorEntryType::TreeWidgetItem)>(nullptr)));
64  }
65 
66  CurrentErrorEntries = ErrorEntries;
67 }
68 
70 {
71  auto OldSelectionChanged = SelectionChanged;
72  SelectionChanged = false;
73 
74  return OldSelectionChanged ? SelectedTreeWidgetItem : nullptr;
75 }
76 
77 void ErrorListDialog::paintEvent(QPaintEvent* event)
78 {
79  QVector<QPointF> BalloonVertices;
80  const float Offset = 0;
81  BalloonVertices << QPointF(Offset, Offset)
82  << QPointF(width() - Offset, Offset)
83  << QPointF(width() - Offset, height() * 0.97)
84  << QPointF(width() * 0.04, height() * 0.97)
85  << QPointF(width() * 0.03, height() - Offset)
86  << QPointF(width() * 0.02, height() * 0.97)
87  << QPointF(Offset, height() * 0.97);
88  auto BalloonPolygon = QPolygonF(BalloonVertices);
89 
90  QPainter painter(this);
91  painter.setRenderHint(QPainter::Antialiasing, true);
92  painter.setBrush(QBrush(ui.TWErrorList->palette().color(QWidget::backgroundRole())));
93  painter.setPen(QPen(ui.TWErrorList->palette().color(QWidget::foregroundRole())));
94 
95  QRegion Mask(BalloonPolygon.toPolygon(), Qt::WindingFill);
96  painter.drawPolygon(BalloonPolygon);
97  setMask(Mask);
98 
99  ui.TWErrorList->horizontalHeader()->resizeSection(0, width() / 4 * 3);
100 }
101 
102 void ErrorListDialog::focusOutEvent(QFocusEvent* event)
103 {
104  if (!ui.TWErrorList->hasFocus())
105  {
106  // Remember wheter this dialog has been closed by clicking on the widget which opens the dialog again.
107  // Direct reopening would be strange behavior, so avoid that (refer to DynExpManager::OnStatusBarStateClicked()).
109  LastCloseTime = std::chrono::system_clock::now();
110 
111  hide();
112  }
113  else
114  setFocus();
115 }
116 
117 void ErrorListDialog::ErrorEntryDoubleClicked(QTableWidgetItem* item)
118 {
119  SelectionChanged = true;
120  SelectedTreeWidgetItem = item->data(Qt::ItemDataRole::UserRole).value<decltype(ErrorEntryType::TreeWidgetItem)>();
121 
122  hide();
123 }
Implements a frame-less pop-up dialog to show errors and warning of DynExp::Object instances.
void ErrorEntryDoubleClicked(QTableWidgetItem *item)
QWidget * WidgetToOpenThisDialog
virtual void focusOutEvent(QFocusEvent *event) override
ErrorEntriesType CurrentErrorEntries
QTreeWidgetItem * GetSelectedEntry()
Ui::ErrorListDialog ui
virtual void paintEvent(QPaintEvent *event) override
QTreeWidgetItem * SelectedTreeWidgetItem
bool ClosedByClickingOpenWidget
void SetErrorEntries(const ErrorEntriesType &ErrorEntries)
ErrorListDialog(QWidget *parent, QWidget *WidgetToOpenThisDialog)
std::vector< ErrorEntryType > ErrorEntriesType
bool HasBeenClosedByClickingOpenWidget() const noexcept
std::chrono::time_point< std::chrono::system_clock > LastCloseTime
constexpr auto Warning
constexpr auto Info
constexpr auto Error
Accumulates include statements to provide a precompiled header.
QTreeWidgetItem * TreeWidgetItem
Pointer to QTreeWidgetItem listed in main window's tree view. Do not dereference this pointer!...
bool operator==(const ErrorEntryType &Other) const