mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-23 03:58:56 -04:00
Description field in view
Added the description field in the view. It is shown when the expand button is pressed. Fixed widths for all columns except Name, which takes up the remaining space.
This commit is contained in:
parent
f968a24adc
commit
bddda5cb2b
@ -14,6 +14,7 @@
|
||||
#include "contentmanagermodel.h"
|
||||
#include <zim/error.h>
|
||||
#include <zim/item.h>
|
||||
#include <QHeaderView>
|
||||
|
||||
ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader, QObject *parent)
|
||||
: QObject(parent),
|
||||
@ -29,6 +30,18 @@ ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader,
|
||||
managerModel->setBooksData(booksList);
|
||||
mp_view->setModel(managerModel);
|
||||
mp_view->show();
|
||||
|
||||
auto header = mp_view->header();
|
||||
header->setSectionResizeMode(0, QHeaderView::Fixed);
|
||||
header->setSectionResizeMode(1, QHeaderView::Stretch);
|
||||
header->setSectionResizeMode(2, QHeaderView::Fixed);
|
||||
header->setSectionResizeMode(3, QHeaderView::Fixed);
|
||||
header->setSectionResizeMode(4, QHeaderView::Fixed);
|
||||
header->setStretchLastSection(false);
|
||||
header->setSectionsClickable(true);
|
||||
header->setHighlightSections(true);
|
||||
mp_view->setWordWrap(true);
|
||||
|
||||
setCurrentLanguage(QLocale().name().split("_").at(0));
|
||||
connect(mp_library, &Library::booksChanged, this, [=]() {emit(this->booksChanged());});
|
||||
connect(this, &ContentManager::filterParamsChanged, this, &ContentManager::updateLibrary);
|
||||
@ -43,7 +56,7 @@ QList<QMap<QString, QVariant>> ContentManager::getBooksList()
|
||||
{
|
||||
const auto bookIds = getBookIds();
|
||||
QList<QMap<QString, QVariant>> bookList;
|
||||
QStringList keys = {"title", "tags", "date", "id", "size"};
|
||||
QStringList keys = {"title", "tags", "date", "id", "size", "description"};
|
||||
auto app = KiwixApp::instance();
|
||||
std::shared_ptr<zim::Archive> archive;
|
||||
QIcon bookIcon;
|
||||
|
@ -134,8 +134,18 @@ void ContentManagerModel::setupNodes()
|
||||
auto description = bookItem["description"].toString();
|
||||
auto icon = bookItem["icon"];
|
||||
const auto temp = new Node({icon, name, date, size, content, id}, rootNode);
|
||||
const auto tempsTemp = new Node({"", description, "", "", "", ""}, temp, true);
|
||||
temp->appendChild(tempsTemp);
|
||||
rootNode->appendChild(temp);
|
||||
}
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
bool ContentManagerModel::hasChildren(const QModelIndex &parent) const
|
||||
{
|
||||
Node *item = static_cast<Node*>(parent.internalPointer());
|
||||
if (item)
|
||||
return !item->isAdditonal();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ public:
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
void setBooksData(const QList<QMap<QString, QVariant>>& data);
|
||||
void setupNodes();
|
||||
bool hasChildren(const QModelIndex &parent) const override;
|
||||
|
||||
private:
|
||||
QList<QMap<QString, QVariant>> m_data;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "node.h"
|
||||
|
||||
Node::Node(const QList<QVariant> &data, Node *parent)
|
||||
: m_itemData(data), m_parentItem(parent)
|
||||
Node::Node(const QList<QVariant> &data, Node *parent, bool isAdditional)
|
||||
: m_itemData(data), m_parentItem(parent), m_isAdditonal(isAdditional)
|
||||
{}
|
||||
|
||||
Node::~Node()
|
||||
|
@ -7,7 +7,7 @@
|
||||
class Node
|
||||
{
|
||||
public:
|
||||
explicit Node(const QList<QVariant> &data, Node *parentNode = nullptr);
|
||||
explicit Node(const QList<QVariant> &data, Node *parentItem = nullptr, bool isAdditional = false);
|
||||
~Node();
|
||||
void appendChild(Node *child);
|
||||
Node *child(int row);
|
||||
@ -16,11 +16,13 @@ public:
|
||||
QVariant data(int column) const;
|
||||
int row() const;
|
||||
Node *parentItem();
|
||||
bool isAdditonal() const { return m_isAdditonal; }
|
||||
|
||||
private:
|
||||
QList<QVariant> m_itemData;
|
||||
Node *m_parentItem;
|
||||
QList<Node *> m_childItems;
|
||||
bool m_isAdditonal;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user