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
|
|
|
|
|
|
|
*/
|
|
|
|
|
2016-04-09 18:47:19 +08:00
|
|
|
#ifndef TREEMODEL_H
|
|
|
|
#define TREEMODEL_H
|
2013-10-08 15:07:03 +08:00
|
|
|
|
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <QVariant>
|
2016-06-26 11:54:21 +08:00
|
|
|
#include <QObject>
|
2013-10-08 15:07:03 +08:00
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
#include "ustring.h"
|
|
|
|
#include "ubytearray.h"
|
2013-10-08 15:07:03 +08:00
|
|
|
#include "basetypes.h"
|
2014-02-27 17:14:41 +08:00
|
|
|
#include "types.h"
|
2016-06-26 11:54:21 +08:00
|
|
|
#include "umodelindex.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();
|
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
QVariant data(const UModelIndex &index, int role) const;
|
|
|
|
Qt::ItemFlags flags(const UModelIndex &index) const;
|
2013-10-08 15:07:03 +08:00
|
|
|
QVariant headerData(int section, Qt::Orientation orientation,
|
2014-07-25 07:59:51 +08:00
|
|
|
int role = Qt::DisplayRole) const;
|
2016-06-26 11:54:21 +08:00
|
|
|
UModelIndex index(int row, int column,
|
|
|
|
const UModelIndex &parent = UModelIndex()) const;
|
|
|
|
UModelIndex parent(const UModelIndex &index) const;
|
|
|
|
int rowCount(const UModelIndex &parent = UModelIndex()) const;
|
|
|
|
int columnCount(const UModelIndex &parent = UModelIndex()) const;
|
2013-12-29 23:13:46 +08:00
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
void setAction(const UModelIndex &index, const UINT8 action);
|
|
|
|
void setType(const UModelIndex &index, const UINT8 type);
|
|
|
|
void setSubtype(const UModelIndex &index, const UINT8 subtype);
|
|
|
|
void setName(const UModelIndex &index, const UString &name);
|
|
|
|
void setText(const UModelIndex &index, const UString &text);
|
|
|
|
void setInfo(const UModelIndex &index, const UString &info);
|
|
|
|
void addInfo(const UModelIndex &index, const UString &info, const bool append = TRUE);
|
|
|
|
void setParsingData(const UModelIndex &index, const UByteArray &data);
|
|
|
|
void setFixed(const UModelIndex &index, const bool fixed);
|
|
|
|
void setCompressed(const UModelIndex &index, const bool compressed);
|
2015-03-13 14:48:53 +08:00
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
UString name(const UModelIndex &index) const;
|
|
|
|
UString text(const UModelIndex &index) const;
|
|
|
|
UString info(const UModelIndex &index) const;
|
|
|
|
UINT8 type(const UModelIndex &index) const;
|
|
|
|
UINT8 subtype(const UModelIndex &index) const;
|
|
|
|
UByteArray header(const UModelIndex &index) const;
|
|
|
|
bool hasEmptyHeader(const UModelIndex &index) const;
|
|
|
|
UByteArray body(const UModelIndex &index) const;
|
|
|
|
bool hasEmptyBody(const UModelIndex &index) const;
|
|
|
|
UByteArray tail(const UModelIndex &index) const;
|
|
|
|
bool hasEmptyTail(const UModelIndex &index) const;
|
|
|
|
UByteArray parsingData(const UModelIndex &index) const;
|
|
|
|
bool hasEmptyParsingData(const UModelIndex &index) const;
|
|
|
|
UINT8 action(const UModelIndex &index) const;
|
|
|
|
bool fixed(const UModelIndex &index) const;
|
2015-12-30 06:39:43 +08:00
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
bool compressed(const UModelIndex &index) const;
|
2013-11-18 23:23:59 +08:00
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
UModelIndex addItem(const UINT8 type, const UINT8 subtype,
|
|
|
|
const UString & name, const UString & text, const UString & info,
|
|
|
|
const UByteArray & header, const UByteArray & body, const UByteArray & tail,
|
|
|
|
const bool fixed, const UByteArray & parsingData = UByteArray(),
|
|
|
|
const UModelIndex & parent = UModelIndex(), const UINT8 mode = CREATE_MODE_APPEND);
|
2013-12-29 23:13:46 +08:00
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
UModelIndex findParentOfType(const UModelIndex & index, UINT8 type) const;
|
2013-11-15 18:48:14 +08:00
|
|
|
|
2013-10-08 15:07:03 +08:00
|
|
|
private:
|
|
|
|
TreeItem *rootItem;
|
|
|
|
};
|
|
|
|
|
2016-04-09 18:47:19 +08:00
|
|
|
#endif // TREEMODEL_H
|