diff options
| -rw-r--r-- | shemov.pro | 6 | ||||
| -rw-r--r-- | smtreeitem.cpp | 2 | ||||
| -rw-r--r-- | smtreeitem.h | 2 | ||||
| -rw-r--r-- | smtreemodel.cpp | 144 | ||||
| -rw-r--r-- | smtreemodel.h | 22 | ||||
| -rw-r--r-- | smubermodel.cpp | 14 | ||||
| -rw-r--r-- | smubermodel.h | 30 | 
7 files changed, 216 insertions, 4 deletions
@@ -47,7 +47,8 @@ SOURCES = main.cpp \      archiveitemcoveredit.cpp \      archiveitemeditdialog.cpp \      smtreeitem.cpp \ -    smtreemodel.cpp +    smtreemodel.cpp \ +    smubermodel.cpp  HEADERS = listitem.h \      listmodel.h \      movieitem.h \ @@ -90,6 +91,7 @@ HEADERS = listitem.h \      archiveitemcoveredit.h \      archiveitemeditdialog.h \      smtreeitem.h \ -    smtreemodel.h +    smtreemodel.h \ +    smubermodel.h  LIBS += -lmagic  RESOURCES = shemov.qrc diff --git a/smtreeitem.cpp b/smtreeitem.cpp index 43998c3..950926e 100644 --- a/smtreeitem.cpp +++ b/smtreeitem.cpp @@ -50,7 +50,7 @@ QVariant SmTreeItem::data(int column) const{  	return mData.at(column);  } -void SmTreeItem::setData(int column, QVariant &data){ +void SmTreeItem::setData(int column, const QVariant &data){  	mData[column] = data;  } diff --git a/smtreeitem.h b/smtreeitem.h index 4696edf..807e3d7 100644 --- a/smtreeitem.h +++ b/smtreeitem.h @@ -23,7 +23,7 @@ class SmTreeItem {  		int row() const;  		SmTreeItem *parent();  		QVariant data(int column) const; -		void setData(int column, QVariant &data); +		void setData(int column, const QVariant &data);  		bool insertChild(int where, SmTreeItem *child);  		bool removeChild(int where); diff --git a/smtreemodel.cpp b/smtreemodel.cpp index 60cc977..2c7a2d6 100644 --- a/smtreemodel.cpp +++ b/smtreemodel.cpp @@ -16,3 +16,147 @@ SmTreeModel::SmTreeModel(const QStringList &headers, QObject *parent) : QAbstrac  SmTreeModel::~SmTreeModel(){  	delete mRootItem;  } + +int SmTreeModel::rowCount(const QModelIndex &parent) const{ +	SmTreeItem *parentItem = itemAt(parent); +	return parentItem->childCount(); +} + +int SmTreeModel::columnCount(const QModelIndex &parent) const{ +	Q_UNUSED(parent); +	return mRootItem->columnCount(); +} + +QModelIndex SmTreeModel::index(int row, int column, const QModelIndex &parent) const{ +	if(parent.isValid() && (parent.column() != 0)){ +		return QModelIndex(); +	} +	SmTreeItem *parentItem = itemAt(parent); +	SmTreeItem *childItem = parentItem->child(row); +	if(childItem){ +		return createIndex(row, column, childItem); +	} +	return QModelIndex(); +} + +Qt::ItemFlags SmTreeModel::flags(const QModelIndex &index) const{ +	if(!index.isValid()){ +		return 0; +	} +	return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +QVariant SmTreeModel::headerData(int section, Qt::Orientation orientation, int role) const{ +	if((orientation == Qt::Horizontal) && (role == Qt::DisplayRole)){ +		return mRootItem->data(section); +	} +	return QVariant(); +} + +bool SmTreeModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role){ +	if((orientation == Qt::Horizontal) && (role == Qt::DisplayRole)){ +		mRootItem->setData(section, value); +		emit headerDataChanged(orientation, section, section); +		return true; +	} +	return false; +} + +QVariant SmTreeModel::data(const QModelIndex &index, int role) const{ +	if(!index.isValid()){ +		return QVariant(); +	} +	SmTreeItem *item = itemAt(index); +	if(role == Qt::DisplayRole){ +		return item->data(index.column()); +	} +	if(role == Qt::EditRole){ +		return item->data(index.column()); +	} +	return QVariant(); +} + +bool SmTreeModel::setData(const QModelIndex &index, const QVariant &value, int role){ +	if(role != Qt::EditRole){ +		return false; +	} +	SmTreeItem *item = itemAt(index); +	item->setData(index.column(), value); +	emit dataChanged(index, index); +	return true; +} + +bool SmTreeModel::setRoot(SmTreeItem *rootItem){ +	if(mRootItem){ +		beginResetModel(); +		delete mRootItem; +		mRootItem = rootItem; +		endResetModel(); +		return true; +	} +	return false; +} + +bool SmTreeModel::insertRows(int row, int count, const QModelIndex &parent){ +	SmTreeItem *parentItem = itemAt(parent); +	bool retval; + +	if(row > parentItem->childCount()){ +		return false; +	} + +	beginInsertRows(parent, row, row + count - 1); +	for(int i = row; i < row + count; ++i){ +		SmTreeItem *newItem = new SmTreeItem(mRootItem->columnCount()); +		retval = parentItem->insertChild(i, newItem); +	} +	endInsertRows(); +	return retval; +} + +bool SmTreeModel::removeRows(int row, int count, const QModelIndex &parent){ +	SmTreeItem *parentItem = itemAt(parent); +	bool retval; + +	if(row > parentItem->childCount()){ +		return false; +	} + +	beginRemoveRows(parent, row, row + count - 1); +	for(int i = row + count; i > row; --i){ +		retval = parentItem->removeChild(i); + +	} +	endRemoveRows(); +	return retval; +} + +bool SmTreeModel::addRow(const QList<QVariant> &data, const QModelIndex &parent){ +	if(data.count() != mRootItem->columnCount()){ +		return false; +	} + +	SmTreeItem *parentItem = itemAt(parent); + +	if(insertRows(parentItem->childCount(), 1, parent)){ +		SmTreeItem *child = parentItem->child(parentItem->childCount()); +		delete child; +		SmTreeItem *newChild = new SmTreeItem(data, parentItem); +		child = newChild; +		QModelIndex start = index(parentItem->childCount() - 1, 0, parent); +		QModelIndex end = index(parentItem->childCount() - 1, parentItem->columnCount() - 1, parent); +		emit dataChanged(start, end); +		return true; +	} +	return false; +} + +SmTreeItem *SmTreeModel::itemAt(const QModelIndex &index) const{ +	if(index.isValid()){ +		SmTreeItem *item = static_cast<SmTreeItem*>(index.internalPointer()); +		if(item){ +			return item; +		} +	} +	return mRootItem; +} diff --git a/smtreemodel.h b/smtreemodel.h index ede4b39..46f852f 100644 --- a/smtreemodel.h +++ b/smtreemodel.h @@ -19,7 +19,29 @@ class SmTreeModel : public QAbstractItemModel {  		explicit SmTreeModel(const QStringList &headers, QObject *parent = 0);  		~SmTreeModel(); +		// counts +		int rowCount(const QModelIndex &parent) const; +		int columnCount(const QModelIndex &parent) const; + +		// index and flags +		QModelIndex index(int row, int column, const QModelIndex &parent) const; +		Qt::ItemFlags flags(const QModelIndex &index) const; + +		// headers + data +		QVariant headerData(int section, Qt::Orientation orientation, int role) const; +		bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role); +		QVariant data(const QModelIndex &index, int role) const; +		bool setData(const QModelIndex &index, const QVariant &value, int role); +		bool setRoot(SmTreeItem *rootItem); + +		// row manipulation +		bool insertRows(int row, int count, const QModelIndex &parent); +		bool removeRows(int row, int count, const QModelIndex &parent); +		bool addRow(const QList<QVariant> &data, const QModelIndex &parent); + +  	private: +		SmTreeItem *itemAt(const QModelIndex &index) const;  		QStringList mHeaders;  		SmTreeItem *mRootItem;  }; diff --git a/smubermodel.cpp b/smubermodel.cpp new file mode 100644 index 0000000..1134e18 --- /dev/null +++ b/smubermodel.cpp @@ -0,0 +1,14 @@ +/* +  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 "smubermodel.h" +#include "smtreemodel.h" +#include "actormodel.h" + +SmUberModel::SmUberModel(QObject *parent) : QObject(parent), mSeriesModel(0), mFileModel(0), mActorModel(0){ + +} diff --git a/smubermodel.h b/smubermodel.h new file mode 100644 index 0000000..edfa008 --- /dev/null +++ b/smubermodel.h @@ -0,0 +1,30 @@ +/* +  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 SMUBERMODEL_H +#define SMUBERMODEL_H + +#include <QObject> + +class SmTreeModel; +class ActorModel; + +class SmUberModel : public QObject { +	Q_OBJECT +	public: +		explicit SmUberModel(QObject *parent = 0); +		~SmUberModel(); + +	private: +		void populateSeriesmodel(); +		SmTreeModel *mSeriesModel; +		SmTreeModel *mFileModel; +		ActorModel *mActorModel; + +}; + +#endif  | 
