Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Common/LtsWidgets/lts_dialog_button_box.cpp
T
torstenandCopilot d6b6ffce7c Apply clang-format to Lts/Common and DTC/enum headers
- Formatted all CodeGen module files (9 files)
- Formatted LtsAppDescriptor module files
- Formatted LtsAppManager/AppChooser files
- Applied clang-format to all DTC and enum headers across modules
- Removed coordTransTests from CommonUnitTestsPlaceholder (moved to tests/)

Cosmetic changes only, no functional modifications.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-08-19 14:46:29 +02:00

200 lines
5.3 KiB
C++

#include "lts_dialog_button_box.h"
#include "lts_message_dialog.h"
#include "ui_lts_dialog_button_box.h"
#include <LtsSession/lts_session_data.h>
#include <QMenu>
namespace LtsWidgets
{
LtsDialogButtonBox::LtsDialogButtonBox(QWidget* parent)
: QWidget(parent), m_isTablet(LtsSessionData::LtsSessionData::getInstance()->isTablet()),
m_ui(new Ui::LtsDialogButtonBox)
{
m_ui->setupUi(this);
_setVisibilityForAll(false);
QMenu* libraryMenu = new QMenu(m_ui->pbLibrary);
libraryMenu->addAction(QIcon(QLatin1String(":/style/library_load.svg")), tr("Load"), this,
&LtsDialogButtonBox::signalLibraryLoadClicked);
libraryMenu->addAction(QIcon(QLatin1String(":/style/library_save.svg")), tr("Save"), this,
&LtsDialogButtonBox::signalLibrarySaveClicked);
m_ui->pbLibrary->setMenu(libraryMenu);
m_ui->pbOk->setVisible(true);
m_ui->pbClose->setVisible(true);
}
LtsDialogButtonBox::~LtsDialogButtonBox()
{
delete m_ui;
}
void LtsDialogButtonBox::_setVisibilityForAll(bool visible)
{
const auto buttons = findChildren<QPushButton*>();
for (QPushButton* button : buttons)
button->setVisible(visible);
}
void LtsDialogButtonBox::setText(DialogButton button, const QString& text)
{
QPushButton* btn = getButton(button);
if (btn)
btn->setText(text);
}
void LtsDialogButtonBox::setToolTip(DialogButton button, const QString& text)
{
QPushButton* btn = getButton(button);
if (btn)
btn->setToolTip(text);
}
void LtsDialogButtonBox::setIcon(DialogButton button, const QIcon& icon)
{
QPushButton* btn = getButton(button);
if (btn)
btn->setIcon(icon);
}
void LtsDialogButtonBox::setMenu(DialogButton button, QMenu* menu)
{
QPushButton* btn = getButton(button);
if (btn)
btn->setMenu(menu);
}
QPushButton* LtsDialogButtonBox::getButton(DialogButton button) const
{
switch (button)
{
case DialogButton::ReadOnly:
return m_ui->pbReadOnly;
case DialogButton::Ok:
return m_ui->pbOk;
case DialogButton::Apply:
return m_ui->pbApply;
case DialogButton::Close:
return m_ui->pbClose;
case DialogButton::Yes:
return m_ui->pbYes;
case DialogButton::No:
return m_ui->pbNo;
case DialogButton::Remove:
return m_ui->pbRemove;
case DialogButton::Hide:
return m_ui->pbHide;
case DialogButton::Add:
return m_ui->pbAdd;
case DialogButton::Help:
return m_ui->pbHelp;
case DialogButton::Edit:
return m_ui->pbEdit;
case DialogButton::Save:
return m_ui->pbSave;
case DialogButton::Load:
return m_ui->pbLoad;
case DialogButton::Show:
return m_ui->pbShow;
case DialogButton::Import:
return m_ui->pbImport;
case DialogButton::Export:
return m_ui->pbExport;
case DialogButton::Library:
return m_ui->pbLibrary;
case DialogButton::CenterMap:
return m_ui->pbCenterMap;
case DialogButton::ZoomMapTo:
return m_ui->pbZoomMapTo;
case DialogButton::Print:
return m_ui->pbPrint;
#ifdef LTS_DEBUG
case DialogButton::_debug_:
return m_ui->_pbChanges;
#endif
}
Q_ASSERT(false);
return nullptr;
}
void LtsDialogButtonBox::slotRemoveClicked()
{
if (LtsMessageDialog::showMessage(this, tr("Are you sure you want to delete the selected entry(ies)?"),
tr("Remove selected entry(ies)"), Behaviour::Modal,
Button::Yes | Button::No) == Button::Yes)
emit signalRemoveClicked();
}
void LtsDialogButtonBox::setButtonsVisible(QPushButton* pb)
{
if (!pb || (pb == m_ui->pbPrint && m_isTablet))
return;
m_ui->line->setVisible(true);
pb->setVisible(true);
}
void LtsDialogButtonBox::setButtonVisible(DialogButton button, bool visible)
{
QPushButton* pb = getButton(button);
if (!pb)
return;
if (m_isTablet && pb == m_ui->pbPrint)
{
pb->setVisible(false);
return;
}
pb->setVisible(visible);
}
bool LtsDialogButtonBox::isButtonVisible(DialogButton button) const
{
const QPushButton* pb = getButton(button);
return (pb ? pb->isVisible() : false);
}
void LtsDialogButtonBox::setButtonEnabled(DialogButton button, bool enabled)
{
QPushButton* pb = getButton(button);
switch (button)
{
case DialogButton::Close:
case DialogButton::Ok:
case DialogButton::Apply:
{
#ifdef LTS_DEBUG
LtsMessageDialog::showMessage(
this,
QStringLiteral("Hier stimmt etwas nicht. Bitte MIKE bescheid geben WAS geklickt oder gemacht wurde als "
"dieser Dialog auftauchte, damit ich es fixen kann. Danke."),
QStringLiteral(">>> STOP <<<"));
#endif
break;
}
default:
break;
}
if (pb)
pb->setEnabled(enabled);
}
bool LtsDialogButtonBox::isButtonEnabled(DialogButton button) const
{
auto* that = const_cast<LtsDialogButtonBox*>(this);
const QPushButton* pb = that->getButton(button);
return (pb ? pb->isEnabled() : false);
}
} // namespace LtsWidgets