Skip to content
Snippets Groups Projects
Commit 2489927e authored by Philip Scherer's avatar Philip Scherer
Browse files

Add rough draft for MemoryViewer prediction widget

parent 21e225d8
No related branches found
No related tags found
1 merge request!254Add GUI for armem predictions to MemoryViewer
Showing
with 324 additions and 16 deletions
......@@ -54,6 +54,9 @@ set(SOURCES
query_widgets/SnapshotForm.cpp
query_widgets/SnapshotSelectorWidget.cpp
prediction_widget/PredictionWidget.cpp
prediction_widget/TimestampInput.cpp
commit_widget/CommitWidget.cpp
)
set(HEADERS
......@@ -98,6 +101,9 @@ set(HEADERS
query_widgets/SnapshotForm.h
query_widgets/SnapshotSelectorWidget.h
prediction_widget/PredictionWidget.h
prediction_widget/TimestampInput.h
commit_widget/CommitWidget.h
)
......
......@@ -86,3 +86,14 @@ QSplitter* armarx::gui::useSplitter(QLayout* layout)
return splitter;
}
armarx::gui::LeadingZeroSpinBox::LeadingZeroSpinBox(int numDigits, int base) :
numDigits(numDigits), base(base)
{
}
QString
armarx::gui::LeadingZeroSpinBox::textFromValue(int value) const
{
return QString("%1").arg(value, numDigits, base, QChar('0'));
}
......@@ -2,6 +2,7 @@
#include <QLayout>
#include <QLayoutItem>
#include <QSpinBox>
#include <QWidget>
class QLayout;
......@@ -56,4 +57,18 @@ namespace armarx::gui
*/
QSplitter* useSplitter(QLayout* layout);
// Source: https://stackoverflow.com/a/26538572
class LeadingZeroSpinBox : public QSpinBox
{
using QSpinBox::QSpinBox;
public:
LeadingZeroSpinBox(int numDigits, int base);
QString textFromValue(int value) const override;
private:
int numDigits;
int base;
};
}
......@@ -47,6 +47,12 @@ namespace armarx::armem::gui::memory
_memoryTabWidget->addTab(_snapshotSelectorWidget, QString("Snapshot Selection"));
}
{
_predictionWidget = new armem::gui::PredictionWidget();
_predictionWidget->setSizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Maximum);
_memoryTabWidget->addTab(_predictionWidget, QString("Prediction"));
}
{
_commitWidget = new armem::gui::CommitWidget();
_commitWidget->setSizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Maximum);
......
......@@ -4,6 +4,7 @@
#include <RobotAPI/libraries/armem_gui/memory/TreeWidget.h>
#include <RobotAPI/libraries/armem_gui/commit_widget/CommitWidget.h>
#include <RobotAPI/libraries/armem_gui/prediction_widget/PredictionWidget.h>
#include <RobotAPI/libraries/armem_gui/query_widgets/QueryWidget.h>
......@@ -49,6 +50,7 @@ namespace armarx::armem::gui::memory
QGroupBox* _memoryTabGroup;
QueryWidget* _queryWidget;
SnapshotSelectorWidget* _snapshotSelectorWidget;
PredictionWidget* _predictionWidget;
CommitWidget* _commitWidget;
};
......
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package RobotAPI::armem::gui
* @author phesch ( ulila at student dot kit dot edu )
* @date 2022
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#include "PredictionWidget.h"
#include <QComboBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QSpinBox>
#include <QVBoxLayout>
namespace armarx::armem::gui
{
PredictionWidget::PredictionWidget() :
memoryEntity(new QLineEdit()),
timestampInputSelector(new QComboBox()),
timestampLayout(new QHBoxLayout()),
instanceSpinner(new QSpinBox()),
predictionEngineSelector(new QComboBox()),
predictButton(new QPushButton("Copy prediction to clipboard"))
{
auto* vlayout = new QVBoxLayout();
// memoryEntity->editingFinished()
auto* hlayout = new QHBoxLayout();
hlayout->addWidget(memoryEntity);
hlayout->addWidget(new QLabel("Entity ID"));
vlayout->addLayout(hlayout);
timestampInputSelector->addItems({"Absolute", "Relative to latest", "Relative to now"});
timestampLayout->addWidget(timestampInputSelector);
vlayout->addLayout(timestampLayout);
//hlayout = new QHBoxLayout();
//instanceSpinner->setRange(0, std::numeric_limits<int>::max());
//hlayout->addWidget(instanceSpinner);
//hlayout->addWidget(new QLabel("Instance"));
//vlayout->addLayout(hlayout);
hlayout = new QHBoxLayout();
hlayout->addWidget(predictionEngineSelector);
hlayout->addWidget(new QLabel("Prediction engine"));
vlayout->addLayout(hlayout);
vlayout->addWidget(predictButton);
addTimestampInputMethod("Absolute", new AbsoluteTimestampInput());
addTimestampInputMethod("Relative to latest", new RelativeToLatestTimestampInput());
addTimestampInputMethod("Relative to now", new RelativeToNowTimestampInput());
setLayout(vlayout);
showTimestampInputMethod("Absolute");
}
void
PredictionWidget::addTimestampInputMethod(const QString& key, TimestampInput* input)
{
timestampInputs.emplace(key, input);
timestampLayout->addWidget(input);
}
void PredictionWidget::showTimestampInputMethod(const QString& key) // NOLINT
{
for (const auto& [inputKey, input] : timestampInputs)
{
input->setVisible(key == inputKey);
}
}
} // namespace armarx::armem::gui
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package RobotAPI::armem::gui
* @author phesch ( ulila at student dot kit dot edu )
* @date 2022
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
#include <map>
#include <QWidget>
#include "TimestampInput.h"
class QComboBox;
class QHBoxLayout;
class QLineEdit;
class QPushButton;
class QSpinBox;
namespace armarx::armem::gui
{
class PredictionWidget : public QWidget
{
Q_OBJECT // NOLINT
public:
PredictionWidget();
private:
QLineEdit* memoryEntity;
QComboBox* timestampInputSelector;
QHBoxLayout* timestampLayout;
QSpinBox* instanceSpinner;
QComboBox* predictionEngineSelector;
QPushButton* predictButton;
std::map<QString, TimestampInput*> timestampInputs;
void addTimestampInputMethod(const QString& key, TimestampInput* input);
private slots: // NOLINT
void showTimestampInputMethod(const QString& key);
};
} // namespace armarx::armem::gui
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package RobotAPI::armem::gui
* @author phesch ( ulila at student dot kit dot edu )
* @date 2022
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#include "TimestampInput.h"
#include <QDateTimeEdit>
#include <QHBoxLayout>
#include <RobotAPI/libraries/armem_gui/gui_utils.h>
namespace armarx::armem::gui
{
AbsoluteTimestampInput::AbsoluteTimestampInput() :
dateTime(new QDateTimeEdit(QDateTime::currentDateTime())),
microseconds(new armarx::gui::LeadingZeroSpinBox(6, 10))
{
dateTime->setDisplayFormat("yyyy-MM-dd HH:mm:ss");
microseconds->setRange(0, 1000 * 1000 - 1);
microseconds->setSingleStep(1);
// This cast is safe because 999 * 1000 < MAX_INT.
microseconds->setValue(
static_cast<int>((QDateTime::currentMSecsSinceEpoch() % 1000) * 1000));
auto* hlayout = new QHBoxLayout();
hlayout->addWidget(dateTime);
hlayout->addWidget(microseconds);
setLayout(hlayout);
}
RelativeTimestampInput::RelativeTimestampInput() :
seconds(new QDoubleSpinBox())
{
auto* hlayout = new QHBoxLayout();
seconds->setSingleStep(0.1);
seconds->setDecimals(6);
seconds->setValue(0);
setLayout(hlayout);
}
} // namespace armarx::armem::gui
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package RobotAPI::armem::gui
* @author phesch ( ulila at student dot kit dot edu )
* @date 2022
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
#include <QWidget>
class QDateTimeEdit;
class QDoubleSpinBox;
namespace armarx::gui
{
class LeadingZeroSpinBox;
}
namespace armarx::armem::gui
{
class TimestampInput : public QWidget
{
Q_OBJECT // NOLINT
};
class AbsoluteTimestampInput : public TimestampInput
{
Q_OBJECT // NOLINT
public : AbsoluteTimestampInput();
private:
QDateTimeEdit* dateTime;
armarx::gui::LeadingZeroSpinBox* microseconds;
};
class RelativeTimestampInput : public TimestampInput
{
Q_OBJECT // NOLINT
public : RelativeTimestampInput();
private:
QDoubleSpinBox* seconds;
};
class RelativeToLatestTimestampInput : public RelativeTimestampInput
{
Q_OBJECT // NOLINT
};
class RelativeToNowTimestampInput : public RelativeTimestampInput
{
Q_OBJECT // NOLINT
};
} // namespace armarx::armem::gui
......@@ -15,6 +15,7 @@
#include <RobotAPI/libraries/armem/core/Time.h>
#include <RobotAPI/libraries/armem/core/ice_conversions.h>
#include <RobotAPI/libraries/armem/client/query/Builder.h>
#include <RobotAPI/libraries/armem_gui/gui_utils.h>
namespace armarx::armem::gui
......@@ -42,21 +43,6 @@ namespace armarx::armem::gui
}
// Source: https://stackoverflow.com/a/26538572
class LeadingZeroSpinBox : public QSpinBox
{
using QSpinBox::QSpinBox;
int numDigits = 6;
int base = 10;
virtual QString textFromValue(int value) const;
};
QString LeadingZeroSpinBox::textFromValue(int value) const
{
return QString("%1").arg(value, numDigits, base, QChar('0'));
}
SnapshotFormSingle::SnapshotFormSingle()
{
......@@ -68,7 +54,7 @@ namespace armarx::armem::gui
dateTime->setDisabled(true);
setDateTimeDisplayFormat(dateTime);
microseconds = new LeadingZeroSpinBox();
microseconds = new armarx::gui::LeadingZeroSpinBox(6, 10);
microseconds->setDisabled(true);
microseconds->setMinimum(0);
microseconds->setMaximum(1000 * 1000 - 1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment