Commit 6a886b2f authored by Karel Slaný's avatar Karel Slaný

Removed Files::File from FileModelEntry interface.

parent 95f9dbc5
/*
* Copyright (C) 2014-2016 CZ.NIC
* Copyright (C) 2014-2017 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -135,6 +135,24 @@ void Files::clearFileModel(void)
globFilesModel.clearAll();
}
/*!
* @brief Set attachment model content.
*
* @param[in,out] model Model to be set.
* @param[in] fileList Attachment list to be added into the model.
*/
static
void setZfoFilesToModel(FileListModel &model,
const QList<Files::File> &fileList)
{
model.clearAll();
foreach (const Files::File &file, fileList) {
model.appendFileEntry(FileListModel::Entry(-1, file.dmFileDescr,
file._dmFileSize, file._icon, file.dmEncodedContent));
}
}
void Files::clearFileModelZfo(void)
{
globFilesModelZfo.clearAll();
......@@ -142,7 +160,7 @@ void Files::clearFileModelZfo(void)
QList<Files::File> fileList = stackFileList.pop();
if (!stackFileList.isEmpty()) {
fileList = stackFileList.pop();
globFilesModelZfo.setZfoFilesToModel(fileList);
setZfoFilesToModel(globFilesModelZfo, fileList);
}
}
if (!stackMessageDetail.isEmpty()) {
......@@ -795,7 +813,7 @@ bool Files::parseXmlData(QByteArray &data)
body += "\n";
// set file model
globFilesModelZfo.setZfoFilesToModel(fileList);
setZfoFilesToModel(globFilesModelZfo, fileList);
// remember file list and message detail
stackFileList.push(fileList);
stackMessageDetail.push(html);
......
/*
* Copyright (C) 2014-2016 CZ.NIC
* Copyright (C) 2014-2017 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (C) 2014-2016 CZ.NIC
* Copyright (C) 2014-2017 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -21,12 +21,11 @@
* the two.
*/
#include <QDebug>
#include <QSqlRecord>
#include "src/models/filemodel.h"
FileModelEntry::FileModelEntry(const FileModelEntry &fme)
FileListModel::Entry::Entry(const Entry &fme)
: m_fileId(fme.m_fileId),
m_dmFileDescr(fme.m_dmFileDescr),
m_dmFileSize(fme.m_dmFileSize),
......@@ -35,7 +34,7 @@ FileModelEntry::FileModelEntry(const FileModelEntry &fme)
{
}
FileModelEntry::FileModelEntry(const int fileId, const QString &dmFileDescr,
FileListModel::Entry::Entry(const int fileId, const QString &dmFileDescr,
const QString &dmFileSize, const QString &icon, const QString &fileContent)
: m_fileId(fileId),
m_dmFileDescr(dmFileDescr),
......@@ -45,52 +44,51 @@ FileModelEntry::FileModelEntry(const int fileId, const QString &dmFileDescr,
{
}
int FileModelEntry::fileId(void) const
int FileListModel::Entry::fileId(void) const
{
return m_fileId;
}
QString FileModelEntry::dmFileDescr(void) const
QString FileListModel::Entry::dmFileDescr(void) const
{
return m_dmFileDescr;
}
void FileModelEntry::setDmFileDescr(const QString &dmFileDescr)
void FileListModel::Entry::setDmFileDescr(const QString &dmFileDescr)
{
m_dmFileDescr = dmFileDescr;
}
QString FileModelEntry::dmFileSize(void) const
QString FileListModel::Entry::dmFileSize(void) const
{
return m_dmFileSize;
}
void FileModelEntry::setDmFileSize(const QString &dmFileSize)
void FileListModel::Entry::setDmFileSize(const QString &dmFileSize)
{
m_dmFileSize = dmFileSize;
}
QString FileModelEntry::icon(void) const
QString FileListModel::Entry::icon(void) const
{
return m_icon;
}
void FileModelEntry::setIcon(const QString &icon)
void FileListModel::Entry::setIcon(const QString &icon)
{
m_icon = icon;
}
QString FileModelEntry::fileContent(void) const
QString FileListModel::Entry::fileContent(void) const
{
return m_fileContent;
}
void FileModelEntry::setFileContent(const QString &fileContent)
void FileListModel::Entry::setFileContent(const QString &fileContent)
{
m_fileContent = fileContent;
}
FileListModel globFilesModel;
FileListModel globFilesModelZfo;
......@@ -127,7 +125,7 @@ QVariant FileListModel::data(const QModelIndex &index, int role) const
return QVariant();
}
const FileModelEntry &file = m_files[index.row()];
const Entry &file(m_files[index.row()]);
switch (role) {
case ROLE_FILE_ID:
......@@ -171,9 +169,9 @@ void FileListModel::setQuery(QSqlQuery &query)
query.first();
while (query.isActive() && query.isValid()) {
m_files.append(FileModelEntry(query.value(0).toInt(),
m_files.append(Entry(query.value(0).toInt(),
query.value(1).toString(), query.value(2).toString(),
query.value(3).toString(), ""));
query.value(3).toString(), QString()));
query.next();
}
......@@ -181,23 +179,15 @@ void FileListModel::setQuery(QSqlQuery &query)
endResetModel();
}
void FileListModel::setZfoFilesToModel(const QList<Files::File> &fileList)
void FileListModel::appendFileEntry(const Entry &entry)
{
beginResetModel();
m_files.clear();
beginInsertRows(QModelIndex(), rowCount(), rowCount());
foreach (const Files::File &file, fileList) {
m_files.append(FileModelEntry(-1,
file.dmFileDescr, file._dmFileSize, file._icon,
file.dmEncodedContent));
}
m_files.append(entry);
endResetModel();
endInsertRows();
}
void FileListModel::clearAll(void)
{
beginResetModel();
......
/*
* Copyright (C) 2014-2016 CZ.NIC
* Copyright (C) 2014-2017 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -21,44 +21,41 @@
* the two.
*/
#ifndef FILEMODEL_H
#define FILEMODEL_H
#ifndef _FILEMODEL_H_
#define _FILEMODEL_H_
#include <QAbstractListModel>
#include <QSqlQuery>
#include "src/files.h"
class FileListModel : public QAbstractListModel {
Q_OBJECT
class FileModelEntry {
public:
FileModelEntry(const FileModelEntry &fme);
FileModelEntry(const int fileId, const QString &dmFileDescr,
const QString &dmFileSize, const QString &icon,
const QString &fileContent);
int fileId(void) const;
QString dmFileDescr(void) const;
void setDmFileDescr(const QString &dmFileDescr);
QString dmFileSize(void) const;
void setDmFileSize(const QString &dmFileSize);
QString icon(void) const;
void setIcon(const QString &icon);
QString fileContent(void) const;
void setFileContent(const QString &fileContent);
private:
int m_fileId; /*!< File database file identifier. */
QString m_dmFileDescr; /*!< File name. */
QString m_dmFileSize; /*!< File size. */
QString m_icon; /*!< File icon? */
QString m_fileContent; /*!< File content */
};
class FileListModel : public QAbstractListModel
{
Q_OBJECT
class Entry {
public:
Entry(const Entry &fme);
Entry(const int fileId, const QString &dmFileDescr,
const QString &dmFileSize, const QString &icon,
const QString &fileContent);
int fileId(void) const;
QString dmFileDescr(void) const;
void setDmFileDescr(const QString &dmFileDescr);
QString dmFileSize(void) const;
void setDmFileSize(const QString &dmFileSize);
QString icon(void) const;
void setIcon(const QString &icon);
QString fileContent(void) const;
void setFileContent(const QString &fileContent);
private:
int m_fileId; /*!< File database file identifier. */
QString m_dmFileDescr; /*!< File name. */
QString m_dmFileSize; /*!< File size. */
QString m_icon; /*!< File icon? */
QString m_fileContent; /*!< File content */
};
public:
/*!
* @brief Roles which this model supports.
*/
......@@ -122,11 +119,11 @@ public:
void setQuery(QSqlQuery &query);
/*!
* @brief Sets the content of the model according files from zfo.
* @brief Appends entry line to model.
*
* @param[in] File data list.
* @param[in] entry Entry to append to model data.
*/
void setZfoFilesToModel(const QList<Files::File> &fileList);
void appendFileEntry(const Entry &entry);
/*!
* @brief Clears the model.
......@@ -134,10 +131,10 @@ public:
void clearAll(void);
private:
QList<FileModelEntry> m_files; /*!< List of file entries. */
QList<Entry> m_files; /*!< List of attachment entries. */
};
extern FileListModel globFilesModel;
extern FileListModel globFilesModelZfo;
#endif // FILEMODEL_H
#endif /* _FILEMODEL_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment