DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
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 "ui_ErrorListDialog.h"
6#include "ErrorListDialog.h"
7
9{
10 return Other.Origin == Origin && Other.Text == Text && Other.ErrorType == ErrorType && Other.TreeWidgetItem == TreeWidgetItem;
11}
12
14 : QDialog(parent, Qt::Widget | Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint),
15 ui(std::make_unique<Ui::ErrorListDialog>()),
18{
19 setAttribute(Qt::WA_TranslucentBackground);
20
21 ui->setupUi(this);
22
23 ui->TWErrorList->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeMode::Fixed);
24 ui->TWErrorList->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::ResizeToContents);
25}
26
30
32{
33 return ClosedByClickingOpenWidget && std::chrono::system_clock::now() < LastCloseTime + std::chrono::milliseconds(500);
34}
35
37{
38 if (ui->TWErrorList->rowCount() && ErrorEntries == CurrentErrorEntries)
39 return;
40
41 ui->TWErrorList->clear();
42 ui->TWErrorList->setRowCount(0);
43
44 for (auto& ErrorEntry : ErrorEntries)
45 {
46 QIcon Icon(ErrorEntry.ErrorType == Util::ErrorType::Error ? DynExpUI::Icons::Error :
48
49 const auto Row = ui->TWErrorList->rowCount();
50 ui->TWErrorList->insertRow(Row);
51
52 ui->TWErrorList->setItem(Row, 0, new QTableWidgetItem(Icon, ErrorEntry.Text));
53 ui->TWErrorList->item(Row, 0)->setToolTip("Double-click to go to item.");
54 ui->TWErrorList->item(Row, 0)->setData(Qt::ItemDataRole::UserRole, QVariant::fromValue(ErrorEntry.TreeWidgetItem));
55 ui->TWErrorList->setItem(Row, 1, new QTableWidgetItem(ErrorEntry.Origin));
56 ui->TWErrorList->item(Row, 1)->setToolTip(ui->TWErrorList->item(Row, 0)->toolTip());
57 ui->TWErrorList->item(Row, 1)->setData(Qt::ItemDataRole::UserRole, QVariant::fromValue(ErrorEntry.TreeWidgetItem));
58 }
59
60 if (ErrorEntries.empty())
61 {
62 ui->TWErrorList->insertRow(0);
63 ui->TWErrorList->setItem(0, 0, new QTableWidgetItem(QIcon(DynExpUI::Icons::Info), "No errors or warnings."));
64 ui->TWErrorList->item(0, 0)->setToolTip(ui->TWErrorList->item(0, 0)->text());
65 ui->TWErrorList->item(0, 0)->setData(Qt::ItemDataRole::UserRole, QVariant::fromValue(static_cast<decltype(ErrorEntryType::TreeWidgetItem)>(nullptr)));
66 }
67
68 CurrentErrorEntries = ErrorEntries;
69}
70
72{
73 auto OldSelectionChanged = SelectionChanged;
74 SelectionChanged = false;
75
76 return OldSelectionChanged ? SelectedTreeWidgetItem : nullptr;
77}
78
79void ErrorListDialog::paintEvent(QPaintEvent* event)
80{
81 QVector<QPointF> BalloonVertices;
82 const float Offset = 0;
83 BalloonVertices << QPointF(Offset, Offset)
84 << QPointF(width() - Offset, Offset)
85 << QPointF(width() - Offset, height() * 0.97)
86 << QPointF(width() * 0.04, height() * 0.97)
87 << QPointF(width() * 0.03, height() - Offset)
88 << QPointF(width() * 0.02, height() * 0.97)
89 << QPointF(Offset, height() * 0.97);
90 auto BalloonPolygon = QPolygonF(BalloonVertices);
91
92 QPainter painter(this);
93 painter.setRenderHint(QPainter::Antialiasing, true);
94 painter.setBrush(QBrush(ui->TWErrorList->palette().color(QWidget::backgroundRole())));
95 painter.setPen(QPen(ui->TWErrorList->palette().color(QWidget::foregroundRole())));
96
97 QRegion Mask(BalloonPolygon.toPolygon(), Qt::WindingFill);
98 painter.drawPolygon(BalloonPolygon);
99 setMask(Mask);
100
101 ui->TWErrorList->horizontalHeader()->resizeSection(0, width() / 4 * 3);
102}
103
104void ErrorListDialog::focusOutEvent(QFocusEvent* event)
105{
106 if (!ui->TWErrorList->hasFocus())
107 {
108 // Remember wheter this dialog has been closed by clicking on the widget which opens the dialog again.
109 // Direct reopening would be strange behavior, so avoid that (refer to DynExpManager::OnStatusBarStateClicked()).
111 LastCloseTime = std::chrono::system_clock::now();
112
113 hide();
114 }
115 else
116 setFocus();
117}
118
120{
121 SelectionChanged = true;
122 SelectedTreeWidgetItem = item->data(Qt::ItemDataRole::UserRole).value<decltype(ErrorEntryType::TreeWidgetItem)>();
123
124 hide();
125}
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()
virtual void paintEvent(QPaintEvent *event) override
QTreeWidgetItem * SelectedTreeWidgetItem
bool ClosedByClickingOpenWidget
void SetErrorEntries(const ErrorEntriesType &ErrorEntries)
std::unique_ptr< Ui::ErrorListDialog > ui
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
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