- flm_db.h: Stub-Header mit Folder/FileContent Klassen erstellt - flm_enums.hpp: MainFolder Enum hinzugefügt (None=0) - flm_translation.h: toInt() entfernt, trFolderName() angepasst - Plugin-Interfaces erstellt (flm, opm, exm) - Viewer-Dialogs: QString-Konvertierungen behoben - AdvancedSymbology CMakeLists.txt: Ungültige Pfade entfernt - ism_mounting_point.cpp: Redundante Definitionen entfernt Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
210 lines
6.8 KiB
C++
Executable File
210 lines
6.8 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
|
|
auto files = [this, xmlType, predicate](const std::vector<FileManagement::FileContent> & fcs, const std::vector<int> &, FileManagement::Interface::DataModification)
|
|
{
|
|
for (const auto& fc : fcs)
|
|
{
|
|
if (!predicate(fc, xmlType))
|
|
continue;
|
|
insertRow(fc);
|
|
}
|
|
};
|
|
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 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::fromStdString(fl.usedBy());
|
|
case LASTMODIFIED:
|
|
return DTG::toStringMSec(fl.lastModified().toMSecsSinceEpoch());
|
|
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);
|
|
}
|