Resolves 1 conflict (new_docker_build.sh, union of viewer-only + codification options); folds in fixes for pre-existing defects surfaced by the validation runs (KDReports-qt6 wiring, LtsSession RTI linking, LtsFileDialog/WLS/BSM Qt6/RTI API migration, GROUP4 target list, new --cmake_build_flags option); validated with BUILD_RTI=ON BUILD_GRANTLEE=ON in 3 Docker runs (run 3: build green, 6 base-state first-run CTest failures documented).
209 lines
6.9 KiB
C++
Executable File
209 lines
6.9 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* from FileManagement - FileContent model
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Iuliana Ojog, SLSE, 2017-07-11
|
|
*/
|
|
|
|
#include "lts_dialog_model_file.h"
|
|
|
|
#include <ngltools/ngltools_dtg.h>
|
|
|
|
#include <QGuiApplication>
|
|
#include <QPalette>
|
|
#include <QMimeData>
|
|
|
|
#include <FileManagement/flm_db.h>
|
|
#include <FileManagement/flm_translation.h>
|
|
|
|
using namespace LtsWidgets;
|
|
//-------------------------------------------------------------------------------------
|
|
// DialogModelFile
|
|
//-------------------------------------------------------------------------------------
|
|
DialogModelFile::DialogModelFile(QObject *parent)
|
|
: LtsWidgets::LtsAbstractTableModel<FileManagement::FileContent>({tr("Name"),
|
|
tr("Template"),
|
|
tr("Type"),
|
|
tr("Category"),
|
|
tr("Status"),
|
|
tr("Exercise"),
|
|
tr("Phase"),
|
|
tr("Operator"),
|
|
tr("Used"),
|
|
tr("Uses"),
|
|
tr("Last modified"),
|
|
tr("Properties")},
|
|
parent)
|
|
, m_flmDtc(nullptr)
|
|
, m_opmDtc(nullptr)
|
|
{
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
bool DialogModelFile::initModel(const std::shared_ptr<FileManagement::Interface::Dtc> &dtc,
|
|
const std::shared_ptr<OperatorManagement::Interface::Dtc> &opmDtc,
|
|
const QString &xmlType,
|
|
const std::function<bool(const FileManagement::FileContent &, const QString &)> &predicate)
|
|
{
|
|
m_flmDtc = dtc;
|
|
m_opmDtc = opmDtc;
|
|
|
|
clear();
|
|
|
|
// insert Model
|
|
// Dtc per-item callback: return true to stop iteration (iterateUntil), so collect with false.
|
|
// Explicit std::function type disambiguates the void/bool overloads.
|
|
std::function<bool(const FileManagement::FileContent &)> files = [this, xmlType, predicate](const FileManagement::FileContent &fc)
|
|
{
|
|
if (predicate(fc, xmlType))
|
|
insertRow(fc);
|
|
return false;
|
|
};
|
|
m_flmDtc->fileContents(files);
|
|
|
|
return true;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
QVariant DialogModelFile::data(const QModelIndex &index, int role) const
|
|
{
|
|
if (!this->indexIsValid(index))
|
|
return {};
|
|
|
|
const FileManagement::FileContent &fl = this->getRowData(index.row());
|
|
|
|
switch(role)
|
|
{
|
|
case Qt::BackgroundRole:
|
|
{
|
|
if (fl.fileStatus == FileManagement::FileStatus::Deleted)
|
|
return QGuiApplication::palette().color(QPalette::Disabled, QPalette::AlternateBase);
|
|
return QGuiApplication::palette().color(QPalette::Active, QPalette::Base);
|
|
}
|
|
case Qt::DisplayRole:
|
|
{
|
|
switch (index.column())
|
|
{
|
|
case NAME:
|
|
return QString::fromStdString(fl.name);
|
|
case ISTEMPLATE:
|
|
return fl.isTemplate ? tr("Yes") : tr("No");
|
|
case FOLDER:
|
|
return fl.folderId;
|
|
case FILETYPE:
|
|
return FileManagement::toString(fl.fileType);
|
|
case FILECATEGORY:
|
|
return FileManagement::toString(fl.fileCategory);
|
|
case FILESTATUS:
|
|
return FileManagement::toString(fl.fileStatus);
|
|
case OPERATOR:
|
|
return QString::fromStdString(m_opmDtc->user(fl.operatorId).name);
|
|
case EXERCISE:
|
|
return fl.exerciseId.has_value() ? fl.exerciseId.value() : QVariant();
|
|
case PHASE:
|
|
return fl.phaseId.has_value() ? fl.phaseId.value() : QVariant();
|
|
case USEDBY:
|
|
return fl.isUsedBy ? tr("Yes") : tr("No");
|
|
case USES:
|
|
return QString::number(fl.usedBy);
|
|
case LASTMODIFIED:
|
|
return DTG::toStringMSec(fl.lastModified);
|
|
case PROPERTIES:
|
|
return QString::fromStdString(fl.properties);
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
case Qt::DecorationRole:
|
|
{
|
|
if (index.column() == NAME && fl.isHidden)
|
|
return QIcon(QLatin1String(":/style/lock.svg"));
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
return {};
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
int DialogModelFile::findFileIdFromName(const QString &fileName) const
|
|
{
|
|
const int rc = this->rowCount();
|
|
for (int row = 0; row < rc; ++row)
|
|
{
|
|
const FileManagement::FileContent &fl = this->getRowData(row);
|
|
if (fl.name == fileName)
|
|
{
|
|
return fl.id;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
const QLatin1String MIMETYPE("application/LtsDialogModelFile/FileId");
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
QStringList DialogModelFile::mimeTypes() const { return QStringList() << MIMETYPE; }
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
QMimeData * DialogModelFile::mimeData(const QModelIndexList &indexes) const
|
|
{
|
|
if (indexes.isEmpty()) return nullptr;
|
|
if (indexes.size() > 1) return nullptr;
|
|
|
|
const QModelIndex & index = indexes.first();
|
|
const FileManagement::FileContent & fl = this->getRowData(index.row());
|
|
int id = fl.id;
|
|
|
|
if (id <= 0) return nullptr;
|
|
|
|
QMimeData * mimeData = new QMimeData();
|
|
QByteArray encodedData;
|
|
|
|
mimeData->setData( MIMETYPE, encodedData.setNum(id) );
|
|
|
|
return mimeData;
|
|
}
|
|
|
|
void DialogFileProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
|
|
{
|
|
m_sourceModel = qobject_cast<DialogModelFile*>(sourceModel);
|
|
LtsWidgets::LtsColumnFilterProxyModel::setSourceModel(sourceModel);
|
|
}
|
|
|
|
bool DialogFileProxyModel::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 LtsWidgets::LtsColumnFilterProxyModel::lessThan(source_left, source_right);
|
|
const auto &dataLeft = m_sourceModel->getDataVector().at(source_left.row());
|
|
const auto dataRight = m_sourceModel->getDataVector().at(source_right.row());
|
|
switch (source_left.column())
|
|
{
|
|
case LASTMODIFIED:
|
|
return dataLeft.lastModified < dataRight.lastModified;
|
|
case NAME:
|
|
case ISTEMPLATE:
|
|
case FILETYPE:
|
|
case FILECATEGORY:
|
|
case FILESTATUS:
|
|
case EXERCISE:
|
|
case PHASE:
|
|
case OPERATOR:
|
|
case USEDBY:
|
|
case USES:
|
|
|
|
case PROPERTIES:
|
|
case FOLDER:
|
|
case COUNT:
|
|
break;
|
|
}
|
|
return LtsWidgets::LtsColumnFilterProxyModel::lessThan(source_left, source_right);
|
|
}
|