26 #include <QHeaderView>
28 #include <QPushButton>
29 #include <QSignalMapper>
30 #include <QStandardItemModel>
33 #include <QVBoxLayout>
41 QString RunningTimeToString(
unsigned int time)
43 int seconds = time % 60;
45 int minutes = time % 60;
47 int hours = time % 24;
50 return QString::fromStdString(
57 QString StateToString(
const ExplorationTask &task)
59 switch(task.GetState()) {
60 case TaskState::Waiting:
61 if (task.GetNumberOfTries() == 0)
65 + QString::fromStdString(to_string(task.GetNumberOfTries())) +
")";
66 case TaskState::Running:
68 case TaskState::Finished:
70 case TaskState::Cancelled:
72 case TaskState::Failed:
75 assert(
false &&
"This task is in an unknown state.");
82 TaskOverview::TaskOverview()
83 : m_exploration_progress(nullptr), m_table(nullptr), m_model(nullptr), m_refresh_timer(new QTimer(this))
85 setMinimumHeight(300);
88 QVBoxLayout* layout =
new QVBoxLayout;
90 m_table =
new QTableView(
this);
91 m_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
92 m_model =
new QStandardItemModel(m_table);
94 QPushButton* close_button =
new QPushButton(
"Close");
95 connect(close_button, SIGNAL(clicked()),
this, SLOT(close()));
97 layout->addWidget(m_table);
98 layout->addWidget(close_button);
104 connect(m_refresh_timer, SIGNAL(timeout()),
this, SLOT(Refresh()));
105 m_refresh_timer->setInterval(1000);
110 m_refresh_timer->stop();
117 header <<
"Id" <<
"Status"<<
"Action" <<
"Time" <<
"Node";
120 m_exploration_progress = explorationProgress;
121 if (m_exploration_progress) {
122 const Exploration& exploration = m_exploration_progress->GetExploration();
125 header << QString::fromStdString(param).split(
'.').last();
128 m_model->setHorizontalHeaderLabels(header);
130 QSignalMapper* stop_signal =
new QSignalMapper(
this);
131 QSignalMapper* restart_signal =
new QSignalMapper(
this);
132 connect(stop_signal, SIGNAL(mapped(
int)),
this, SIGNAL(
StopTask(
int)));
133 connect(restart_signal, SIGNAL(mapped(
int)),
this, SIGNAL(
StartTask(
int)));
136 auto task = m_exploration_progress->GetTask(i);
137 auto state = task.GetState();
139 m_model->setItem(i, j++,
new QStandardItem(QString::number(i)));
140 m_model->setItem(i, j++,
new QStandardItem(StateToString(task)));
141 m_model->setItem(i, j++, 0);
142 m_model->setItem(i, j++,
new QStandardItem(RunningTimeToString(task.GetRunningTime())));
145 QPushButton* button =
new QPushButton(
"Stop");
146 connect(button, SIGNAL(clicked()), stop_signal, SLOT(map()));
147 stop_signal->setMapping(button, i);
148 m_table->setIndexWidget(m_model->index(i,2), button);
150 QPushButton* button =
new QPushButton(
"Restart");
151 connect(button, SIGNAL(clicked()), restart_signal, SLOT(map()));
152 restart_signal->setMapping(button, i);
153 m_table->setIndexWidget(m_model->index(i,2), button);
155 m_model->setItem(i, j++,
new QStandardItem(QString::fromStdString(task.getNodeIp())+
":"+QString::number(task.getNodePort())));
157 for (
const std::string &value : exploration.
GetValues(i)) {
158 m_model->setItem(i, j++,
new QStandardItem(QString::fromStdString(value)));
163 m_model->setHorizontalHeaderLabels(header);
164 m_table->setModel(m_model);
165 m_table->resizeColumnsToContents();
166 m_table->horizontalHeader()->setStretchLastSection(
true);
171 m_refresh_timer->start();
172 QWidget::showEvent(event);
177 m_refresh_timer->stop();
178 QWidget::hideEvent(event);
181 void TaskOverview::Refresh()
183 if (m_exploration_progress) {
184 auto num = m_exploration_progress->GetExploration().GetNumberOfTasks();
185 for (
unsigned int i = 0; i < num; ++i) {
186 m_model->setItem(i, 3,
new QStandardItem(
187 RunningTimeToString(m_exploration_progress->GetTask(i).GetRunningTime())));
Interface for Exploration.
Interface for TaskOverview.
The task is waiting to be sent for the first time.
string ToString(Type w)
Converts a WallType::Type value to corresponding name.
virtual unsigned int GetNumberOfTasks() const =0
Returns the number of tasks the exploration currently contains.
virtual std::vector< std::string > GetValues(unsigned int index) const =0
Return the values of a certain task.
virtual ~TaskOverview()
Destructor.
virtual std::vector< std::string > GetParameters() const =0
Returns all the parameters in the exploration.
static std::string ToString(const T &value)
Builds a string representation of a value of type T.
void UpdateExploration(const std::shared_ptr< const ExplorationProgress > &explorationProgress)
Update the current exploration.
void StartTask(int task)
Send message to restart a stopped task.
virtual void showEvent(QShowEvent *event) override
Overriding QWidget::showEvent to start the refresh timer.
virtual void hideEvent(QHideEvent *event) override
Overriding QWidget::hideEvent to stop the refresh timer.
void StopTask(int task)
Send message to stop a certain task.
String manipulation utilities.
Namespace for SimPT parameter explorer package.
Class describing a generic exploration.