Continue the Qt5->Qt6 migration so the LTS Projects (Group 10) and LTS
Application (Group 11) compile, link, and ctest runs.
Qt5->Qt6 API migration (resolves removed/deprecated Qt6 APIs) across Lts
Tools and Apps, e.g. QAction->QActionGroup, QAbstractSocket::errorOccurred,
Qt::SkipEmptyParts, QRandomGenerator, QInputDevice::DeviceType,
QRegularExpression, QLatin1Literal->QStringLiteral, and the SampleModel
m_description->description rename.
CMake build fixes:
- CMakeLists.txt: add Lts/Common to CMAKE_AUTOMOC_INCLUDE_DIRECTORIES so moc
resolves Q_INTERFACES(ProjectPlugin::Plugin) for the migrated Projects.
- cmake/NGLMacros.cmake: NGL_COMPILE_RESOURCES - replace return() (which aborts
the calling CMakeLists.txt) with an if/else/endif.
- OpApp/THP: guard the ArcGISQt5Hack link with $<IF:$<TARGET_EXISTS:...>> (the
target is absent when the SituationMap viewer is stubbed); matches
CentralEffectSimulation.
- LtsSession: prefer the in-tree svcCoreClient target over a FIND_LIBRARY in
/usr/local/lib.
- CnrProxyTester/DotMatrixDisplay: set AUTOUIC_SEARCH_PATHS for the ui/ subdir.
- TopicDiscover: link NGLLogger.
Export-header visibility stubs (expand the empty *_EXPORT macro to
__attribute__((visibility("default"))); the build sets -fvisibility=hidden and
these stubs shadow the CMake-generated header):
- include/LtsProjectionWorkstation/ltsprojectionworkstation_export.h (fixes
undefined reference to LtsProjectionWorkstation::getInstance /
setProjectionOperatorPreset)
- include/LtsSession/ltssession_export.h, include/LtsUtilsGuiDds/ltsutilsguidds_export.h (same pattern)
New plugin modules (copied from legacy) so LtsAppDescriptorChecker finds the
gui:3 IIDs referenced by the Projects' apps.json:
- TakeHomePackageManager/OldTHP gui:3:tpm.man, gui:3:tpm.usb
- PresentationManagement/.../ScriptEditor gui:3:pre.script.edit
- Timeline/Gui/EventTimelineClassic gui:3:tln.view
new_docker_build.sh: correct group targets to the actual CMake target names,
guard LtsReportDisplay on BUILD_CODIFICATION, and skip modules unavailable in
the prebuilt image (AsmWorkstationCertifier/botan2, TrajectoryWidget,
VideoImport, thp_viewer/VLC).
215 lines
5.4 KiB
C++
Executable File
215 lines
5.4 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* PresentationManangement - Script Overview Dialog Model
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*
|
|
* Created by Mike Wille, SLSE, 2017-03-15
|
|
*/
|
|
|
|
#include "databases_model.h"
|
|
|
|
#include <ngltools/ngltools_dtg.h>
|
|
#include <ngldb/nsqlquery.h>
|
|
|
|
#include <QtCore/QDateTime>
|
|
#include <QPalette>
|
|
|
|
namespace AARApplication
|
|
{
|
|
|
|
DatabasesModel::DatabasesModel(QObject *parent)
|
|
: QAbstractTableModel(parent)
|
|
, m_logger(getLogger("DatabasesModel"))
|
|
{
|
|
beginResetModel();
|
|
m_vecData.clear();
|
|
endResetModel();
|
|
}
|
|
|
|
bool DatabasesModel::initModel(const QSqlDatabase &db)
|
|
{
|
|
NSqlQuery q(db);
|
|
|
|
QString stmt = QStringLiteral("SELECT id, name, begin_time, end_time, exercise_state_id FROM exm.exercise");
|
|
|
|
if (!q.prepare(stmt))
|
|
{
|
|
ERROR_LOG(m_logger) << "Preparing statement '" << stmt << "' failed.";
|
|
return false;
|
|
}
|
|
|
|
if (!q.exec(stmt))
|
|
{
|
|
ERROR_LOG(m_logger) << "Executing statement '" << stmt << "' failed.";
|
|
return false;
|
|
}
|
|
|
|
int count = 0;
|
|
while (q.next())
|
|
{
|
|
if (count > 0)
|
|
{
|
|
WARNING_LOG(m_logger) << "More than one exercise detected. There should be only one exercise per database.";
|
|
break;
|
|
}
|
|
|
|
Exercise exercise;
|
|
exercise.id = q.value(0).toInt();
|
|
exercise.name = q.value(1).toString();
|
|
exercise.startTime = q.value(2).toLongLong();
|
|
exercise.endTime = q.value(3).toLongLong();
|
|
exercise.dbName = QStringLiteral("lts_db_") + QString::number(exercise.id);
|
|
exercise.stateId = q.value(4).toInt();
|
|
TRACE_LOG(m_logger) << "Found exercise with id=" << exercise.id << ", name=" << exercise.name << ", startTime="
|
|
<< exercise.startTime << ", endTime=" << exercise.endTime << ", dbName=" << exercise.dbName
|
|
<< ", stateId=" << exercise.stateId;
|
|
if (exercise.stateId != 6)
|
|
onDataChanged(exercise, DataModification::eAdded);
|
|
++count;
|
|
}
|
|
|
|
INFO_LOG(m_logger) << "initModel - #exercises: " << m_vecData.size();
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
QVariant DatabasesModel::data(const QModelIndex &index, int role) const
|
|
{
|
|
if (role != Qt::DisplayRole || !index.isValid() || index.row() >= m_vecData.size())
|
|
return QVariant();
|
|
|
|
const Exercise &e = m_vecData.at(index.row());
|
|
|
|
switch (index.column())
|
|
{
|
|
case Id:
|
|
return e.id;
|
|
case Name:
|
|
return QString(e.name);
|
|
case StartTime:
|
|
return DTG::toStringMSec(e.startTime);
|
|
case EndTime:
|
|
return DTG::toStringMSec(e.endTime);
|
|
}
|
|
|
|
return QVariant();
|
|
}
|
|
|
|
int DatabasesModel::rowCount(const QModelIndex &parent) const
|
|
{
|
|
return parent.isValid() ? 0 : m_vecData.size();
|
|
}
|
|
|
|
int DatabasesModel::columnCount(const QModelIndex &parent) const
|
|
{
|
|
return parent.isValid() ? 0 : EndTime + 1;
|
|
}
|
|
|
|
QVariant DatabasesModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
{
|
|
if (orientation == Qt::Horizontal
|
|
&& role == Qt::DisplayRole)
|
|
{
|
|
Columns col = static_cast<Columns>(section);
|
|
switch (col)
|
|
{
|
|
case Id:
|
|
return tr("Id");
|
|
case Name:
|
|
return tr("Name");
|
|
case StartTime:
|
|
return tr("Start Time");
|
|
case EndTime:
|
|
return tr("End Time");
|
|
}
|
|
}
|
|
return QAbstractTableModel::headerData(section, orientation, role);
|
|
}
|
|
|
|
Exercise DatabasesModel::getRowData(int row) const
|
|
{
|
|
if (row < 0 || row >= m_vecData.size())
|
|
return Exercise();
|
|
return m_vecData.at(row);
|
|
}
|
|
|
|
bool DatabasesModel::insertRow(const Exercise &item)
|
|
{
|
|
beginInsertRows(QModelIndex(), m_vecData.size(), m_vecData.size());
|
|
m_vecData.append(item);
|
|
endInsertRows();
|
|
return true;
|
|
}
|
|
|
|
bool DatabasesModel::removeRow(const int &row)
|
|
{
|
|
beginRemoveRows(QModelIndex(), row, row);
|
|
m_vecData.remove(row);
|
|
endRemoveRows();
|
|
return true;
|
|
}
|
|
|
|
void DatabasesModel::onDataChanged(const Exercise &data, DataModification modType)
|
|
{
|
|
int row = -1;
|
|
switch (modType)
|
|
{
|
|
case DataModification::eAdded:
|
|
row = m_vecData.size();
|
|
if (insertRow(data))
|
|
emit dataChanged(index(row, Columns::Id), index(row, Columns::EndTime));
|
|
return;
|
|
|
|
case DataModification::eModified:
|
|
row = m_vecData.indexOf(data);
|
|
if (row != -1)
|
|
{
|
|
m_vecData[row] = data;
|
|
emit dataChanged(index(row, Columns::Id), index(row, Columns::EndTime));
|
|
}
|
|
return;
|
|
|
|
case DataModification::eRemoved:
|
|
row = m_vecData.indexOf(data);
|
|
if (row != -1)
|
|
if (removeRow(row))
|
|
emit dataChanged(index(std::min<qsizetype>(row, m_vecData.size() - 1), Columns::Id), index(m_vecData.size()-1, Columns::EndTime));
|
|
return;
|
|
} // switch
|
|
}
|
|
|
|
|
|
void DatabasesProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
|
|
{
|
|
m_sourceModel = qobject_cast<DatabasesModel*>(sourceModel);
|
|
QSortFilterProxyModel::setSourceModel(sourceModel);
|
|
}
|
|
|
|
bool DatabasesProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
|
|
{
|
|
if (!m_sourceModel ||
|
|
source_left.column() != source_right.column() ||
|
|
!source_left.isValid() ||
|
|
!source_right.isValid())
|
|
return QSortFilterProxyModel::lessThan(source_left, source_right);
|
|
const auto &dataLeft = m_sourceModel->m_vecData.at(source_left.row());
|
|
const auto dataRight = m_sourceModel->m_vecData.at(source_right.row());
|
|
switch (source_left.column())
|
|
{
|
|
case DatabasesModel::StartTime:
|
|
return dataLeft.startTime < dataRight.startTime;
|
|
case DatabasesModel::EndTime:
|
|
return dataLeft.endTime < dataRight.endTime;
|
|
case DatabasesModel::Id:
|
|
case DatabasesModel::Name:
|
|
break;
|
|
}
|
|
return QSortFilterProxyModel::lessThan(source_left, source_right);
|
|
}
|
|
|
|
|
|
} // namespace AARApplication
|