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