Commit d08a80ab authored by Karel Slaný's avatar Karel Slaný Committed by Martin Straka

Removed UploadHierarchyModel.

parent f3b2a1b6
......@@ -102,7 +102,6 @@ SOURCES += \
src/datovka_shared/records_management/json/stored_files.cpp \
src/datovka_shared/records_management/json/upload_file.cpp \
src/datovka_shared/records_management/json/upload_hierarchy.cpp \
src/datovka_shared/records_management/models/upload_hierarchy_model.cpp \
src/datovka_shared/records_management/models/upload_hierarchy_proxy_model.cpp \
src/datovka_shared/settings/pin.cpp \
src/datovka_shared/settings/records_management.cpp \
......@@ -186,7 +185,6 @@ HEADERS += \
src/datovka_shared/records_management/json/stored_files.h \
src/datovka_shared/records_management/json/upload_file.h \
src/datovka_shared/records_management/json/upload_hierarchy.h \
src/datovka_shared/records_management/models/upload_hierarchy_model.h \
src/datovka_shared/records_management/models/upload_hierarchy_proxy_model.h \
src/datovka_shared/settings/pin.h \
src/datovka_shared/settings/records_management.h \
......
/*
* Copyright (C) 2014-2018 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#include "src/datovka_shared/records_management/models/upload_hierarchy_model.h"
UploadHierarchyModel::UploadHierarchyModel(QObject *parent)
: QAbstractItemModel(parent),
m_hierarchy()
{
}
QModelIndex UploadHierarchyModel::index(int row, int column,
const QModelIndex &parent) const
{
if (!hasIndex(row, column, parent)) {
return QModelIndex();
}
quintptr internalId = 0;
if (!parent.isValid()) {
if (showRootName()) {
/* Root is shown. */
internalId = (quintptr)m_hierarchy.root();
} else {
/* Root is not shown. */
internalId = (quintptr)m_hierarchy.root()->sub().at(row);
}
} else {
const UploadHierarchyResp::NodeEntry *entry =
(UploadHierarchyResp::NodeEntry *)parent.internalId();
internalId = (quintptr)entry->sub().at(row);
}
return createIndex(row, column, internalId);
}
QModelIndex UploadHierarchyModel::parent(const QModelIndex &index) const
{
if (!index.isValid()) {
return QModelIndex();
}
const UploadHierarchyResp::NodeEntry *iEntry =
(UploadHierarchyResp::NodeEntry *)index.internalId();
const UploadHierarchyResp::NodeEntry *pEntry = iEntry->super();
if ((pEntry != Q_NULLPTR) &&
((pEntry != m_hierarchy.root()) || showRootName())) {
if (pEntry == m_hierarchy.root()) {
/* Root node is shown and parent is root. */
return createIndex(0, 0, (quintptr)pEntry);
} else {
const UploadHierarchyResp::NodeEntry *ppEntry =
pEntry->super();
int row = 0;
/* Find position of parent. */
for ( ; row < ppEntry->sub().size(); ++row) {
if (pEntry == ppEntry->sub().at(row)) {
break;
}
}
Q_ASSERT(row < ppEntry->sub().size());
return createIndex(row, 0, (quintptr)pEntry);
}
} else {
return QModelIndex();
}
}
int UploadHierarchyModel::rowCount(const QModelIndex &parent) const
{
if (parent.column() > 0) {
return 0;
}
if (!parent.isValid()) {
if (!m_hierarchy.isValid()) {
/* Invalid hierarchy. */
return 0;
}
/* Root. */
if (showRootName()) {
return 1;
} else {
return m_hierarchy.root()->sub().size();
}
} else {
const UploadHierarchyResp::NodeEntry *entry =
(UploadHierarchyResp::NodeEntry *)parent.internalId();
return entry->sub().size();
}
}
int UploadHierarchyModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 1;
}
QVariant UploadHierarchyModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) {
return QVariant();
}
const UploadHierarchyResp::NodeEntry *entry =
(UploadHierarchyResp::NodeEntry *)index.internalId();
if (entry == Q_NULLPTR) {
Q_ASSERT(0);
return QVariant();
}
switch (role) {
case Qt::DisplayRole:
return entry->name();
break;
case Qt::ToolTipRole:
return filterData(entry).join(QStringLiteral("\n"));
break;
case Qt::AccessibleTextRole:
return entry->name();
break;
case ROLE_FILTER:
return filterDataRecursive(entry, true);
break;
case ROLE_ID:
return entry->id();
break;
default:
return QVariant();
break;
}
}
QVariant UploadHierarchyModel::headerData(int section,
Qt::Orientation orientation, int role) const
{
if ((Qt::Horizontal == orientation) && (Qt::DisplayRole == role) &&
(0 == section)) {
return tr("Records Management Hierarchy");
}
return QVariant();
}
Qt::ItemFlags UploadHierarchyModel::flags(const QModelIndex &index) const
{
if (!index.isValid()) {
return Qt::NoItemFlags;
}
Qt::ItemFlags flags =
QAbstractItemModel::flags(index) & ~Qt::ItemIsEditable;
const UploadHierarchyResp::NodeEntry *entry =
(UploadHierarchyResp::NodeEntry *)index.internalId();
if (entry->id().isEmpty()) {
flags &= ~Qt::ItemIsSelectable;
}
return flags;
}
void UploadHierarchyModel::setHierarchy(const UploadHierarchyResp &uhr)
{
beginResetModel();
m_hierarchy = uhr;
endResetModel();
}
bool UploadHierarchyModel::showRootName(void) const
{
return m_hierarchy.isValid() && !m_hierarchy.root()->name().isEmpty();
}
QStringList UploadHierarchyModel::filterData(
const UploadHierarchyResp::NodeEntry *entry)
{
if (Q_UNLIKELY(entry == Q_NULLPTR)) {
Q_ASSERT(0);
return QStringList();
}
return QStringList(entry->name()) + entry->metadata();
}
QStringList UploadHierarchyModel::filterDataRecursive(
const UploadHierarchyResp::NodeEntry *entry, bool takeSuper)
{
if (Q_UNLIKELY(entry == Q_NULLPTR)) {
Q_ASSERT(0);
return QStringList();
}
QStringList res(filterData(entry));
foreach (const UploadHierarchyResp::NodeEntry *sub, entry->sub()) {
res += filterDataRecursive(sub, false);
}
if (takeSuper) {
/*
* Add also filter data from superordinate node. This has the
* effect that all sub-nodes (including those not matching the
* filter) of a node which matches the entered filter are
* going to be also displayed.
*/
const UploadHierarchyResp::NodeEntry *sup = entry->super();
if (Q_UNLIKELY(sup == Q_NULLPTR)) {
return res;
}
res += filterData(sup);
}
return res;
}
/*
* Copyright (C) 2014-2018 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
#pragma once
#include <QAbstractItemModel>
#include "src/datovka_shared/records_management/json/upload_hierarchy.h"
/*!
* @brief Upload hierarchy model.
*/
class UploadHierarchyModel : public QAbstractItemModel {
Q_OBJECT
public:
/*!
* @brief Custom roles.
*/
enum CustomRoles {
ROLE_FILTER = (Qt::UserRole + 1), /* Exposes metadata for filtering. */
ROLE_ID /* Hierarchy entry identifier. */
};
/*!
* @brief Constructor.
*
* @param[in] parent Pointer to parent object.
*/
explicit UploadHierarchyModel(QObject *parent = Q_NULLPTR);
/*!
* @brief Return index specified by supplied parameters.
*
* @param[in] row Item row.
* @param[in] column Parent column.
* @param[in] parent Parent index.
* @return Index to desired element or invalid index on error.
*/
virtual
QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
/*!
* @brief Return parent index of the item with the given index.
*
* @param[in] index Child node index.
* @return Index of the parent node or invalid index on error.
*/
virtual
QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE;
/*!
* @brief Return number of rows under the given parent.
*
* @param[in] parent Parent node index.
* @return Number of rows.
*/
virtual
int rowCount(const QModelIndex &parent = QModelIndex()) const
Q_DECL_OVERRIDE;
/*!
* @brief Return the number of columns for the children of given parent.
*
* @param[in] parent Parent node index.
* @return Number of columns.
*/
virtual
int columnCount(const QModelIndex &parent = QModelIndex()) const
Q_DECL_OVERRIDE;
/*!
* @brief Return data stored in given location under given role.
*
* @param[in] index Index specifying the item.
* @param[in] role Data role.
* @return Data from model.
*/
virtual
QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
/*!
* @brief Returns header data in given location under given role.
*
* @brief[in] section Header position.
* @brief[in] orientation Header orientation.
* @brief[in] role Data role.
* @return Header data from model.
*/
virtual
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
/*!
* @brief Returns item flags for given index.
*
* @brief[in] index Index specifying the item.
* @return Item flags.
*/
virtual
Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
/*!
* @brief Set content data.
*
* @param[in] uhr Upload hierarchy response structure.
*/
void setHierarchy(const UploadHierarchyResp &uhr);
private:
/*!
* @brief Check whether to show root name.
*
* @return True in root node contains a name.
*/
bool showRootName(void) const;
/*!
* @brief Return all data related to node which can be used for
* filtering.
*
* @param[in] entry Node identifier.
* @return List of strings.
*/
static
QStringList filterData(const UploadHierarchyResp::NodeEntry *entry);
/*!
* @brief Returns list of all (meta)data (including children).
*
* @param[in] entry Node identifying the root.
* @param[in] takeSuper Set true when data of superordinate node should
* be taken into account.
* @return List of all gathered data according to which can be filtered.
*/
static
QStringList filterDataRecursive(
const UploadHierarchyResp::NodeEntry *entry, bool takeSuper);
UploadHierarchyResp m_hierarchy; /*!< Upload hierarchy structure. */
};
......@@ -92,8 +92,6 @@ bool processUploadFileResponse(const UploadFileResp &ufRes, qint64 dmId,
RecordsManagement::RecordsManagement(QObject *parent)
: QObject(parent),
m_uploadModel(),
m_uploadProxyModel(),
m_rmc(RecordsManagementConnection::ignoreSslErrorsDflt, this),
m_logoSvg()
{
......
......@@ -26,8 +26,6 @@
#include <QObject>
#include "src/sqlite/message_db_container.h"
#include "src/datovka_shared/records_management/models/upload_hierarchy_model.h"
#include "src/datovka_shared/records_management/models/upload_hierarchy_proxy_model.h"
#include "src/datovka_shared/records_management/io/records_management_connection.h"
#include "src/datovka_shared/settings/records_management.h"
......@@ -169,8 +167,6 @@ private:
bool uploadFile(qint64 dmId, const QString &msgFileName,
const QByteArray &msgData, const QStringList &uploadIds);
UploadHierarchyModel m_uploadModel; /*!< Upload hierarchy model. */
UploadHierarchyProxyModel m_uploadProxyModel; /*!< Used for filtering. */
RecordsManagementConnection m_rmc; /*!< Connection to records management service. */
QByteArray m_logoSvg; /*!< Raw SVG data. */
};
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