findresultitem.cpp
author insilmaril
Mon, 08 Mar 2010 12:21:46 +0000
changeset 827 a591443f229c
parent 825 1ad892c1a709
child 829 832e96c9abb6
permissions -rw-r--r--
Added missing flag for Bugzilla
insilmaril@825
     1
#include <QStringList>
insilmaril@825
     2
insilmaril@825
     3
#include "findresultitem.h"
insilmaril@825
     4
insilmaril@825
     5
FindResultItem::FindResultItem(const QVector<QVariant> &data, FindResultItem *parent)
insilmaril@825
     6
{
insilmaril@825
     7
    parentItem = parent;
insilmaril@825
     8
    itemData = data;
insilmaril@825
     9
}
insilmaril@825
    10
insilmaril@825
    11
FindResultItem::~FindResultItem()
insilmaril@825
    12
{
insilmaril@825
    13
    qDeleteAll(childItems);
insilmaril@825
    14
}
insilmaril@825
    15
insilmaril@825
    16
FindResultItem *FindResultItem::child(int number)
insilmaril@825
    17
{
insilmaril@825
    18
    return childItems.value(number);
insilmaril@825
    19
}
insilmaril@825
    20
insilmaril@825
    21
int FindResultItem::childCount() const
insilmaril@825
    22
{
insilmaril@825
    23
    return childItems.count();
insilmaril@825
    24
}
insilmaril@825
    25
insilmaril@825
    26
int FindResultItem::childNumber() const
insilmaril@825
    27
{
insilmaril@825
    28
    if (parentItem)
insilmaril@825
    29
        return parentItem->childItems.indexOf(const_cast<FindResultItem*>(this));
insilmaril@825
    30
insilmaril@825
    31
    return 0;
insilmaril@825
    32
}
insilmaril@825
    33
insilmaril@825
    34
int FindResultItem::columnCount() const
insilmaril@825
    35
{
insilmaril@825
    36
    return itemData.count();
insilmaril@825
    37
}
insilmaril@825
    38
insilmaril@825
    39
QVariant FindResultItem::data(int column) const
insilmaril@825
    40
{
insilmaril@825
    41
    return itemData.value(column);
insilmaril@825
    42
}
insilmaril@825
    43
insilmaril@825
    44
bool FindResultItem::insertChildren(int position, int count, int columns)
insilmaril@825
    45
{
insilmaril@825
    46
    if (position < 0 || position > childItems.size())
insilmaril@825
    47
        return false;
insilmaril@825
    48
insilmaril@825
    49
    for (int row = 0; row < count; ++row) {
insilmaril@825
    50
        QVector<QVariant> data(columns);
insilmaril@825
    51
        FindResultItem *item = new FindResultItem(data, this);
insilmaril@825
    52
        childItems.insert(position, item);
insilmaril@825
    53
    }
insilmaril@825
    54
insilmaril@825
    55
    return true;
insilmaril@825
    56
}
insilmaril@825
    57
insilmaril@825
    58
bool FindResultItem::insertColumns(int position, int columns)
insilmaril@825
    59
{
insilmaril@825
    60
    if (position < 0 || position > itemData.size())
insilmaril@825
    61
        return false;
insilmaril@825
    62
insilmaril@825
    63
    for (int column = 0; column < columns; ++column)
insilmaril@825
    64
        itemData.insert(position, QVariant());
insilmaril@825
    65
insilmaril@825
    66
    foreach (FindResultItem *child, childItems)
insilmaril@825
    67
        child->insertColumns(position, columns);
insilmaril@825
    68
insilmaril@825
    69
    return true;
insilmaril@825
    70
}
insilmaril@825
    71
insilmaril@825
    72
FindResultItem *FindResultItem::parent()
insilmaril@825
    73
{
insilmaril@825
    74
    return parentItem;
insilmaril@825
    75
}
insilmaril@825
    76
insilmaril@825
    77
bool FindResultItem::removeChildren(int position, int count)
insilmaril@825
    78
{
insilmaril@825
    79
    if (position < 0 || position + count > childItems.size())
insilmaril@825
    80
        return false;
insilmaril@825
    81
insilmaril@825
    82
    for (int row = 0; row < count; ++row)
insilmaril@825
    83
        delete childItems.takeAt(position);
insilmaril@825
    84
insilmaril@825
    85
    return true;
insilmaril@825
    86
}
insilmaril@825
    87
insilmaril@825
    88
bool FindResultItem::removeColumns(int position, int columns)
insilmaril@825
    89
{
insilmaril@825
    90
    if (position < 0 || position + columns > itemData.size())
insilmaril@825
    91
        return false;
insilmaril@825
    92
insilmaril@825
    93
    for (int column = 0; column < columns; ++column)
insilmaril@825
    94
        itemData.remove(position);
insilmaril@825
    95
insilmaril@825
    96
    foreach (FindResultItem *child, childItems)
insilmaril@825
    97
        child->removeColumns(position, columns);
insilmaril@825
    98
insilmaril@825
    99
    return true;
insilmaril@825
   100
}
insilmaril@825
   101
insilmaril@825
   102
bool FindResultItem::setData(int column, const QVariant &value)
insilmaril@825
   103
{
insilmaril@825
   104
    if (column < 0 || column >= itemData.size())
insilmaril@825
   105
        return false;
insilmaril@825
   106
insilmaril@825
   107
    itemData[column] = value;
insilmaril@825
   108
    return true;
insilmaril@825
   109
}