UEFITool/common/treeitem.cpp

101 lines
2.8 KiB
C++
Raw Normal View History

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