author | insilmaril |
Thu, 26 Mar 2009 07:49:17 +0000 | |
changeset 746 | ee6b0f3a4c2f |
parent 745 | 2d4cc445a86a |
child 749 | 9ff332964015 |
permissions | -rw-r--r-- |
insilmaril@746 | 1 |
#include <iostream> |
insilmaril@746 | 2 |
using namespace std; |
insilmaril@746 | 3 |
|
insilmaril@725 | 4 |
#include <QStringList> |
insilmaril@725 | 5 |
|
insilmaril@741 | 6 |
#include "branchobj.h" |
insilmaril@725 | 7 |
#include "treeitem.h" |
insilmaril@746 | 8 |
#include "vymmodel.h" |
insilmaril@725 | 9 |
|
insilmaril@725 | 10 |
TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent) |
insilmaril@725 | 11 |
{ |
insilmaril@746 | 12 |
model=NULL; |
insilmaril@746 | 13 |
|
insilmaril@725 | 14 |
parentItem = parent; |
insilmaril@725 | 15 |
itemData = data; |
insilmaril@726 | 16 |
lmo=NULL; |
insilmaril@738 | 17 |
|
insilmaril@738 | 18 |
branchOffset=0; |
insilmaril@741 | 19 |
branchCounter=0; |
insilmaril@738 | 20 |
lastSelectedBranchNum=-1; |
insilmaril@746 | 21 |
|
insilmaril@746 | 22 |
note.setNote(""); |
insilmaril@746 | 23 |
// note.setFontHint (textEditor->getFontHintDefault() ); //FIXME-2 |
insilmaril@746 | 24 |
// isNoteInEditor=false; |
insilmaril@746 | 25 |
|
insilmaril@746 | 26 |
|
insilmaril@725 | 27 |
} |
insilmaril@725 | 28 |
|
insilmaril@725 | 29 |
TreeItem::~TreeItem() |
insilmaril@725 | 30 |
{ |
insilmaril@725 | 31 |
qDeleteAll(childItems); |
insilmaril@725 | 32 |
} |
insilmaril@725 | 33 |
|
insilmaril@746 | 34 |
QString TreeItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset) |
insilmaril@746 | 35 |
{ |
insilmaril@746 | 36 |
qWarning ("TreeItem::saveToDir called directly"); |
insilmaril@746 | 37 |
return QString(); |
insilmaril@746 | 38 |
} |
insilmaril@746 | 39 |
|
insilmaril@746 | 40 |
|
insilmaril@746 | 41 |
/* |
insilmaril@746 | 42 |
void TreeItem::copy (OrnamentedObj* other) //FIXME-2 |
insilmaril@746 | 43 |
|
insilmaril@746 | 44 |
{ |
insilmaril@746 | 45 |
note.copy (other->note); |
insilmaril@746 | 46 |
model=other->model; |
insilmaril@746 | 47 |
} |
insilmaril@746 | 48 |
*/ |
insilmaril@746 | 49 |
|
insilmaril@746 | 50 |
void TreeItem::setModel (VymModel *m) |
insilmaril@746 | 51 |
{ |
insilmaril@746 | 52 |
model=m; |
insilmaril@746 | 53 |
} |
insilmaril@746 | 54 |
|
insilmaril@746 | 55 |
VymModel* TreeItem::getModel () |
insilmaril@746 | 56 |
{ |
insilmaril@746 | 57 |
return model; |
insilmaril@746 | 58 |
} |
insilmaril@741 | 59 |
|
insilmaril@725 | 60 |
void TreeItem::appendChild(TreeItem *item) |
insilmaril@725 | 61 |
{ |
insilmaril@725 | 62 |
childItems.append(item); |
insilmaril@746 | 63 |
item->setModel (model); |
insilmaril@741 | 64 |
|
insilmaril@741 | 65 |
if (item->type == Branch || item->type ==MapCenter) |
insilmaril@738 | 66 |
{ |
insilmaril@741 | 67 |
if (branchCounter==0) |
insilmaril@738 | 68 |
branchOffset=childItems.count()-1; |
insilmaril@741 | 69 |
branchCounter++; |
insilmaril@738 | 70 |
} |
insilmaril@725 | 71 |
} |
insilmaril@725 | 72 |
|
insilmaril@727 | 73 |
void TreeItem::removeChild(int row) |
insilmaril@727 | 74 |
{ |
insilmaril@745 | 75 |
if (row<0 || row > childItems.size()-1) |
insilmaril@745 | 76 |
qWarning ("TreeItem::removeChild tried to remove non existing item?!\n"); |
insilmaril@745 | 77 |
else |
insilmaril@727 | 78 |
{ |
insilmaril@745 | 79 |
cout << "TI::removeChild this="<<this<<" row="<<row<<endl; |
insilmaril@745 | 80 |
delete childItems.takeAt (row); |
insilmaril@745 | 81 |
} |
insilmaril@727 | 82 |
} |
insilmaril@727 | 83 |
|
insilmaril@725 | 84 |
TreeItem *TreeItem::child(int row) |
insilmaril@725 | 85 |
{ |
insilmaril@725 | 86 |
return childItems.value(row); |
insilmaril@725 | 87 |
} |
insilmaril@725 | 88 |
|
insilmaril@725 | 89 |
int TreeItem::childCount() const |
insilmaril@725 | 90 |
{ |
insilmaril@725 | 91 |
return childItems.count(); |
insilmaril@725 | 92 |
} |
insilmaril@725 | 93 |
|
insilmaril@745 | 94 |
int TreeItem::childNumber() const |
insilmaril@745 | 95 |
{ |
insilmaril@745 | 96 |
if (parentItem) |
insilmaril@745 | 97 |
return parentItem->childItems.indexOf(const_cast<TreeItem*>(this)); |
insilmaril@745 | 98 |
|
insilmaril@745 | 99 |
return 0; |
insilmaril@745 | 100 |
} |
insilmaril@745 | 101 |
|
insilmaril@725 | 102 |
int TreeItem::columnCount() const |
insilmaril@725 | 103 |
{ |
insilmaril@725 | 104 |
return itemData.count(); |
insilmaril@725 | 105 |
} |
insilmaril@741 | 106 |
|
insilmaril@741 | 107 |
int TreeItem::branchCount() const |
insilmaril@741 | 108 |
{ |
insilmaril@741 | 109 |
return branchCounter; |
insilmaril@741 | 110 |
} |
insilmaril@727 | 111 |
int TreeItem::row() const |
insilmaril@727 | 112 |
{ |
insilmaril@727 | 113 |
if (parentItem) |
insilmaril@727 | 114 |
return parentItem->childItems.indexOf(const_cast<TreeItem*>(this)); |
insilmaril@727 | 115 |
|
insilmaril@727 | 116 |
return 0; |
insilmaril@727 | 117 |
} |
insilmaril@727 | 118 |
|
insilmaril@727 | 119 |
int TreeItem::column() const |
insilmaril@727 | 120 |
{ |
insilmaril@727 | 121 |
return 0; |
insilmaril@727 | 122 |
} |
insilmaril@727 | 123 |
|
insilmaril@740 | 124 |
int TreeItem::depth() |
insilmaril@740 | 125 |
{ |
insilmaril@740 | 126 |
int d=-1; |
insilmaril@740 | 127 |
TreeItem *ti=this; |
insilmaril@740 | 128 |
while (ti!=NULL) |
insilmaril@740 | 129 |
{ |
insilmaril@740 | 130 |
ti=ti->parent(); |
insilmaril@740 | 131 |
d++; |
insilmaril@740 | 132 |
} |
insilmaril@740 | 133 |
return d; |
insilmaril@740 | 134 |
} |
insilmaril@740 | 135 |
|
insilmaril@727 | 136 |
TreeItem *TreeItem::parent() |
insilmaril@727 | 137 |
{ |
insilmaril@727 | 138 |
return parentItem; |
insilmaril@727 | 139 |
} |
insilmaril@727 | 140 |
|
insilmaril@741 | 141 |
int TreeItem::num() |
insilmaril@741 | 142 |
{ |
insilmaril@741 | 143 |
switch (type) |
insilmaril@741 | 144 |
{ |
insilmaril@741 | 145 |
case Undefined: return -1; |
insilmaril@741 | 146 |
case MapCenter: return parentItem->childItems.indexOf (this) - branchOffset; |
insilmaril@741 | 147 |
case Branch: return parentItem->childItems.indexOf (this) - branchOffset; |
insilmaril@746 | 148 |
case Image: return -1; // FIXME-2 |
insilmaril@741 | 149 |
default: return -1; |
insilmaril@741 | 150 |
} |
insilmaril@741 | 151 |
|
insilmaril@741 | 152 |
} |
insilmaril@725 | 153 |
|
insilmaril@725 | 154 |
QVariant TreeItem::data(int column) const |
insilmaril@725 | 155 |
{ |
insilmaril@725 | 156 |
return itemData.value(column); |
insilmaril@725 | 157 |
} |
insilmaril@725 | 158 |
|
insilmaril@726 | 159 |
void TreeItem::setHeading (const QString s) |
insilmaril@725 | 160 |
{ |
insilmaril@726 | 161 |
itemData[0]=s; |
insilmaril@726 | 162 |
} |
insilmaril@726 | 163 |
|
insilmaril@726 | 164 |
QString TreeItem::getHeading () |
insilmaril@726 | 165 |
{ |
insilmaril@726 | 166 |
return itemData[0].toString(); |
insilmaril@726 | 167 |
} |
insilmaril@726 | 168 |
|
insilmaril@741 | 169 |
void TreeItem::setNote(const QString s) |
insilmaril@741 | 170 |
{ |
insilmaril@746 | 171 |
note.setNote(s); |
insilmaril@746 | 172 |
// updateNoteFlag(); FIXME-2 needed? |
insilmaril@746 | 173 |
if (model) |
insilmaril@746 | 174 |
model->emitContentHasChanged (this); |
insilmaril@746 | 175 |
} |
insilmaril@746 | 176 |
|
insilmaril@746 | 177 |
void TreeItem::setNoteObj(const NoteObj &n, bool updateNoteEditor) |
insilmaril@746 | 178 |
{ |
insilmaril@746 | 179 |
note=n; |
insilmaril@746 | 180 |
// updateNoteFlag(); FIXME-2 needed? |
insilmaril@746 | 181 |
if (model && updateNoteEditor) |
insilmaril@746 | 182 |
model->emitContentHasChanged (this); |
insilmaril@741 | 183 |
} |
insilmaril@741 | 184 |
|
insilmaril@741 | 185 |
QString TreeItem::getNote() |
insilmaril@741 | 186 |
{ |
insilmaril@746 | 187 |
return note.getNote(); |
insilmaril@746 | 188 |
} |
insilmaril@746 | 189 |
|
insilmaril@746 | 190 |
NoteObj TreeItem::getNoteObj() |
insilmaril@746 | 191 |
{ |
insilmaril@746 | 192 |
return note; |
insilmaril@746 | 193 |
} |
insilmaril@746 | 194 |
|
insilmaril@746 | 195 |
QString TreeItem::getNoteASCII(const QString &indent, const int &width) |
insilmaril@746 | 196 |
{ |
insilmaril@746 | 197 |
return note.getNoteASCII(indent,width); |
insilmaril@746 | 198 |
} |
insilmaril@746 | 199 |
|
insilmaril@746 | 200 |
QString TreeItem::getNoteASCII() |
insilmaril@746 | 201 |
{ |
insilmaril@746 | 202 |
return note.getNoteASCII(); |
insilmaril@746 | 203 |
} |
insilmaril@746 | 204 |
|
insilmaril@746 | 205 |
QString TreeItem::getNoteOpenDoc() |
insilmaril@746 | 206 |
{ |
insilmaril@746 | 207 |
return note.getNoteOpenDoc(); |
insilmaril@741 | 208 |
} |
insilmaril@741 | 209 |
|
insilmaril@726 | 210 |
void TreeItem::setType(const Type t) |
insilmaril@726 | 211 |
{ |
insilmaril@726 | 212 |
type=t; |
insilmaril@726 | 213 |
itemData[1]=getTypeName(); |
insilmaril@726 | 214 |
} |
insilmaril@726 | 215 |
|
insilmaril@726 | 216 |
TreeItem::Type TreeItem::getType() |
insilmaril@726 | 217 |
{ |
insilmaril@726 | 218 |
return type; |
insilmaril@726 | 219 |
} |
insilmaril@726 | 220 |
|
insilmaril@726 | 221 |
QString TreeItem::getTypeName() |
insilmaril@726 | 222 |
{ |
insilmaril@726 | 223 |
switch (type) |
insilmaril@726 | 224 |
{ |
insilmaril@726 | 225 |
case Undefined: return QString ("Undefined"); |
insilmaril@726 | 226 |
case MapCenter: return QString ("MapCenter"); |
insilmaril@726 | 227 |
case Branch: return QString ("Branch"); |
insilmaril@739 | 228 |
case Image: return QString ("Image"); |
insilmaril@726 | 229 |
default: return QString ("TreeItem::getTypeName no typename defined?!"); |
insilmaril@726 | 230 |
} |
insilmaril@725 | 231 |
} |
insilmaril@725 | 232 |
|
insilmaril@738 | 233 |
TreeItem* TreeItem::getChildNum(const int &n) |
insilmaril@738 | 234 |
{ |
insilmaril@738 | 235 |
if (n>=0 && n<childItems.count() ) |
insilmaril@738 | 236 |
return childItems.at(n); |
insilmaril@738 | 237 |
else |
insilmaril@738 | 238 |
return NULL; |
insilmaril@738 | 239 |
} |
insilmaril@738 | 240 |
|
insilmaril@738 | 241 |
TreeItem* TreeItem::getFirstBranch() |
insilmaril@738 | 242 |
{ |
insilmaril@741 | 243 |
if (branchCounter>0) |
insilmaril@738 | 244 |
return getBranchNum (branchOffset); |
insilmaril@738 | 245 |
else |
insilmaril@738 | 246 |
return NULL; |
insilmaril@738 | 247 |
} |
insilmaril@738 | 248 |
|
insilmaril@738 | 249 |
TreeItem* TreeItem::getLastBranch() |
insilmaril@738 | 250 |
{ |
insilmaril@741 | 251 |
if (branchCounter>0) |
insilmaril@741 | 252 |
return getBranchNum (branchOffset + branchCounter-1); |
insilmaril@738 | 253 |
else |
insilmaril@738 | 254 |
return NULL; |
insilmaril@738 | 255 |
} |
insilmaril@738 | 256 |
|
insilmaril@738 | 257 |
|
insilmaril@738 | 258 |
TreeItem* TreeItem::getBranchNum(const int &n) |
insilmaril@738 | 259 |
{ |
insilmaril@741 | 260 |
if (branchCounter>0) |
insilmaril@738 | 261 |
return getChildNum (branchOffset + n); |
insilmaril@738 | 262 |
else |
insilmaril@738 | 263 |
return NULL; |
insilmaril@738 | 264 |
} |
insilmaril@738 | 265 |
|
insilmaril@738 | 266 |
void TreeItem::setLastSelectedBranch() |
insilmaril@738 | 267 |
{ |
insilmaril@738 | 268 |
if (parentItem) |
insilmaril@738 | 269 |
parentItem->lastSelectedBranchNum=parentItem->childItems.indexOf(this); |
insilmaril@738 | 270 |
} |
insilmaril@738 | 271 |
|
insilmaril@738 | 272 |
TreeItem* TreeItem::getLastSelectedBranch() |
insilmaril@738 | 273 |
{ |
insilmaril@738 | 274 |
return getBranchNum (lastSelectedBranchNum); |
insilmaril@738 | 275 |
} |
insilmaril@738 | 276 |
|
insilmaril@746 | 277 |
LinkableMapObj* TreeItem::getLMO() // FIXME-3 VM should be unnecessary in the end |
insilmaril@726 | 278 |
{ |
insilmaril@726 | 279 |
return lmo; |
insilmaril@726 | 280 |
} |
insilmaril@726 | 281 |
|
insilmaril@726 | 282 |
void TreeItem::setLMO(LinkableMapObj *l) |
insilmaril@726 | 283 |
{ |
insilmaril@726 | 284 |
lmo=l; |
insilmaril@726 | 285 |
} |
insilmaril@726 | 286 |