findresultitem.cpp
author convert-repo
Fri, 23 Jul 2010 16:43:49 +0000
changeset 849 988f1908a7c4
parent 847 43268373032d
permissions -rw-r--r--
update tags
     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 	orgIndex=-1;
    13 	orgModel=NULL;
    14 	if (data.isEmpty()) itemData.append(QVariant("empty"));
    15 }
    16 
    17 FindResultItem::~FindResultItem()
    18 {
    19     qDeleteAll(childItems);
    20 }
    21 
    22 FindResultItem *FindResultItem::child(int number)
    23 {
    24     return childItems.value(number);
    25 }
    26 
    27 int FindResultItem::childCount() const
    28 {
    29     return childItems.count();
    30 }
    31 
    32 int FindResultItem::childNumber() const
    33 {
    34     if (parentItem)
    35         return parentItem->childItems.indexOf(const_cast<FindResultItem*>(this));
    36 
    37     return 0;
    38 }
    39 
    40 int FindResultItem::columnCount() const
    41 {
    42     return itemData.count();
    43 }
    44 
    45 QVariant FindResultItem::data(int column) const
    46 {
    47     return itemData.value(column);
    48 }
    49 
    50 int FindResultItem::row() const
    51 {
    52     if (parentItem)
    53         return parentItem->childItems.indexOf(const_cast<FindResultItem*>(this));
    54 
    55     return 0;
    56 }
    57 
    58 bool FindResultItem::insertChildren(int position, int count, int columns)
    59 {
    60     if (position < 0 || position > childItems.size())
    61         return false;
    62 
    63     for (int row = 0; row < count; ++row) {
    64         QVector<QVariant> data(columns);
    65         FindResultItem *item = new FindResultItem(data, this);
    66         childItems.insert(position, item);
    67     }
    68 
    69     return true;
    70 }
    71 
    72 bool FindResultItem::insertColumns(int position, int columns)
    73 {
    74     if (position < 0 || position > itemData.size())
    75         return false;
    76 
    77     for (int column = 0; column < columns; ++column)
    78         itemData.insert(position, QVariant());
    79 
    80     foreach (FindResultItem *child, childItems)
    81         child->insertColumns(position, columns);
    82 
    83     return true;
    84 }
    85 
    86 FindResultItem *FindResultItem::parent()
    87 {
    88     return parentItem;
    89 }
    90 
    91 bool FindResultItem::removeChildren(int position, int count)
    92 {
    93     if (position < 0 || position + count > childItems.size())
    94         return false;
    95 
    96     for (int row = 0; row < count; ++row)
    97         delete childItems.takeAt(position);
    98 
    99     return true;
   100 }
   101 
   102 bool FindResultItem::removeColumns(int position, int columns)
   103 {
   104     if (position < 0 || position + columns > itemData.size())
   105         return false;
   106 
   107     for (int column = 0; column < columns; ++column)
   108         itemData.remove(position);
   109 
   110     foreach (FindResultItem *child, childItems)
   111         child->removeColumns(position, columns);
   112 
   113     return true;
   114 }
   115 
   116 bool FindResultItem::setData(int column, const QVariant &value)
   117 {
   118     if (column < 0 || column >= itemData.size())
   119         return false;
   120 
   121     itemData[column] = value;
   122     return true;
   123 }
   124 
   125 void FindResultItem::setOriginal (TreeItem *ti)
   126 {
   127 	orgModel=ti->getModel();
   128 	orgID=ti->getID();
   129 }
   130 
   131 int FindResultItem::getOriginalID()
   132 {
   133 	return orgID;
   134 }
   135 
   136 void FindResultItem::setOriginalIndex(int i)
   137 {
   138 	orgIndex=i;
   139 }
   140 
   141 int FindResultItem::getOriginalIndex()
   142 {
   143 	return orgIndex;
   144 }
   145 
   146 VymModel* FindResultItem::getOrgModel()
   147 {
   148 	return orgModel;
   149 }
   150