Files
qt5-legatus-legacy/Lts/Plugins/InfrastructureManagement/Gui/ResourceManagement/PlanChooser/plan_chooser.cpp
T
2026-08-13 18:33:10 +02:00

144 lines
3.5 KiB
C++
Executable File

/**
* @RDE_HEADER@
* PlanChooser Payload UI
* $Id$
* $HeadURL$
* $Author$
* Created by Mike Wille, SLSE, 2016-08-12
*/
#include "plan_chooser.h"
#include "ui_plan_chooser.h"
#include "ism_plan_dialog_model.h"
#include "CustomViews/ism_schedule.h"
#include <LtsSession/lts_session_manager.h>
#include <LtsSession/lts_session.h>
#include <ConnectDialog/connect_dialog_nt.h>
#include <LtsWidgets/lts_global_wait_dialog.h>
#include <QCloseEvent>
#include <QPushButton>
#define DEVEL
namespace InfrastructureManagement
{
PlanChooser::PlanChooser(const std::shared_ptr<Interface::Dtc> &dtc, QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::PlanChooser)
, m_model(nullptr)
, m_dtc(dtc)
, m_selected(false)
, m_logger(getLogger("PlanChooser"))
{
LtsWidgets::LtsGlobalWaitDialog::getInstance()->setVisible(false);
m_ui->setupUi(this);
setWindowTitle(tr("Select Instrumentation Plan"));
setWindowFlags(windowFlags() | /*Qt::WindowStaysOnTopHint | */Qt::FramelessWindowHint); // hints..
m_ui->widget->seamless();
connect(m_ui->widget, &LtsDataView::LtsDataView::signalSelectionChanged,
this, &PlanChooser::enaDisa, Qt::QueuedConnection);
connect(m_ui->widget, &LtsDataView::LtsDataView::signalDoubleClicked,
this, &PlanChooser::slotPlanSelected, Qt::QueuedConnection);
connect(m_ui->pbNewPlan, &QPushButton::clicked,
this, &PlanChooser::signalNewPlan); //[this]() { emit signalNewPlan(); });
connect(m_ui->pbSelect, &QPushButton::clicked,
this, &PlanChooser::slotPlanSelected, Qt::QueuedConnection);
connect(m_ui->pbCancel, &QPushButton::clicked,
this, &PlanChooser::signalQuit, Qt::QueuedConnection);
connect(m_ui->pbCancel, &QPushButton::clicked,
this, [this]()
{
LtsWidgets::LtsGlobalWaitDialog::getInstance()->setVisible(true);
m_close = true;
close();
});
new LtsUtils::ConnectingDialogNT([this](int timeWait) { return m_dtc->waitForHistoricalDataMainSchedule(timeWait); }, tr("Infrastructure Management"), tr("Global"), parent);
}
bool PlanChooser::init(LtsSession::LtsSession *session)
{
m_session = session;
delete m_model;
m_model = new PlanDialogModel(this);
m_model->initModel(m_dtc);
m_ui->widget->selectCustomView();
m_ui->widget->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection);
m_ui->widget->setModel(m_model, [this]() { return new CustomViewSchedule(this); });
for (int i = 0; i < m_model->columnCount(); ++i)
m_ui->widget->hideColumn(i);
m_ui->widget->showColumn(PlanDialogModel::NAME);
return true;
}
PlanChooser::~PlanChooser()
{
LtsWidgets::LtsGlobalWaitDialog::getInstance()->setVisible(true);
delete m_ui;
}
void PlanChooser::reject()
{
if (!m_selected)
emit signalQuit();
QDialog::reject();
}
void PlanChooser::enaDisa()
{
//const QModelIndex idx = m_ui->widget->currentIndex();
//const MainSchedule ms = m_model->getRowData(idx.row());
m_ui->pbSelect->setEnabled(m_ui->widget->selectedRows().size() == 1);
}
void PlanChooser::closeEvent(QCloseEvent *event) // TODO: override reject()
{
if (!m_close)
event->ignore();
}
void PlanChooser::slotPlanSelected()
{
const QModelIndex idx = m_ui->widget->currentIndex();
const MainSchedule ms = m_model->getRowData(idx.row());
int id = ms.id();
if (id <= 0)
return;
m_selected = true;
emit signalSelectPlan(id);
m_close = true;
close();
}
void PlanChooser::selectPlan(int planId)
{
m_selected = true;
emit signalSelectPlan(planId);
m_close = true;
close();
}
} // namespace InfrastructureManagement