diff options
author | Arno <am@disconnect.de> | 2010-06-03 21:06:30 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2010-06-03 21:06:30 +0200 |
commit | 4d78abefd76d7d828a4ac078b80e8891ddb975e6 (patch) | |
tree | 77168d0a74272b0be7e8d78cf3c9322f6c9aed55 | |
parent | daa5c2eb9148b9175302228a6bae257e84881846 (diff) | |
download | SheMov-4d78abefd76d7d828a4ac078b80e8891ddb975e6.tar.gz SheMov-4d78abefd76d7d828a4ac078b80e8891ddb975e6.tar.bz2 SheMov-4d78abefd76d7d828a4ac078b80e8891ddb975e6.zip |
Started Treemodel for Archive
Implemented generic SmTreeItem, started on generic SmTreeModel.
-rw-r--r-- | shemov.pro | 8 | ||||
-rw-r--r-- | smtreeitem.cpp | 71 | ||||
-rw-r--r-- | smtreeitem.h | 36 | ||||
-rw-r--r-- | smtreemodel.cpp | 18 | ||||
-rw-r--r-- | smtreemodel.h | 27 |
5 files changed, 158 insertions, 2 deletions
@@ -45,7 +45,9 @@ SOURCES = main.cpp \ pictureviewerinfoitem.cpp \ archiveiteminfoedit.cpp \ archiveitemcoveredit.cpp \ - archiveitemeditdialog.cpp + archiveitemeditdialog.cpp \ + smtreeitem.cpp \ + smtreemodel.cpp HEADERS = listitem.h \ listmodel.h \ movieitem.h \ @@ -86,6 +88,8 @@ HEADERS = listitem.h \ pictureviewerinfoitem.h \ archiveiteminfoedit.h \ archiveitemcoveredit.h \ - archiveitemeditdialog.h + archiveitemeditdialog.h \ + smtreeitem.h \ + smtreemodel.h LIBS += -lmagic RESOURCES = shemov.qrc diff --git a/smtreeitem.cpp b/smtreeitem.cpp new file mode 100644 index 0000000..43998c3 --- /dev/null +++ b/smtreeitem.cpp @@ -0,0 +1,71 @@ +/* + 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 + 2 of the License, or (at your option) any later version. +*/ + +#include "smtreeitem.h" + +SmTreeItem::SmTreeItem(const QList<QVariant> &data, SmTreeItem *parent) : mData(data), mParent(parent) {} + +SmTreeItem::SmTreeItem(int rows, SmTreeItem *parent) : mParent(parent){ + for(int i = 0; i < rows; ++i){ + mData << QVariant(); + } +} + +SmTreeItem::~SmTreeItem(){ + qDeleteAll(mChildren); +} + +void SmTreeItem::appendChild(SmTreeItem *child){ + mChildren.append(child); +} + +SmTreeItem *SmTreeItem::child(int row){ + return mChildren.at(row); +} + +int SmTreeItem::childCount() const{ + return mChildren.count(); +} + +int SmTreeItem::columnCount() const{ + return mData.count(); +} + +int SmTreeItem::row() const{ + if(mParent){ + return mParent->mChildren.indexOf(const_cast<SmTreeItem*>(this)); + } + return 0; +} + +SmTreeItem *SmTreeItem::parent(){ + return mParent; +} + +QVariant SmTreeItem::data(int column) const{ + return mData.at(column); +} + +void SmTreeItem::setData(int column, QVariant &data){ + mData[column] = data; +} + +bool SmTreeItem::insertChild(int where, SmTreeItem *child){ + if((where < 0) || (where > mChildren.count())){ + return false; + } + mChildren.insert(where, child); + return true; +} + +bool SmTreeItem::removeChild(int where){ + if((where < 0) || (where >= mChildren.count())){ + return false; + } + delete mChildren.takeAt(where); + return true; +} diff --git a/smtreeitem.h b/smtreeitem.h new file mode 100644 index 0000000..4696edf --- /dev/null +++ b/smtreeitem.h @@ -0,0 +1,36 @@ +/* + 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 + 2 of the License, or (at your option) any later version. +*/ + +#ifndef SMTREEITEM_H +#define SMTREEITEM_H + +#include <QList> +#include <QVariant> + +class SmTreeItem { + public: + SmTreeItem(const QList<QVariant> &data, SmTreeItem *parent = 0); + SmTreeItem(int rows, SmTreeItem *parent = 0); + ~SmTreeItem(); + void appendChild(SmTreeItem *child); + SmTreeItem *child(int row); + int childCount() const; + int columnCount() const; + int row() const; + SmTreeItem *parent(); + QVariant data(int column) const; + void setData(int column, QVariant &data); + bool insertChild(int where, SmTreeItem *child); + bool removeChild(int where); + + private: + QList<SmTreeItem*> mChildren; + QList<QVariant> mData; + SmTreeItem *mParent; +}; + +#endif diff --git a/smtreemodel.cpp b/smtreemodel.cpp new file mode 100644 index 0000000..60cc977 --- /dev/null +++ b/smtreemodel.cpp @@ -0,0 +1,18 @@ +/* + 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 + 2 of the License, or (at your option) any later version. +*/ + +#include "smtreemodel.h" +#include "smtreeitem.h" + +SmTreeModel::SmTreeModel(const QStringList &headers, QObject *parent) : QAbstractItemModel(parent), mRootItem(0){ + mHeaders = headers; + mRootItem = new SmTreeItem(headers.count()); +} + +SmTreeModel::~SmTreeModel(){ + delete mRootItem; +} diff --git a/smtreemodel.h b/smtreemodel.h new file mode 100644 index 0000000..ede4b39 --- /dev/null +++ b/smtreemodel.h @@ -0,0 +1,27 @@ +/* + 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 + 2 of the License, or (at your option) any later version. +*/ + +#ifndef SMTREEMODEL_H +#define SMTREEMODEL_H + +#include <QAbstractItemModel> +#include <QStringList> + +class SmTreeItem; + +class SmTreeModel : public QAbstractItemModel { + Q_OBJECT + public: + explicit SmTreeModel(const QStringList &headers, QObject *parent = 0); + ~SmTreeModel(); + + private: + QStringList mHeaders; + SmTreeItem *mRootItem; +}; + +#endif |