treeitem.h
author insilmaril
Tue, 07 Jul 2009 09:34:24 +0000
changeset 779 1fb50e79661c
parent 777 8acac4fade1b
child 786 6269016c9905
permissions -rw-r--r--
Hiding of links works again
     1 #ifndef TREEITEM_H
     2 #define TREEITEM_H
     3 
     4 #include <QColor>
     5 #include <QList>
     6 #include <QVariant>
     7 
     8 #include "flagrow.h"
     9 //#include "mapitem.h"
    10 #include "noteobj.h"
    11 #include "xmlobj.h"
    12 
    13 class LinkableMapObj;
    14 class BranchObj;
    15 class BranchItem;
    16 class FloatImageObj;
    17 class ImageItem;
    18 class VymModel;
    19 
    20 class TreeItem:public XMLObj
    21 {
    22 public:
    23 	enum Type {Undefined,MapCenter,Branch,Image};	//FIXME-3 MapCenter still needed?
    24 	enum HideTmpMode {HideNone, HideExport};
    25 
    26     TreeItem();
    27     TreeItem(const QList<QVariant> &data, TreeItem *parent = 0);
    28     ~TreeItem();
    29 	void init();
    30 
    31 	// General housekeeping
    32 	virtual void setModel (VymModel *m);
    33 	virtual VymModel* getModel();
    34 
    35 
    36 	/*! Return number of item, as it would be after it would have been appended.
    37 	    This is used to notify view about layout changes before model is modified. */
    38 	virtual int getRowNumAppend (TreeItem *child);
    39 
    40     virtual void appendChild (TreeItem *child);
    41 	virtual void removeChild (int row);
    42 	virtual void removeChildBranches ();
    43 
    44     virtual TreeItem *child(int row);
    45     virtual int childCount() const;
    46     virtual int childNumber() const;
    47     virtual int columnCount() const;
    48 	virtual int branchCount() const;
    49 	virtual int imageCount() const;
    50 	virtual int xlinkCount() const;
    51 
    52     virtual int row() const;
    53 	virtual int column() const;
    54 	virtual int depth() ;
    55     virtual TreeItem *parent();
    56 
    57 	/*! Return number of item in parent by type, 
    58 	    e.g. first branch has number 0           */
    59 	virtual int childNum();				//! Return number of item in list of all children
    60 	virtual int num();					//! Return number of item by type
    61 	virtual int num (TreeItem *item);	//! Return number of item by type
    62 
    63 protected:
    64 	Type type;
    65 public:	
    66 	virtual void setType (const Type t);
    67 	virtual Type getType ();
    68 	virtual bool isBranchLikeType() const;
    69 	virtual QString getTypeName ();
    70 
    71 // Accessing data
    72     virtual QVariant data(int column) const;
    73 
    74 
    75 protected:
    76 	QColor headingColor;
    77 public:	
    78 	virtual void setHeading (const QString s);
    79 	virtual QString getHeading() const;
    80 	virtual std::string getHeadingStd() const;	//! convenience function used for debugging
    81 	virtual void setHeadingColor(QColor color);	//! Set color of heading. In BranchItem overloaded to update QGraphicsView
    82 	virtual QColor getHeadingColor();			//! Returns color of heading
    83 
    84 
    85 protected:
    86 	QString url;
    87 public:
    88 	void setURL (const QString &url);			//! Set URL
    89 	QString getURL ();							//! Get URL
    90 
    91 
    92 protected:
    93 	QString vymLink;
    94 public:
    95 	void setVymLink (const QString &url);			//! Set URL
    96 	QString getVymLink ();							//! Get URL
    97 
    98 
    99 protected:
   100 	NoteObj note;
   101 public:	
   102 	virtual void setNote(const QString &s);
   103 	virtual void clearNote();
   104 	virtual QString getNote();
   105 	virtual bool hasEmptyNote();
   106 	virtual void setNoteObj(const NoteObj &, bool updateNoteEditor=true); //FIXME-1 setNoteObj is called for every select or so???
   107 
   108 	virtual NoteObj getNoteObj();			
   109 	virtual QString getNoteASCII(const QString &indent, const int &width); // returns note	(ASCII)
   110     virtual QString getNoteASCII();			// returns note	(ASCII)
   111     virtual QString getNoteOpenDoc();		// returns note	(OpenDoc)
   112 
   113 
   114 protected:
   115 	FlagRow standardFlags;
   116 	FlagRow systemFlags;
   117 public:	
   118 	virtual void activateStandardFlag(const QString &flag);
   119 	virtual void deactivateStandardFlag(const QString &flag);
   120 	virtual void deactivateAllStandardFlags();
   121 
   122 	/*! \brief Toggle a Flag 
   123 	    If master is not NULL,, only one Flag from FlagRow master may 
   124 		be active simultanously, the others get deactivated.
   125 	*/	
   126 	virtual void toggleStandardFlag(const QString &flag, FlagRow *master=NULL);
   127 	virtual bool isActiveStandardFlag (const QString &flag);
   128 	virtual QStringList activeStandardFlagNames();
   129 	virtual FlagRow* getStandardFlagRow ();
   130 
   131 	virtual QStringList activeSystemFlagNames();
   132 
   133 
   134 	virtual bool canMoveDown();
   135 	virtual bool canMoveUp();
   136 
   137 protected:
   138 	QString objID;					//! id set during load/save currently used for xLinks
   139 public:
   140 	virtual void setID (const QString &s);
   141 	virtual QString getID ();
   142 
   143 	// Navigation and selection
   144 	virtual TreeItem* getChildNum(const int &n);
   145 	virtual BranchItem* getFirstBranch();
   146 	virtual BranchItem* getLastBranch();
   147 
   148 	/*! Get next branch after current branch. Return NULL if there is no
   149 	    next branch */
   150 	virtual BranchItem* getNextBranch(BranchItem* currentBranch);
   151 
   152 	virtual BranchItem* getBranchNum(const int &n);
   153 	virtual BranchObj* getBranchObjNum(const int &n);
   154 	virtual void setLastSelectedBranch();		//! Set myself as last selected in parent
   155 	virtual void setLastSelectedBranch(int i);	//! Set last selected branch directly
   156 	virtual TreeItem* getLastSelectedBranch();
   157 
   158 	virtual ImageItem* getImageNum(const int &n);
   159 	virtual FloatImageObj* getImageObjNum(const int &n);
   160 
   161 protected:
   162 	bool hideExport;							//! Hide this item in export
   163 public:
   164 	virtual void setHideTmp (HideTmpMode);
   165 	virtual bool hasHiddenExportParent ();
   166 	virtual void setHideInExport(bool);		// set export of object (and children)
   167 	virtual bool hideInExport();
   168 	virtual bool isHidden ();		
   169 
   170 	virtual QString getGeneralAttr();
   171 	
   172 protected:
   173 	VymModel *model;
   174 
   175     QList<TreeItem*> childItems;
   176     QList<QVariant> itemData;
   177     TreeItem *parentItem;
   178 
   179 	/*!  Set rootItem (does not change, needed for quick check 
   180 	     if some branch is mapCenter */
   181 	TreeItem *rootItem;
   182  
   183 	int branchOffset;
   184 	int branchCounter;
   185 	int lastSelectedBranchNum;
   186 
   187 	int imageOffset;
   188 	int imageCounter;
   189 
   190 	bool hidden;	//! Hidden in export if true
   191 };
   192 
   193 #endif