author | insilmaril |
Thu, 02 Apr 2009 09:54:42 +0000 | |
changeset 751 | 7fa9b3164cbe |
parent 750 | ff3b01ce0960 |
child 753 | 25a77484ec72 |
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@750 | 6 |
#include "treeitem.h" |
insilmaril@750 | 7 |
|
insilmaril@741 | 8 |
#include "branchobj.h" |
insilmaril@750 | 9 |
#include "branchitem.h" |
insilmaril@746 | 10 |
#include "vymmodel.h" |
insilmaril@725 | 11 |
|
insilmaril@725 | 12 |
TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent) |
insilmaril@725 | 13 |
{ |
insilmaril@746 | 14 |
model=NULL; |
insilmaril@746 | 15 |
|
insilmaril@725 | 16 |
parentItem = parent; |
insilmaril@725 | 17 |
itemData = data; |
insilmaril@726 | 18 |
lmo=NULL; |
insilmaril@738 | 19 |
|
insilmaril@738 | 20 |
branchOffset=0; |
insilmaril@741 | 21 |
branchCounter=0; |
insilmaril@738 | 22 |
lastSelectedBranchNum=-1; |
insilmaril@746 | 23 |
|
insilmaril@746 | 24 |
note.setNote(""); |
insilmaril@746 | 25 |
// note.setFontHint (textEditor->getFontHintDefault() ); //FIXME-2 |
insilmaril@746 | 26 |
// isNoteInEditor=false; |
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@749 | 111 |
|
insilmaril@749 | 112 |
int TreeItem::imageCount() const |
insilmaril@749 | 113 |
{ |
insilmaril@749 | 114 |
int imageCounter=0; |
insilmaril@749 | 115 |
return imageCounter; // FIXME-1 imageCounter needs to be calculated... |
insilmaril@749 | 116 |
} |
insilmaril@749 | 117 |
|
insilmaril@749 | 118 |
int TreeItem::xlinkCount() const // FIXME-2 check if xlinks are stored in a different way (global to model?) |
insilmaril@749 | 119 |
{ |
insilmaril@749 | 120 |
int xlinkCounter=0; |
insilmaril@749 | 121 |
return xlinkCounter; // FIXME-1 xlinkCounter needs to be calculated... |
insilmaril@749 | 122 |
} |
insilmaril@749 | 123 |
|
insilmaril@727 | 124 |
int TreeItem::row() const |
insilmaril@727 | 125 |
{ |
insilmaril@727 | 126 |
if (parentItem) |
insilmaril@727 | 127 |
return parentItem->childItems.indexOf(const_cast<TreeItem*>(this)); |
insilmaril@727 | 128 |
|
insilmaril@727 | 129 |
return 0; |
insilmaril@727 | 130 |
} |
insilmaril@727 | 131 |
|
insilmaril@727 | 132 |
int TreeItem::column() const |
insilmaril@727 | 133 |
{ |
insilmaril@727 | 134 |
return 0; |
insilmaril@727 | 135 |
} |
insilmaril@727 | 136 |
|
insilmaril@740 | 137 |
int TreeItem::depth() |
insilmaril@740 | 138 |
{ |
insilmaril@740 | 139 |
int d=-1; |
insilmaril@740 | 140 |
TreeItem *ti=this; |
insilmaril@740 | 141 |
while (ti!=NULL) |
insilmaril@740 | 142 |
{ |
insilmaril@740 | 143 |
ti=ti->parent(); |
insilmaril@740 | 144 |
d++; |
insilmaril@740 | 145 |
} |
insilmaril@740 | 146 |
return d; |
insilmaril@740 | 147 |
} |
insilmaril@740 | 148 |
|
insilmaril@727 | 149 |
TreeItem *TreeItem::parent() |
insilmaril@727 | 150 |
{ |
insilmaril@727 | 151 |
return parentItem; |
insilmaril@727 | 152 |
} |
insilmaril@727 | 153 |
|
insilmaril@741 | 154 |
int TreeItem::num() |
insilmaril@741 | 155 |
{ |
insilmaril@741 | 156 |
switch (type) |
insilmaril@741 | 157 |
{ |
insilmaril@741 | 158 |
case Undefined: return -1; |
insilmaril@741 | 159 |
case MapCenter: return parentItem->childItems.indexOf (this) - branchOffset; |
insilmaril@741 | 160 |
case Branch: return parentItem->childItems.indexOf (this) - branchOffset; |
insilmaril@746 | 161 |
case Image: return -1; // FIXME-2 |
insilmaril@741 | 162 |
default: return -1; |
insilmaril@741 | 163 |
} |
insilmaril@749 | 164 |
} |
insilmaril@749 | 165 |
|
insilmaril@749 | 166 |
int TreeItem::num (TreeItem *item) |
insilmaril@749 | 167 |
{ |
insilmaril@749 | 168 |
if (!item) return -1; |
insilmaril@749 | 169 |
switch (item->getType()) |
insilmaril@749 | 170 |
{ |
insilmaril@749 | 171 |
case Undefined: return -1; |
insilmaril@749 | 172 |
case MapCenter: return childItems.indexOf (this) - branchOffset; |
insilmaril@749 | 173 |
case Branch: return childItems.indexOf (this) - branchOffset; |
insilmaril@749 | 174 |
case Image: return -1; // FIXME-2 |
insilmaril@749 | 175 |
default: return -1; |
insilmaril@749 | 176 |
} |
insilmaril@741 | 177 |
} |
insilmaril@725 | 178 |
|
insilmaril@725 | 179 |
QVariant TreeItem::data(int column) const |
insilmaril@725 | 180 |
{ |
insilmaril@725 | 181 |
return itemData.value(column); |
insilmaril@725 | 182 |
} |
insilmaril@725 | 183 |
|
insilmaril@726 | 184 |
void TreeItem::setHeading (const QString s) |
insilmaril@725 | 185 |
{ |
insilmaril@726 | 186 |
itemData[0]=s; |
insilmaril@726 | 187 |
} |
insilmaril@726 | 188 |
|
insilmaril@726 | 189 |
QString TreeItem::getHeading () |
insilmaril@726 | 190 |
{ |
insilmaril@726 | 191 |
return itemData[0].toString(); |
insilmaril@726 | 192 |
} |
insilmaril@726 | 193 |
|
insilmaril@741 | 194 |
void TreeItem::setNote(const QString s) |
insilmaril@741 | 195 |
{ |
insilmaril@746 | 196 |
note.setNote(s); |
insilmaril@746 | 197 |
// updateNoteFlag(); FIXME-2 needed? |
insilmaril@746 | 198 |
if (model) |
insilmaril@746 | 199 |
model->emitContentHasChanged (this); |
insilmaril@746 | 200 |
} |
insilmaril@746 | 201 |
|
insilmaril@746 | 202 |
void TreeItem::setNoteObj(const NoteObj &n, bool updateNoteEditor) |
insilmaril@746 | 203 |
{ |
insilmaril@746 | 204 |
note=n; |
insilmaril@746 | 205 |
// updateNoteFlag(); FIXME-2 needed? |
insilmaril@746 | 206 |
if (model && updateNoteEditor) |
insilmaril@746 | 207 |
model->emitContentHasChanged (this); |
insilmaril@741 | 208 |
} |
insilmaril@741 | 209 |
|
insilmaril@741 | 210 |
QString TreeItem::getNote() |
insilmaril@741 | 211 |
{ |
insilmaril@746 | 212 |
return note.getNote(); |
insilmaril@746 | 213 |
} |
insilmaril@746 | 214 |
|
insilmaril@746 | 215 |
NoteObj TreeItem::getNoteObj() |
insilmaril@746 | 216 |
{ |
insilmaril@746 | 217 |
return note; |
insilmaril@746 | 218 |
} |
insilmaril@746 | 219 |
|
insilmaril@746 | 220 |
QString TreeItem::getNoteASCII(const QString &indent, const int &width) |
insilmaril@746 | 221 |
{ |
insilmaril@746 | 222 |
return note.getNoteASCII(indent,width); |
insilmaril@746 | 223 |
} |
insilmaril@746 | 224 |
|
insilmaril@746 | 225 |
QString TreeItem::getNoteASCII() |
insilmaril@746 | 226 |
{ |
insilmaril@746 | 227 |
return note.getNoteASCII(); |
insilmaril@746 | 228 |
} |
insilmaril@746 | 229 |
|
insilmaril@746 | 230 |
QString TreeItem::getNoteOpenDoc() |
insilmaril@746 | 231 |
{ |
insilmaril@746 | 232 |
return note.getNoteOpenDoc(); |
insilmaril@741 | 233 |
} |
insilmaril@741 | 234 |
|
insilmaril@726 | 235 |
void TreeItem::setType(const Type t) |
insilmaril@726 | 236 |
{ |
insilmaril@726 | 237 |
type=t; |
insilmaril@726 | 238 |
itemData[1]=getTypeName(); |
insilmaril@726 | 239 |
} |
insilmaril@726 | 240 |
|
insilmaril@726 | 241 |
TreeItem::Type TreeItem::getType() |
insilmaril@726 | 242 |
{ |
insilmaril@726 | 243 |
return type; |
insilmaril@726 | 244 |
} |
insilmaril@726 | 245 |
|
insilmaril@726 | 246 |
QString TreeItem::getTypeName() |
insilmaril@726 | 247 |
{ |
insilmaril@726 | 248 |
switch (type) |
insilmaril@726 | 249 |
{ |
insilmaril@726 | 250 |
case Undefined: return QString ("Undefined"); |
insilmaril@726 | 251 |
case MapCenter: return QString ("MapCenter"); |
insilmaril@726 | 252 |
case Branch: return QString ("Branch"); |
insilmaril@739 | 253 |
case Image: return QString ("Image"); |
insilmaril@726 | 254 |
default: return QString ("TreeItem::getTypeName no typename defined?!"); |
insilmaril@726 | 255 |
} |
insilmaril@725 | 256 |
} |
insilmaril@725 | 257 |
|
insilmaril@738 | 258 |
TreeItem* TreeItem::getChildNum(const int &n) |
insilmaril@738 | 259 |
{ |
insilmaril@738 | 260 |
if (n>=0 && n<childItems.count() ) |
insilmaril@738 | 261 |
return childItems.at(n); |
insilmaril@738 | 262 |
else |
insilmaril@738 | 263 |
return NULL; |
insilmaril@738 | 264 |
} |
insilmaril@738 | 265 |
|
insilmaril@750 | 266 |
BranchItem* TreeItem::getFirstBranch() |
insilmaril@738 | 267 |
{ |
insilmaril@741 | 268 |
if (branchCounter>0) |
insilmaril@738 | 269 |
return getBranchNum (branchOffset); |
insilmaril@738 | 270 |
else |
insilmaril@738 | 271 |
return NULL; |
insilmaril@738 | 272 |
} |
insilmaril@738 | 273 |
|
insilmaril@750 | 274 |
BranchItem* TreeItem::getLastBranch() |
insilmaril@738 | 275 |
{ |
insilmaril@741 | 276 |
if (branchCounter>0) |
insilmaril@741 | 277 |
return getBranchNum (branchOffset + branchCounter-1); |
insilmaril@738 | 278 |
else |
insilmaril@738 | 279 |
return NULL; |
insilmaril@738 | 280 |
} |
insilmaril@738 | 281 |
|
insilmaril@738 | 282 |
|
insilmaril@750 | 283 |
BranchItem* TreeItem::getBranchNum(const int &n) |
insilmaril@738 | 284 |
{ |
insilmaril@741 | 285 |
if (branchCounter>0) |
insilmaril@750 | 286 |
return (BranchItem*)getChildNum (branchOffset + n); |
insilmaril@738 | 287 |
else |
insilmaril@738 | 288 |
return NULL; |
insilmaril@738 | 289 |
} |
insilmaril@738 | 290 |
|
insilmaril@750 | 291 |
BranchObj* TreeItem::getBranchObjNum(const int &n) |
insilmaril@750 | 292 |
{ |
insilmaril@750 | 293 |
if (branchCounter>0) |
insilmaril@750 | 294 |
{ |
insilmaril@750 | 295 |
return (BranchObj*)(getChildNum (branchOffset+n)->lmo); |
insilmaril@750 | 296 |
} else |
insilmaril@750 | 297 |
return NULL; |
insilmaril@750 | 298 |
} |
insilmaril@750 | 299 |
|
insilmaril@738 | 300 |
void TreeItem::setLastSelectedBranch() |
insilmaril@738 | 301 |
{ |
insilmaril@738 | 302 |
if (parentItem) |
insilmaril@738 | 303 |
parentItem->lastSelectedBranchNum=parentItem->childItems.indexOf(this); |
insilmaril@738 | 304 |
} |
insilmaril@738 | 305 |
|
insilmaril@738 | 306 |
TreeItem* TreeItem::getLastSelectedBranch() |
insilmaril@738 | 307 |
{ |
insilmaril@738 | 308 |
return getBranchNum (lastSelectedBranchNum); |
insilmaril@738 | 309 |
} |
insilmaril@738 | 310 |
|
insilmaril@746 | 311 |
LinkableMapObj* TreeItem::getLMO() // FIXME-3 VM should be unnecessary in the end |
insilmaril@726 | 312 |
{ |
insilmaril@726 | 313 |
return lmo; |
insilmaril@726 | 314 |
} |
insilmaril@726 | 315 |
|
insilmaril@726 | 316 |
void TreeItem::setLMO(LinkableMapObj *l) |
insilmaril@726 | 317 |
{ |
insilmaril@726 | 318 |
lmo=l; |
insilmaril@726 | 319 |
} |
insilmaril@726 | 320 |