Cleanup + docs

This commit is contained in:
Luca Beltrame 2013-06-09 18:39:26 +02:00
parent e74c73db3c
commit c363891de3
4 changed files with 54 additions and 12 deletions

View file

@ -20,15 +20,20 @@
*
*/
#include "danboorupostdelegate.h"
// Own
#include "danboorupostdelegate.h"
#include "libdanbooru/danboorupost.h"
// Qt
#include <QListView>
#include <QPainter>
#include <QDebug>
#include <QApplication>
// KDE
#include <KPushButton>
namespace Danbooru {
@ -135,7 +140,8 @@ namespace Danbooru {
}
QSize DanbooruPostDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
QSize DanbooruPostDelegate::sizeHint(const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
Q_UNUSED(option)
Q_UNUSED(index)

View file

@ -23,6 +23,12 @@
#ifndef DANBOORUPOSTDELEGATE_H
#define DANBOORUPOSTDELEGATE_H
/**
* @brief This file includes custom delegates to represent DanbooruItems.
* @file danboorupostdelegate.h
*
**/
#include <QStyledItemDelegate>
class QListView;
@ -31,6 +37,10 @@ class KPushButton;
namespace Danbooru {
/**
* @brief Specific delegate for Danbooru items.
*
*/
class DanbooruPostDelegate : public QStyledItemDelegate
{
@ -47,10 +57,6 @@ namespace Danbooru {
QModelIndex hoveredIndex() const;
QList<QWidget*> createItemWidgets() const;
void updateItemWidgets( const QList<QWidget*> widgets,
const QStyleOptionViewItem& option,
const QPersistentModelIndex & index) const;
private:

View file

@ -20,9 +20,13 @@
*
*/
// Own
#include "danboorutablemodel.h"
#include "libdanbooru/danboorupost.h"
// Qt
#include <QDebug>
#include <QPixmap>
@ -47,7 +51,7 @@ namespace Danbooru {
void DanbooruTableModel::addPost(Danbooru::DanbooruPost* post)
{
beginInsertRows(QModelIndex(), m_posts.length(), m_posts.length()+1);
beginInsertRows(QModelIndex(), m_posts.length(), m_posts.length() + 1);
m_posts.append(post);
endInsertRows();
}
@ -70,8 +74,12 @@ namespace Danbooru {
if (role == Qt::DisplayRole) {
DanbooruPost* post = m_posts.at(index.row());
return post->fileUrl().fileName();
Danbooru::DanbooruPost* post = m_posts.at(index.row());
QVariant variant;
variant.setValue(post);
return variant;
}
if (role == Qt::DecorationRole) {

View file

@ -23,12 +23,29 @@
#ifndef DANBOORUTABLEMODEL_H
#define DANBOORUTABLEMODEL_H
/**
* @brief This file contains a specific model to represent Danbooru Items
* @file danboorutablemodel.h
*
**/
#include <QAbstractListModel>
#include <QList>
namespace Danbooru {
class DanbooruPost;
/**
* @brief A model to represent DanbooruItems
*
* Since items from a Danbooru service are sent by the service itself,
* there is no need for sorting or table-like structures: everything is
* represented as a flat list.
*
* Items are added through the addPost() slot.
*
*/
class DanbooruTableModel : public QAbstractListModel
{
@ -41,13 +58,18 @@ namespace Danbooru {
int rowCount(const QModelIndex& parent=QModelIndex()) const;
QVariant data(const QModelIndex& index, int role) const;
// bool insertRows(int row, int count=rowCount(),
// const QModelIndex& parent=QModelIndex());
private:
QList<DanbooruPost*> m_posts;
public Q_SLOTS:
/**
* @brief Add a new post to the model
*
* Connect to this slot when you want to add items to the model.
*
* @param post A pointer to a DanbooruPost.
*
*/
void addPost(Danbooru::DanbooruPost* post);
};