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