2013-10-08 15:07:03 +08:00
|
|
|
/* treemodel.h
|
|
|
|
|
2015-01-31 22:00:00 +08:00
|
|
|
Copyright (c) 2015, Nikolaj Schlej. All rights reserved.
|
2013-12-29 23:13:46 +08:00
|
|
|
This program and the accompanying materials
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
2013-10-08 15:07:03 +08:00
|
|
|
|
2013-12-29 23:13:46 +08:00
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
2013-10-08 15:07:03 +08:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __TREEMODEL_H__
|
|
|
|
#define __TREEMODEL_H__
|
|
|
|
|
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <QModelIndex>
|
|
|
|
#include <QString>
|
|
|
|
#include <QVariant>
|
|
|
|
|
|
|
|
#include "basetypes.h"
|
2014-02-27 17:14:41 +08:00
|
|
|
#include "types.h"
|
2013-10-08 15:07:03 +08:00
|
|
|
|
|
|
|
class TreeItem;
|
|
|
|
|
|
|
|
class TreeModel : public QAbstractItemModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2013-12-29 23:13:46 +08:00
|
|
|
TreeModel(QObject *parent = 0);
|
2013-10-08 15:07:03 +08:00
|
|
|
~TreeModel();
|
|
|
|
|
|
|
|
QVariant data(const QModelIndex &index, int role) const;
|
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation,
|
2014-07-25 07:59:51 +08:00
|
|
|
int role = Qt::DisplayRole) const;
|
2013-10-08 15:07:03 +08:00
|
|
|
QModelIndex index(int row, int column,
|
2014-07-25 07:59:51 +08:00
|
|
|
const QModelIndex &parent = QModelIndex()) const;
|
2013-10-08 15:07:03 +08:00
|
|
|
QModelIndex parent(const QModelIndex &index) const;
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
2013-12-29 23:13:46 +08:00
|
|
|
|
|
|
|
void setAction(const QModelIndex &index, const UINT8 action);
|
2015-01-31 22:00:00 +08:00
|
|
|
void setType(const QModelIndex &index, const UINT8 type);
|
2015-02-06 16:47:19 +08:00
|
|
|
void setSubtype(const QModelIndex &index, const UINT8 subtype);
|
2015-01-31 22:00:00 +08:00
|
|
|
void setName(const QModelIndex &index, const QString &name);
|
|
|
|
void setText(const QModelIndex &index, const QString &text);
|
2018-12-30 23:37:27 +08:00
|
|
|
void setDictionarySize(const QModelIndex &index, const UINT32 dictionarySize);
|
2014-01-11 17:20:58 +08:00
|
|
|
|
2015-01-31 22:00:00 +08:00
|
|
|
QString name(const QModelIndex &index) const;
|
|
|
|
QString text(const QModelIndex &index) const;
|
|
|
|
QString info(const QModelIndex &index) const;
|
2013-12-29 23:13:46 +08:00
|
|
|
UINT8 type(const QModelIndex &index) const;
|
2015-02-06 16:47:19 +08:00
|
|
|
UINT8 subtype(const QModelIndex &index) const;
|
2013-12-29 23:13:46 +08:00
|
|
|
QByteArray header(const QModelIndex &index) const;
|
|
|
|
bool hasEmptyHeader(const QModelIndex &index) const;
|
|
|
|
QByteArray body(const QModelIndex &index) const;
|
|
|
|
bool hasEmptyBody(const QModelIndex &index) const;
|
|
|
|
UINT8 action(const QModelIndex &index) const;
|
|
|
|
UINT8 compression(const QModelIndex &index) const;
|
2018-12-30 23:37:27 +08:00
|
|
|
UINT32 dictionarySize(const QModelIndex &index) const;
|
2013-11-18 23:23:59 +08:00
|
|
|
|
2015-02-06 16:47:19 +08:00
|
|
|
QModelIndex addItem(const UINT8 type, const UINT8 subtype = 0, const UINT8 compression = COMPRESSION_ALGORITHM_NONE,
|
2014-07-25 07:59:51 +08:00
|
|
|
const QString & name = QString(), const QString & text = QString(), const QString & info = QString(),
|
2015-07-05 19:28:53 +08:00
|
|
|
const QByteArray & header = QByteArray(), const QByteArray & body = QByteArray(),
|
2014-07-25 07:59:51 +08:00
|
|
|
const QModelIndex & parent = QModelIndex(), const UINT8 mode = CREATE_MODE_APPEND);
|
2013-12-29 23:13:46 +08:00
|
|
|
|
|
|
|
QModelIndex findParentOfType(const QModelIndex & index, UINT8 type) const;
|
2013-11-15 18:48:14 +08:00
|
|
|
|
2013-10-08 15:07:03 +08:00
|
|
|
private:
|
|
|
|
TreeItem *rootItem;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|