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

Hid some private static methods from UploadHierarchyListModel interface.

parent f0b3afc6
......@@ -152,10 +152,102 @@ QHash<int, QByteArray> UploadHierarchyListModel::roleNames(void) const
return roles;
}
/*!
* @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)
{
if (Q_UNLIKELY(entry == Q_NULLPTR)) {
Q_ASSERT(0);
return QStringList();
}
return QStringList(entry->name()) + entry->metadata();
}
/*!
* @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)
{
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;
}
/* Return true if entry is selectable. */
#define isSelectable(entry) \
(!(entry)->id().isEmpty())
/*!
* @brief Check whether identifier of node is in set.
*
* @param[in] entry Node entry.
* @param[in] idMap Identifier map to search in.
* @param[in] takeSub Whether sub-nodes are to be taken into
* consideration.
* @return true if node identifier is in set or any of its sub-nodes if
* takeSub enabled.
*/
static
bool idInSelection(const UploadHierarchyResp::NodeEntry *entry,
const QMap<QString, QString> &idMap, bool takeSub)
{
if (Q_UNLIKELY(entry == Q_NULLPTR)) {
Q_ASSERT(0);
return false;
}
int present = false;
const QString &id(entry->id());
if (!id.isEmpty()) {
present = idMap.contains(id);
}
if (takeSub) {
int i = 0;
while ((!present) && (i < entry->sub().size())) {
present = idInSelection(entry->sub().at(i), idMap, true);
++i;
}
}
return present;
}
QVariant UploadHierarchyListModel::data(const QModelIndex &index,
int role) const
{
......@@ -271,29 +363,30 @@ void UploadHierarchyListModel::navigateSub(int row)
}
/*!
* @brief Return node name.
* @brief Return entry name.
*
* @param[in] node Node pointer.
* @param[in] entry Entry pointer.
* @param[in] takeSuper If true, then full path across all
* superordinate nodes is taken.
* @param[in] sep Separator to be used. It is always appended to
* the end of the returned string.
* @return Name or path of names to the node.
* @return Name or path of names to the entry.
*/
static
QString nodeName(const UploadHierarchyResp::NodeEntry *node, bool takeSuper,
QString entryName(const UploadHierarchyResp::NodeEntry *entry, bool takeSuper,
const QString &sep)
{
if (Q_UNLIKELY(node == Q_NULLPTR)) {
if (Q_UNLIKELY(entry == Q_NULLPTR)) {
Q_ASSERT(0);
return QString();
}
QString nodeName(node->name() + sep);
QString nodeName(entry->name() + sep);
if (takeSuper) {
node = node->super();
while ((node != Q_NULLPTR) && (!node->name().isEmpty())) {
nodeName = node->name() + sep + nodeName;
node = node->super();
entry = entry->super();
while ((entry != Q_NULLPTR) && (!entry->name().isEmpty())) {
nodeName = entry->name() + sep + nodeName;
entry = entry->super();
}
}
......@@ -311,7 +404,7 @@ QString UploadHierarchyListModel::navigatedRootName(bool takeSuper,
return sep;
}
return nodeName(m_workingRoot, takeSuper, sep);
return entryName(m_workingRoot, takeSuper, sep);
}
bool UploadHierarchyListModel::toggleNodeSelection(int row)
......@@ -329,7 +422,7 @@ bool UploadHierarchyListModel::toggleNodeSelection(int row)
m_selected.remove(sub->id());
} else {
m_selected.insert(sub->id(),
nodeName(sub, true, "/")); /* TODO -- Make the separator configurable. */
entryName(sub, true, "/")); /* TODO -- Make the separator configurable. */
}
QModelIndex changedIdx(index(row, 0, QModelIndex()));
QVector<int> roles(2);
......@@ -385,69 +478,3 @@ bool UploadHierarchyListModel::showRootName(void) const
return m_hierarchy.isValid() && (m_workingRoot != Q_NULLPTR) &&
!m_workingRoot->name().isEmpty();
}
QStringList UploadHierarchyListModel::filterData(
const UploadHierarchyResp::NodeEntry *entry)
{
if (Q_UNLIKELY(entry == Q_NULLPTR)) {
Q_ASSERT(0);
return QStringList();
}
return QStringList(entry->name()) + entry->metadata();
}
QStringList UploadHierarchyListModel::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;
}
bool UploadHierarchyListModel::idInSelection(
const UploadHierarchyResp::NodeEntry *entry,
const QMap<QString, QString> &idMap, bool takeSub)
{
if (Q_UNLIKELY(entry == Q_NULLPTR)) {
Q_ASSERT(0);
return false;
}
int present = false;
const QString &id(entry->id());
if (!id.isEmpty()) {
present = idMap.contains(id);
}
if (takeSub) {
int i = 0;
while ((!present) && (i < entry->sub().size())) {
present = idInSelection(entry->sub().at(i), idMap, true);
++i;
}
}
return present;
}
......@@ -216,42 +216,6 @@ private:
*/
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);
/*!
* @brief Check whether identifier of node is in set.
*
* @param[in] entry Node entry.
* @param[in] idMap Identifier map to search in.
* @param[in] takeSub Whether sub-nodes are to be taken into
* consideration.
* @return true if node identifier is in set or any of its sub-nodes if
* takeSub enabled.
*/
static
bool idInSelection(const UploadHierarchyResp::NodeEntry *entry,
const QMap<QString, QString> &idMap, bool takeSub);
UploadHierarchyResp m_hierarchy; /*!< Upload hierarchy structure. */
const UploadHierarchyResp::NodeEntry *m_workingRoot; /*!< Node acting as working root. */
QMap<QString, QString> m_selected; /*!< Keys are ids, values are full names. */
......
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