2013-10-08 15:07:03 +08:00
|
|
|
/* treeitem.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 TREEITEM_H
|
|
|
|
#define TREEITEM_H
|
2013-10-08 15:07:03 +08:00
|
|
|
|
2016-06-26 16:05:45 +08:00
|
|
|
#include <list>
|
2016-07-16 14:59:29 +08:00
|
|
|
#include <iterator>
|
2013-10-08 15:07:03 +08:00
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
#include "ubytearray.h"
|
|
|
|
#include "ustring.h"
|
2013-10-08 15:07:03 +08:00
|
|
|
#include "basetypes.h"
|
|
|
|
|
2016-07-16 14:59:29 +08:00
|
|
|
template <typename ForwardIt>
|
|
|
|
ForwardIt u_std_next(
|
|
|
|
ForwardIt it,
|
|
|
|
typename std::iterator_traits<ForwardIt>::difference_type n = 1
|
|
|
|
)
|
|
|
|
{
|
|
|
|
std::advance(it, n);
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
2013-10-08 15:07:03 +08:00
|
|
|
class TreeItem
|
|
|
|
{
|
|
|
|
public:
|
2016-06-26 11:54:21 +08:00
|
|
|
TreeItem(const UINT8 type, const UINT8 subtype, const UString &name, const UString &text, const UString &info,
|
|
|
|
const UByteArray & header, const UByteArray & body, const UByteArray & tail,
|
2016-07-05 23:22:03 +08:00
|
|
|
const bool fixed, const bool compressed, const UByteArray & parsingData,
|
2014-07-25 07:59:51 +08:00
|
|
|
TreeItem *parent = 0);
|
2016-06-26 16:05:45 +08:00
|
|
|
~TreeItem(); // Non-trivial implementation in CPP file
|
2013-10-08 15:07:03 +08:00
|
|
|
|
2013-11-07 21:46:28 +08:00
|
|
|
// Operations with items
|
2016-06-26 16:05:45 +08:00
|
|
|
void appendChild(TreeItem *item) { childItems.push_back(item); }
|
|
|
|
void prependChild(TreeItem *item) { childItems.push_front(item); };
|
2015-12-30 06:39:43 +08:00
|
|
|
UINT8 insertChildBefore(TreeItem *item, TreeItem *newItem); // Non-trivial implementation in CPP file
|
|
|
|
UINT8 insertChildAfter(TreeItem *item, TreeItem *newItem); // Non-trivial implementation in CPP file
|
2013-11-07 21:46:28 +08:00
|
|
|
|
|
|
|
// Model support operations
|
2016-07-16 14:59:29 +08:00
|
|
|
TreeItem *child(int row) { return *u_std_next(childItems.begin(), row); }
|
2016-06-26 16:05:45 +08:00
|
|
|
int childCount() const {return childItems.size(); }
|
2015-12-30 06:39:43 +08:00
|
|
|
int columnCount() const { return 5; }
|
2016-06-26 16:05:45 +08:00
|
|
|
UString data(int column) const; // Non-trivial implementation in CPP file
|
2015-12-30 06:39:43 +08:00
|
|
|
int row() const; // Non-trivial implementation in CPP file
|
|
|
|
TreeItem *parent() { return parentItem; }
|
2013-10-08 15:07:03 +08:00
|
|
|
|
2013-11-07 21:46:28 +08:00
|
|
|
// Reading operations for item parameters
|
2016-06-26 11:54:21 +08:00
|
|
|
UString name() const { return itemName; }
|
|
|
|
void setName(const UString &text) { itemName = text; }
|
2015-01-31 22:00:00 +08:00
|
|
|
|
2015-12-30 06:39:43 +08:00
|
|
|
UINT8 type() const { return itemType; }
|
|
|
|
void setType(const UINT8 type) { itemType = type; }
|
2015-01-31 22:00:00 +08:00
|
|
|
|
2015-12-30 06:39:43 +08:00
|
|
|
UINT8 subtype() const { return itemSubtype; }
|
|
|
|
void setSubtype(const UINT8 subtype) { itemSubtype = subtype; }
|
2015-01-31 22:00:00 +08:00
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
UString text() const { return itemText; }
|
|
|
|
void setText(const UString &text) { itemText = text; }
|
2015-01-31 22:00:00 +08:00
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
UByteArray header() const { return itemHeader; }
|
2015-12-30 06:39:43 +08:00
|
|
|
bool hasEmptyHeader() const { return itemHeader.isEmpty(); }
|
2015-01-31 22:00:00 +08:00
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
UByteArray body() const { return itemBody; };
|
2015-12-30 06:39:43 +08:00
|
|
|
bool hasEmptyBody() const { return itemBody.isEmpty(); }
|
2015-02-06 16:47:19 +08:00
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
UByteArray tail() const { return itemTail; };
|
2016-04-21 04:41:18 +08:00
|
|
|
bool hasEmptyTail() const { return itemTail.isEmpty(); }
|
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
UByteArray parsingData() const { return itemParsingData; }
|
2015-12-30 06:39:43 +08:00
|
|
|
bool hasEmptyParsingData() const { return itemParsingData.isEmpty(); }
|
2016-06-26 11:54:21 +08:00
|
|
|
void setParsingData(const UByteArray & data) { itemParsingData = data; }
|
2015-02-06 16:47:19 +08:00
|
|
|
|
2016-06-26 11:54:21 +08:00
|
|
|
UString info() const { return itemInfo; }
|
2016-07-05 23:22:03 +08:00
|
|
|
void addInfo(const UString &info, const bool append) { if (append) itemInfo += info; else itemInfo = info + itemInfo; }
|
2016-06-26 11:54:21 +08:00
|
|
|
void setInfo(const UString &info) { itemInfo = info; }
|
2015-01-31 22:00:00 +08:00
|
|
|
|
2015-12-30 06:39:43 +08:00
|
|
|
UINT8 action() const {return itemAction; }
|
|
|
|
void setAction(const UINT8 action) { itemAction = action; }
|
|
|
|
|
2016-07-05 23:22:03 +08:00
|
|
|
bool fixed() const { return itemFixed; }
|
2015-12-30 06:39:43 +08:00
|
|
|
void setFixed(const bool fixed) { itemFixed = fixed; }
|
|
|
|
|
2016-07-05 23:22:03 +08:00
|
|
|
bool compressed() const { return itemCompressed; }
|
2015-12-30 06:39:43 +08:00
|
|
|
void setCompressed(const bool compressed) { itemCompressed = compressed; }
|
2013-10-08 15:07:03 +08:00
|
|
|
|
2015-01-31 22:00:00 +08:00
|
|
|
private:
|
2016-06-26 16:05:45 +08:00
|
|
|
std::list<TreeItem*> childItems;
|
2015-01-31 22:00:00 +08:00
|
|
|
UINT8 itemAction;
|
|
|
|
UINT8 itemType;
|
2015-02-06 16:47:19 +08:00
|
|
|
UINT8 itemSubtype;
|
2016-06-26 11:54:21 +08:00
|
|
|
UString itemName;
|
|
|
|
UString itemText;
|
|
|
|
UString itemInfo;
|
|
|
|
UByteArray itemHeader;
|
|
|
|
UByteArray itemBody;
|
|
|
|
UByteArray itemTail;
|
|
|
|
UByteArray itemParsingData;
|
2015-12-30 06:39:43 +08:00
|
|
|
bool itemFixed;
|
|
|
|
bool itemCompressed;
|
|
|
|
TreeItem* parentItem;
|
2013-10-08 15:07:03 +08:00
|
|
|
};
|
|
|
|
|
2016-04-09 18:47:19 +08:00
|
|
|
#endif // TREEITEM_H
|