findresultitem.cpp
author insilmaril
Tue, 09 Mar 2010 13:09:05 +0000
changeset 833 bfacef6f29c1
parent 829 832e96c9abb6
child 842 bec082472471
permissions -rw-r--r--
Bugfix: Previous checkin caused toggleScroll to fail
     1 #include <QStringList>
     2 
     3 #include "findresultitem.h"
     4 #include "treeitem.h"
     5 #include "vymmodel.h"
     6 
     7 FindResultItem::FindResultItem(const QVector<QVariant> &data, FindResultItem *parent)
     8 {
     9     parentItem = parent;
    10     itemData = data;
    11 	orgID=-1;
    12 	orgModel=NULL;
    13 }
    14 
    15 FindResultItem::~FindResultItem()
    16 {
    17     qDeleteAll(childItems);
    18 }
    19 
    20 FindResultItem *FindResultItem::child(int number)
    21 {
    22     return childItems.value(number);
    23 }
    24 
    25 int FindResultItem::childCount() const
    26 {
    27     return childItems.count();
    28 }
    29 
    30 int FindResultItem::childNumber() const
    31 {
    32     if (parentItem)
    33         return parentItem->childItems.indexOf(const_cast<FindResultItem*>(this));
    34 
    35     return 0;
    36 }
    37 
    38 int FindResultItem::columnCount() const
    39 {
    40     return itemData.count();
    41 }
    42 
    43 QVariant FindResultItem::data(int column) const
    44 {
    45     return itemData.value(column);
    46 }
    47 
    48 int FindResultItem::row() const
    49 {
    50     if (parentItem)
    51         return parentItem->childItems.indexOf(const_cast<FindResultItem*>(this));
    52 
    53     return 0;
    54 }
    55 
    56 
    57 bool FindResultItem::insertChildren(int position, int count, int columns)
    58 {
    59     if (position < 0 || position > childItems.size())
    60         return false;
    61 
    62     for (int row = 0; row < count; ++row) {
    63         QVector<QVariant> data(columns);
    64         FindResultItem *item = new FindResultItem(data, this);
    65         childItems.insert(position, item);
    66     }
    67 
    68     return true;
    69 }
    70 
    71 bool FindResultItem::insertColumns(int position, int columns)
    72 {
    73     if (position < 0 || position > itemData.size())
    74         return false;
    75 
    76     for (int column = 0; column < columns; ++column)
    77         itemData.insert(position, QVariant());
    78 
    79     foreach (FindResultItem *child, childItems)
    80         child->insertColumns(position, columns);
    81 
    82     return true;
    83 }
    84 
    85 FindResultItem *FindResultItem::parent()
    86 {
    87     return parentItem;
    88 }
    89 
    90 bool FindResultItem::removeChildren(int position, int count)
    91 {
    92     if (position < 0 || position + count > childItems.size())
    93         return false;
    94 
    95     for (int row = 0; row < count; ++row)
    96         delete childItems.takeAt(position);
    97 
    98     return true;
    99 }
   100 
   101 bool FindResultItem::removeColumns(int position, int columns)
   102 {
   103     if (position < 0 || position + columns > itemData.size())
   104         return false;
   105 
   106     for (int column = 0; column < columns; ++column)
   107         itemData.remove(position);
   108 
   109     foreach (FindResultItem *child, childItems)
   110         child->removeColumns(position, columns);
   111 
   112     return true;
   113 }
   114 
   115 bool FindResultItem::setData(int column, const QVariant &value)
   116 {
   117     if (column < 0 || column >= itemData.size())
   118         return false;
   119 
   120     itemData[column] = value;
   121     return true;
   122 }
   123 
   124 void FindResultItem::setOriginal (TreeItem *ti)
   125 {
   126 	orgModel=ti->getModel();
   127 	orgID=ti->getID();
   128 }
   129 
   130 uint FindResultItem::getOrgID()
   131 {
   132 	return orgID;
   133 }
   134 
   135 VymModel* FindResultItem::getOrgModel()
   136 {
   137 	return orgModel;
   138 }
   139