2013-10-08 15:07:03 +08:00
|
|
|
/* treeitem.cpp
|
|
|
|
|
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
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "treeitem.h"
|
2014-02-27 17:14:41 +08:00
|
|
|
#include "types.h"
|
2013-10-08 15:07:03 +08:00
|
|
|
|
2016-10-28 00:31:15 +08:00
|
|
|
TreeItem::TreeItem(const UINT32 offset, const UINT8 type, const UINT8 subtype,
|
2016-06-26 11:54:21 +08:00
|
|
|
const UString & name, const UString & text, const UString & info,
|
|
|
|
const UByteArray & header, const UByteArray & body, const UByteArray & tail,
|
2016-10-28 00:31:15 +08:00
|
|
|
const bool fixed, const bool compressed,
|
2015-01-31 22:00:00 +08:00
|
|
|
TreeItem *parent) :
|
2016-10-28 00:31:15 +08:00
|
|
|
itemOffset(offset),
|
2018-04-30 13:33:19 +08:00
|
|
|
itemAction(Actions::NoAction),
|
2015-01-31 22:00:00 +08:00
|
|
|
itemType(type),
|
2015-02-06 16:47:19 +08:00
|
|
|
itemSubtype(subtype),
|
2018-04-30 13:33:19 +08:00
|
|
|
itemMarking(0),
|
2015-01-31 22:00:00 +08:00
|
|
|
itemName(name),
|
|
|
|
itemText(text),
|
|
|
|
itemInfo(info),
|
|
|
|
itemHeader(header),
|
|
|
|
itemBody(body),
|
2016-04-21 04:41:18 +08:00
|
|
|
itemTail(tail),
|
2015-12-30 06:39:43 +08:00
|
|
|
itemFixed(fixed),
|
|
|
|
itemCompressed(compressed),
|
2018-09-01 01:05:01 +08:00
|
|
|
itemCompression(COMPRESSION_ALGORITHM_NONE),
|
2015-01-31 22:00:00 +08:00
|
|
|
parentItem(parent)
|
2013-11-07 21:46:28 +08:00
|
|
|
{
|
2016-06-26 16:05:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TreeItem::~TreeItem() {
|
|
|
|
std::list<TreeItem*>::iterator begin = childItems.begin();
|
|
|
|
while (begin != childItems.end()) {
|
|
|
|
delete *begin;
|
|
|
|
++begin;
|
|
|
|
}
|
2013-11-07 21:46:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
UINT8 TreeItem::insertChildBefore(TreeItem *item, TreeItem *newItem)
|
|
|
|
{
|
2016-07-16 14:59:29 +08:00
|
|
|
std::list<TreeItem*>::iterator found = std::find(childItems.begin(), childItems.end(), item);
|
|
|
|
if (found == childItems.end())
|
2016-06-26 11:54:21 +08:00
|
|
|
return U_ITEM_NOT_FOUND;
|
2016-06-26 16:05:45 +08:00
|
|
|
childItems.insert(found, newItem);
|
2016-06-26 11:54:21 +08:00
|
|
|
return U_SUCCESS;
|
2013-11-07 21:46:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
UINT8 TreeItem::insertChildAfter(TreeItem *item, TreeItem *newItem)
|
2013-10-08 15:07:03 +08:00
|
|
|
{
|
2016-07-16 14:59:29 +08:00
|
|
|
std::list<TreeItem*>::iterator found = std::find(childItems.begin(), childItems.end(), item);
|
|
|
|
if (found == childItems.end())
|
2016-06-26 11:54:21 +08:00
|
|
|
return U_ITEM_NOT_FOUND;
|
2016-06-26 16:05:45 +08:00
|
|
|
childItems.insert(++found, newItem);
|
2016-06-26 11:54:21 +08:00
|
|
|
return U_SUCCESS;
|
2013-10-08 15:07:03 +08:00
|
|
|
}
|
|
|
|
|
2016-06-26 16:05:45 +08:00
|
|
|
UString TreeItem::data(int column) const
|
2013-10-08 15:07:03 +08:00
|
|
|
{
|
2014-07-25 07:59:51 +08:00
|
|
|
switch (column)
|
2013-10-08 15:07:03 +08:00
|
|
|
{
|
2015-01-31 22:00:00 +08:00
|
|
|
case 0: // Name
|
2013-11-14 18:40:39 +08:00
|
|
|
return itemName;
|
2015-01-31 22:00:00 +08:00
|
|
|
case 1: // Action
|
2016-06-26 11:54:21 +08:00
|
|
|
return actionTypeToUString(itemAction);
|
2015-01-31 22:00:00 +08:00
|
|
|
case 2: // Type
|
2016-06-26 11:54:21 +08:00
|
|
|
return itemTypeToUString(itemType);
|
2015-02-06 16:47:19 +08:00
|
|
|
case 3: // Subtype
|
2016-06-26 11:54:21 +08:00
|
|
|
return itemSubtypeToUString(itemType, itemSubtype);
|
2015-01-31 22:00:00 +08:00
|
|
|
case 4: // Text
|
2013-10-08 15:07:03 +08:00
|
|
|
return itemText;
|
|
|
|
default:
|
2016-06-26 16:05:45 +08:00
|
|
|
return UString();
|
2013-10-08 15:07:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int TreeItem::row() const
|
|
|
|
{
|
2016-06-26 16:05:45 +08:00
|
|
|
if (parentItem) {
|
2016-07-16 14:59:29 +08:00
|
|
|
std::list<TreeItem*>::const_iterator iter = parentItem->childItems.begin();
|
2016-06-26 16:05:45 +08:00
|
|
|
for (int i = 0; i < (int)parentItem->childItems.size(); ++i, ++iter) {
|
|
|
|
if (const_cast<TreeItem*>(this) == *iter)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2013-10-08 15:07:03 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2016-07-16 15:08:41 +08:00
|
|
|
|
|
|
|
TreeItem* TreeItem::child(int row)
|
|
|
|
{
|
|
|
|
std::list<TreeItem*>::iterator child = childItems.begin();
|
|
|
|
std::advance(child, row);
|
|
|
|
return *child;
|
2018-09-01 01:05:01 +08:00
|
|
|
}
|