206 lines
6.6 KiB
C++
Executable File
206 lines
6.6 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 <Services/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 FileManagement::FileContent & fc)
|
|
{
|
|
if (!predicate(fc, xmlType))
|
|
return;
|
|
insertRow(fc);
|
|
};
|
|
m_flmDtc->fileContents(files);
|
|
|
|
return true;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------------
|
|
QVariant DialogModelFile::data(const QModelIndex &index, int role) const
|
|
{
|
|
if (!indexIsValid(index))
|
|
return {};
|
|
|
|
const FileManagement::FileContent &fl = 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().is_set() ? fl.exerciseId().get() : QVariant();
|
|
case PHASE:
|
|
return fl.phaseId().is_set() ? fl.phaseId().get() : QVariant();
|
|
case USEDBY:
|
|
return fl.isUsedBy() ? tr("Yes") : tr("No");
|
|
case USES:
|
|
return 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 = rowCount();
|
|
for (int row = 0; row < rc; ++row)
|
|
{
|
|
const FileManagement::FileContent &fl = getRowData(row);
|
|
if (QString::fromStdString(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 = 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->m_vecData.at(source_left.row());
|
|
const auto dataRight = m_sourceModel->m_vecData.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);
|
|
}
|