Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,389 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* SituationMap - MapWidgetControlDialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2016-02-29
|
||||
*/
|
||||
|
||||
|
||||
#include "sitmap_widget_control.h"
|
||||
#include "ui_sitmap_widget_control.h"
|
||||
|
||||
#include <Map/map_notifier.h>
|
||||
#include <Map/grid.h>
|
||||
#include <Map/overview_map_handler.h>
|
||||
#include <LtsUtilsSettings/settings.h>
|
||||
|
||||
// Qt
|
||||
#include <QToolButton>
|
||||
|
||||
namespace SituationMap
|
||||
{
|
||||
|
||||
MapWidgetControl::MapWidgetControl(const QString &menuGroup, QWidget *parent)
|
||||
: LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
|
||||
, m_menuGroup(menuGroup)
|
||||
, m_situationMap(nullptr)
|
||||
, m_ui(new Ui::MapWidgetControl)
|
||||
, m_tbGrid(nullptr)
|
||||
, m_tbCompass(nullptr)
|
||||
, m_tbPositionString(nullptr)
|
||||
, m_tbExerciseTimeString(nullptr)
|
||||
, m_tbOverviewMap(nullptr)
|
||||
, m_tb2D3D(nullptr)
|
||||
, m_session(nullptr)
|
||||
, m_logger(getLogger("MapWidgetControl"))
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
m_ui->setupUi(this);
|
||||
|
||||
setOnlineHelpFilename(QStringLiteral("Situation-Map_Widgets"));
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
||||
}
|
||||
|
||||
MapWidgetControl::~MapWidgetControl()
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
delete m_ui;
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
||||
}
|
||||
|
||||
void MapWidgetControl::retranslate()
|
||||
{
|
||||
translate(m_ui, tr("Map Widgets"));
|
||||
reBuildUi();
|
||||
}
|
||||
|
||||
bool MapWidgetControl::init(SituationMap::Map *map, LtsSession::LtsSession *session )
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START " << " map=" << map;
|
||||
|
||||
if (!map)
|
||||
return false;
|
||||
|
||||
m_situationMap = map;
|
||||
m_session = session;
|
||||
|
||||
if (m_situationMap == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "invalid situation map given";
|
||||
return false;
|
||||
}
|
||||
|
||||
reBuildUi();
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END " << " map=" << map;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MapWidgetControl::isBtn2D3Denabled() const
|
||||
{
|
||||
return m_isBtn2D3Denabled;
|
||||
}
|
||||
|
||||
void MapWidgetControl::enableBtn2D3D(bool onOff)
|
||||
{
|
||||
m_isBtn2D3Denabled = onOff;
|
||||
|
||||
if (m_tb2D3D)
|
||||
m_tb2D3D->setEnabled(m_isBtn2D3Denabled);
|
||||
}
|
||||
|
||||
bool MapWidgetControl::isReplay() const
|
||||
{
|
||||
if (m_situationMap == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "cannot check if situation map is in replay, no situation map available";
|
||||
return false;
|
||||
}
|
||||
return m_situationMap->isReplay();
|
||||
}
|
||||
|
||||
void MapWidgetControl::setIsReplay(bool b)
|
||||
{
|
||||
if (m_situationMap)
|
||||
m_situationMap->setReplay(b);
|
||||
}
|
||||
|
||||
void MapWidgetControl::onChangeModeRequested()
|
||||
{
|
||||
if (m_tb2D3D == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "cannot process change mode request, no 2D/3D option available";
|
||||
return;
|
||||
}
|
||||
m_tb2D3D->setEnabled(false);
|
||||
emit changeModeRequested();
|
||||
}
|
||||
|
||||
void MapWidgetControl::enableBtn2D3DInternal(bool onOff)
|
||||
{
|
||||
if (!m_tb2D3D)
|
||||
return;
|
||||
|
||||
m_tb2D3D->setEnabled(onOff);
|
||||
|
||||
if (m_tb2D3D->isEnabled())
|
||||
m_tb2D3D->setStyleSheet(QLatin1String("QWidget {background-color: gray;}"));
|
||||
else
|
||||
m_tb2D3D->setStyleSheet(QLatin1String("QWidget {background-color: red;}"));
|
||||
}
|
||||
|
||||
//private
|
||||
void MapWidgetControl::reBuildUi()
|
||||
{
|
||||
LtsUtils::ProjectSettings *ps = LtsUtils::ProjectSettings::getInstance();
|
||||
|
||||
bool enable3dMap = ps->value(QStringLiteral("SituationMap"), QStringLiteral("enable3dMap"), true).toBool();
|
||||
|
||||
if (m_situationMap == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "cannot rebuild ui, no situation map available";
|
||||
return;
|
||||
}
|
||||
|
||||
MenuWidgetPosition pos;
|
||||
pos.row = 0;
|
||||
pos.column = 0;
|
||||
|
||||
//Grid
|
||||
if (!m_tbGrid)
|
||||
{
|
||||
QToolButton *tool;
|
||||
tool = new QToolButton(this);
|
||||
tool->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
tool->setIcon(QIcon(QLatin1String("icon:mgrs_grid.svg")));
|
||||
tool->setIconSize(QSize(40, 40));
|
||||
tool->setText(tr("Grid"));
|
||||
tool->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextUnderIcon);
|
||||
tool->setCheckable(true);
|
||||
m_tbGrid = tool;
|
||||
}
|
||||
m_tbGrid->setChecked(m_situationMap->grid().isVisible());
|
||||
QObject::connect(m_tbGrid, &QToolButton::clicked, this, [this]()
|
||||
{
|
||||
m_situationMap->grid().setVisible(m_tbGrid->isChecked());
|
||||
});
|
||||
QObject::connect(m_situationMap.data(), &Map::visualComponentChanged, this, [this]()
|
||||
{
|
||||
if (!m_situationMap)
|
||||
return;
|
||||
m_tbGrid->setChecked(m_situationMap->grid().isVisible());
|
||||
});
|
||||
m_ui->gridLayout->addWidget(m_tbGrid, pos.row, pos.column);
|
||||
pos = calculateMenuWidgetPosition(pos);
|
||||
|
||||
//Compass
|
||||
if (!m_tbCompass)
|
||||
{
|
||||
QToolButton *tool;
|
||||
tool = new QToolButton(this);
|
||||
tool->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
tool->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextUnderIcon);
|
||||
tool->setIcon(QIcon(QLatin1String("icon:load.svg")));
|
||||
tool->setIconSize(QSize(40, 40));
|
||||
tool->setText(tr("Compass Rose"));
|
||||
tool->setCheckable(true);
|
||||
m_tbCompass = tool;
|
||||
}
|
||||
m_tbCompass->setChecked(m_situationMap->isCompassVisible());
|
||||
QObject::connect(m_tbCompass, &QToolButton::clicked, this, [this]()
|
||||
{
|
||||
m_situationMap->showCompass(m_tbCompass->isChecked());
|
||||
});
|
||||
QObject::connect(m_situationMap.data(), &Map::visualComponentChanged, this, [this]()
|
||||
{
|
||||
if (!m_situationMap)
|
||||
return;
|
||||
m_tbCompass->setChecked(m_situationMap->isCompassVisible());
|
||||
});
|
||||
m_ui->gridLayout->addWidget(m_tbCompass, pos.row, pos.column);
|
||||
pos = calculateMenuWidgetPosition(pos);
|
||||
|
||||
// PositionString:
|
||||
if ( m_session->app() != LtsAppDescriptor::App::OC)
|
||||
{
|
||||
if (!m_tbPositionString)
|
||||
{
|
||||
QToolButton *tool;
|
||||
tool = new QToolButton(this);
|
||||
tool->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
tool->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextUnderIcon);
|
||||
tool->setIcon(QIcon(QLatin1String("icon:load.svg")));
|
||||
tool->setIconSize(QSize(40, 40));
|
||||
tool->setText(tr("Position String"));
|
||||
tool->setCheckable(true);
|
||||
m_tbPositionString = tool;
|
||||
}
|
||||
m_tbPositionString->setChecked(m_situationMap->isPositionStringVisible());
|
||||
QObject::connect(m_tbPositionString, &QToolButton::clicked, this, [this]()
|
||||
{
|
||||
m_situationMap->showPositionString(m_tbPositionString->isChecked());
|
||||
});
|
||||
QObject::connect(m_situationMap.data(), &Map::visualComponentChanged, this, [this]()
|
||||
{
|
||||
if (!m_situationMap)
|
||||
return;
|
||||
m_tbPositionString->setChecked(m_situationMap->isPositionStringVisible());
|
||||
});
|
||||
m_ui->gridLayout->addWidget(m_tbPositionString, pos.row, pos.column);
|
||||
pos = calculateMenuWidgetPosition(pos);
|
||||
}
|
||||
|
||||
// ExerciseTimeString
|
||||
if (isReplay())
|
||||
{
|
||||
if (!m_tbExerciseTimeString)
|
||||
{
|
||||
QToolButton *tool;
|
||||
tool = new QToolButton(this);
|
||||
tool->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
tool->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextUnderIcon);
|
||||
tool->setIcon(QIcon(QLatin1String("icon:global_exercise_settings.svg")));
|
||||
tool->setIconSize(QSize(40, 40));
|
||||
tool->setText(tr("Exercise Time String"));
|
||||
tool->setCheckable(true);
|
||||
m_tbExerciseTimeString = tool;
|
||||
}
|
||||
m_tbExerciseTimeString->setChecked(m_situationMap->isExerciseTimeStringVisible());
|
||||
QObject::connect(m_tbExerciseTimeString, &QToolButton::clicked, this, [this]()
|
||||
{
|
||||
m_situationMap->showExerciseTimeString(m_tbExerciseTimeString->isChecked());
|
||||
});
|
||||
QObject::connect(m_situationMap.data(), &Map::visualComponentChanged, this, [this]()
|
||||
{
|
||||
if (!m_situationMap)
|
||||
return;
|
||||
m_tbExerciseTimeString->setChecked(m_situationMap->isExerciseTimeStringVisible());
|
||||
});
|
||||
m_ui->gridLayout->addWidget(m_tbExerciseTimeString, pos.row, pos.column);
|
||||
pos = calculateMenuWidgetPosition(pos);
|
||||
}
|
||||
|
||||
//OverviewMap
|
||||
if ( m_session->app() != LtsAppDescriptor::App::OC)
|
||||
{
|
||||
if (!m_tbOverviewMap)
|
||||
{
|
||||
QToolButton *tool;
|
||||
tool = new QToolButton(this);
|
||||
tool->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
tool->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextUnderIcon);
|
||||
tool->setIcon(QIcon(QLatin1String("icon:mini_map.svg")));
|
||||
tool->setIconSize(QSize(40, 40));
|
||||
tool->setText(tr("Overview Map"));
|
||||
tool->setCheckable(true);
|
||||
m_tbOverviewMap = tool;
|
||||
}
|
||||
m_tbOverviewMap->setChecked(m_situationMap->overviewMapHandler().builtInOverviewMapWidget());
|
||||
QObject::connect(m_tbOverviewMap, &QToolButton::clicked, this, [this]()
|
||||
{
|
||||
if (m_tbOverviewMap->isChecked())
|
||||
m_situationMap->overviewMapHandler().createBuiltInOverviewMap();
|
||||
else
|
||||
m_situationMap->overviewMapHandler().removeBuiltInOverviewMap();
|
||||
});
|
||||
QObject::connect(m_situationMap.data(), &Map::visualComponentChanged, this, [this]()
|
||||
{
|
||||
if (!m_situationMap)
|
||||
return;
|
||||
m_tbOverviewMap->setChecked(m_situationMap->overviewMapHandler().builtInOverviewMapWidget());
|
||||
});
|
||||
m_ui->gridLayout->addWidget(m_tbOverviewMap, pos.row, pos.column);
|
||||
pos = calculateMenuWidgetPosition(pos);
|
||||
}
|
||||
|
||||
// 2D - 3D
|
||||
// Switching between 2D and 3D should be allowed for Snapshots (==isReplay)
|
||||
if (!m_tb2D3D && enable3dMap)
|
||||
{
|
||||
QToolButton *tool;
|
||||
tool = new QToolButton(this);
|
||||
tool->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
tool->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextUnderIcon);
|
||||
tool->setIcon(QIcon(QLatin1String("icon:map_2d.svg"))); // map_3d.svg
|
||||
tool->setIconSize(QSize(40, 40));
|
||||
tool->setText(tr("2D - 3D"));
|
||||
tool->setCheckable(true);
|
||||
m_tb2D3D = tool;
|
||||
// signal-signal connection:
|
||||
connect(m_tb2D3D, &QToolButton::clicked, this, &MapWidgetControl::onChangeModeRequested, Qt::UniqueConnection);
|
||||
}
|
||||
if (m_tb2D3D && enable3dMap)
|
||||
m_ui->gridLayout->addWidget(m_tb2D3D, pos.row, pos.column);
|
||||
pos = calculateMenuWidgetPosition(pos);
|
||||
|
||||
|
||||
// enable/disable button
|
||||
enableBtn2D3DInternal(false);
|
||||
|
||||
QPointer<MapNotifier> mapNotifier = m_situationMap->createMapNotifier();
|
||||
if (mapNotifier)
|
||||
{
|
||||
connect(mapNotifier.data(), &MapNotifier::mapReadyAndSymbolDictionaryLoaded, this, [this]()
|
||||
{
|
||||
QTimer::singleShot(1000, this, &MapWidgetControl::enaDisa);
|
||||
});
|
||||
mapNotifier->run();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MapWidgetControl::MenuWidgetPosition MapWidgetControl::calculateMenuWidgetPosition(MapWidgetControl::MenuWidgetPosition &pos) const
|
||||
{
|
||||
if (pos.column < 1)
|
||||
pos.column++;
|
||||
else
|
||||
{
|
||||
pos.row++;
|
||||
pos.column = 0;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
void MapWidgetControl::enaDisa()
|
||||
{
|
||||
LtsUtils::ProjectSettings *ps = LtsUtils::ProjectSettings::getInstance();
|
||||
|
||||
bool enable3dMap = ps->value(QStringLiteral("SituationMap"), QStringLiteral("enable3dMap"), true).toBool();
|
||||
|
||||
if (m_situationMap == nullptr)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "cannot enable/disable ui, no situation map available";
|
||||
return;
|
||||
}
|
||||
if ( m_tb2D3D && !enable3dMap)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "m_tb2D3D->hide();"
|
||||
<< "m_enable3dMap=" << enable3dMap;
|
||||
m_tb2D3D->hide();
|
||||
}
|
||||
if (m_tb2D3D && enable3dMap)
|
||||
{
|
||||
enableBtn2D3DInternal(m_isBtn2D3Denabled);
|
||||
|
||||
switch (m_situationMap->mode())
|
||||
{
|
||||
case Mode::Mode_2D:
|
||||
m_tb2D3D->setText(tr("Switch to 3D"));
|
||||
m_tb2D3D->setIcon(QIcon(QLatin1String("icon:map_3d.svg")));
|
||||
DEBUG_LOG(m_logger) << "m_tb2D3D Switch to 3D"
|
||||
<< "enable3dMap=" << enable3dMap;
|
||||
break;
|
||||
case Mode::Mode_3D:
|
||||
m_tb2D3D->setText(tr("Switch to 2D"));
|
||||
m_tb2D3D->setIcon(QIcon(QLatin1String("icon:map_2d.svg")));
|
||||
DEBUG_LOG(m_logger) << "m_tb2D3D Switch to 2D"
|
||||
<< "enable3dMap=" << enable3dMap;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} //namespace SituationMap
|
||||
Reference in new issue
Block a user