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" #include "libdanbooru/danboorupost.h"
// Qt
#include <QListView> #include <QListView>
#include <QPainter> #include <QPainter>
#include <QDebug> #include <QDebug>
#include <QApplication> #include <QApplication>
// KDE
#include <KPushButton> #include <KPushButton>
namespace Danbooru { 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(option)
Q_UNUSED(index) Q_UNUSED(index)

View file

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

View file

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

View file

@ -23,12 +23,29 @@
#ifndef DANBOORUTABLEMODEL_H #ifndef DANBOORUTABLEMODEL_H
#define DANBOORUTABLEMODEL_H #define DANBOORUTABLEMODEL_H
/**
* @brief This file contains a specific model to represent Danbooru Items
* @file danboorutablemodel.h
*
**/
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QList> #include <QList>
namespace Danbooru { namespace Danbooru {
class DanbooruPost; 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 class DanbooruTableModel : public QAbstractListModel
{ {
@ -41,13 +58,18 @@ namespace Danbooru {
int rowCount(const QModelIndex& parent=QModelIndex()) const; int rowCount(const QModelIndex& parent=QModelIndex()) const;
QVariant data(const QModelIndex& index, int role) const; QVariant data(const QModelIndex& index, int role) const;
// bool insertRows(int row, int count=rowCount(),
// const QModelIndex& parent=QModelIndex());
private: private:
QList<DanbooruPost*> m_posts; QList<DanbooruPost*> m_posts;
public Q_SLOTS: 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); void addPost(Danbooru::DanbooruPost* post);
}; };