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