14#include <QDialogButtonBox>
17#include <Kanoop/utility/loggingbaseclass.h>
18#include <Kanoop/entitymetadata.h>
19#include <Kanoop/timespan.h>
20#include <Kanoop/gui/libkanoopgui.h>
22#define COMPARE(a, b) compare(a, b)
31class LIBKANOOPGUI_EXPORT
Dialog :
public QDialog,
32 public LoggingBaseClass
37 explicit Dialog(QWidget* parent =
nullptr);
44 explicit Dialog(
const QString& loggingCategory, QWidget* parent =
nullptr);
194 void setDefaultSize(
int width,
int height) { _defaultSize = QSize(width, height); }
200 QDialogButtonBox*
buttonBox()
const {
return _buttonBox; }
215 virtual void loggedItem(
const Log::LogEntry& entry) { Q_UNUSED(entry) }
218 bool compare(
const QString& a,
const QString& b) {
return a != b; }
220 bool compare(
const QUuid& a,
const QUuid& b) {
return a != b; }
222 bool compare(
const QList<QUuid>& a,
const QList<QUuid>& b) {
return a != b; }
224 bool compare(
const int a,
int b) {
return a != b; }
226 bool compare(
const TimeSpan& a,
const TimeSpan& b) {
return a != b; }
253 void connectLineEditSignals();
255 void connectTextEditSignals();
257 void connectComboBoxSignals();
259 void connectRadioButtonSignals();
261 void connectCheckBoxSignals();
263 void connectSpinBoxSignals();
265 void connectButtonBoxSignals();
267 void setButtonBoxButtons();
270 void closeLogConsumer();
272 template <
typename T>
273 void appendToList(QList<QWidget*>& list,
const QList<T>& typedList)
const
275 for(T widget : typedList) {
276 QWidget* w = qobject_cast<QWidget*>(widget);
283 QDialogButtonBox* _buttonBox =
nullptr;
284 QStatusBar* _statusBar =
nullptr;
285 bool _formLoadComplete =
false;
286 bool _formLoadFailed =
false;
290 bool _applyEnabled =
true;
291 bool _cancelEnabled =
true;
292 bool _okEnabled =
true;
296 bool _persistPosition =
true;
297 bool _persistSize =
true;
298 bool _restoreToParentScreen =
true;
300 LogConsumer* _logConsumer =
nullptr;
326 void onLoggedItem(
const Log::LogEntry& entry);
328 void onSplitterMoved();
332 void onApplyClicked();
334 void onCancelClicked();
QDialog subclass providing logging, validation, persistence, and button-box management.
void setPersistSize(bool value)
Enable or disable size persistence.
void setStatusBarVisible(bool value)
Show or hide the status bar.
virtual void onPreferencesChanged()
Called when application preferences change; override to react.
bool isValid() const
Return whether the current form state is valid.
void performLayout()
Perform layout and button-box wiring; call from the subclass constructor.
virtual void boolChanged(bool)
Trigger validation when a boolean input changes.
void setApplyEnabled(bool value)
Enable or disable the Apply button.
Dialog(const QString &loggingCategory, QWidget *parent=nullptr)
Construct with a logging category and optional parent.
void setDefaultSize(int width, int height)
Set the default dialog size by width and height.
QDialogButtonBox * buttonBox() const
Return the dialog button box.
bool restoreToParentScreen() const
Return whether to restore to the parent screen on show.
virtual void enableAppropriateButtons()
Update button enabling based on current validity and dirty state.
void setFormLoadFailed(bool value)
Set the form load failure flag.
bool compare(const QList< QUuid > &a, const QList< QUuid > &b)
Return true if a != b (used with COMPARE macro).
QColor defaultTextColor() const
Return the default text color from the current palette.
void setDefaultSize(const QSize &value)
Set the default dialog size.
QStatusBar * statusBar() const
Return the dialog status bar.
virtual void stringChanged(const QString &)
Trigger validation when a string input changes.
bool persistSize() const
Return whether the dialog persists its size between sessions.
void itemAdded(const EntityMetadata &metadata)
Emitted after an item is added via this dialog.
virtual void validate()=0
Implement to validate the form and call setValid()/setDirty().
bool formLoadComplete() const
Return whether the form has finished loading.
bool compare(const int a, int b)
Return true if a != b (used with COMPARE macro).
void setOkEnabled(bool value)
Enable or disable the OK button.
void connectValidationSignals()
Connect all child input widget signals to the validation slots.
bool isDirty() const
Return whether the form has unsaved changes.
void itemUpdated(const EntityMetadata &metadata)
Emitted after an item is updated via this dialog.
bool compare(const TimeSpan &a, const TimeSpan &b)
Return true if a != b (used with COMPARE macro).
QSize defaultSize() const
Return the default dialog size.
bool formLoadFailed() const
Return whether the form failed to load.
void setPersistPosition(bool value)
Enable or disable position persistence.
virtual void cancelClicked()
Called when the Cancel button is clicked (no-op by default).
virtual void moveEvent(QMoveEvent *event) override
Persist position on move.
void setCancelEnabled(bool value)
Enable or disable the Cancel button.
virtual void resizeEvent(QResizeEvent *event) override
Persist size on resize.
bool compare(const QString &a, const QString &b)
Return true if a != b (used with COMPARE macro).
Dialog(QWidget *parent=nullptr)
Construct with an optional parent.
virtual void applyClicked()
Called when the Apply button is clicked (no-op by default).
void setDirty(bool value)
Set the dirty flag.
bool persistPosition() const
Return whether the dialog persists its position between sessions.
void setValid(bool value)
Set the form validity state and update button enabling accordingly.
void setRestoreToParentScreen(bool value)
Enable or disable restore-to-parent-screen behaviour.
virtual void okClicked()
Called when the OK button is clicked (no-op by default).
void setLogHookEnabled(bool enabled)
Enable or disable the log consumer hook for this dialog.
virtual void voidChanged()
Trigger validation when a parameterless signal fires.
virtual ~Dialog()
Destructor — closes any open log consumer.
bool compare(const QUuid &a, const QUuid &b)
Return true if a != b (used with COMPARE macro).
virtual void loggedItem(const Log::LogEntry &entry)
Called when a log entry is delivered (no-op by default).
virtual void intChanged(int)
Trigger validation when an integer input changes.
virtual void showEvent(QShowEvent *event) override
Restore geometry and complete form load on first show.
void setChildInputWidgetsEnabled(QWidget *widget, bool enabled)
Enable or disable all input child widgets of a given widget.
void itemDeleted(const EntityMetadata &metadata)
Emitted after an item is deleted via this dialog.