10 #include "adaptormodel.h"
14 #include "branchitem.h"
15 #include "imageitem.h"
16 #include "mapeditor.h"
19 #include "treemodel.h"
24 class FindResultModel;
35 typedef QMap<uint,QString> ItemList ;
37 class VymModel : public TreeModel {
39 Q_CLASSINFO("D-Bus Interface", "org.insilmaril.vym.VymModel-h")
41 ////////////////////////////////////////////
42 // General housekeeping
43 ////////////////////////////////////////////
45 QString version; //!< version string saved in vym file
51 static uint idLast; //! the last used unique ID
59 void makeTmpDirectories(); //!< create temporary directories e.g. for history
61 MapEditor* getMapEditor();
62 uint getModelID(); //! Return unique ID of model
64 void setView (VymView*); //! Set vymView for resizing editors after load
69 bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview
70 void updateActions(); //!< Update buttons in mainwindow
73 ////////////////////////////////////////////
75 ////////////////////////////////////////////
78 bool zipped; // should map be zipped
79 static int mapNum; // unique number for model used in save/undo
80 FileType fileType; // type of file, e.g. vym, freemind...
81 QString fileName; // short name of file (for tab)
84 QString filePath; // path to file which will be saved
85 // /home/tux/example.vym
87 QString fileDir; // dir where file is saved
90 QString destPath; // path to .vym file (needed for vymlinks)
91 // /home/tux/example.vym
93 QString mapName; // fileName without ".vym"
96 QString tmpMapDir; // tmp directory with undo history
98 QTimer *autosaveTimer;
99 QTimer *fileChangedTimer;
100 QDateTime fileChangedTime;
103 /*! This function saves all information of the map to disc.
104 saveToDir also calls the functions for all BranchObj and other objects in the map.
105 The structure of the map itself is returned as QString and passed back to Main,
106 where saveToDir is called initially
108 QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel);
110 /*! Save all data in tree*/
111 QString saveTreeToDir (const QString&,const QString&,const QPointF&,QList <Link*> &tmpLinks);// Save data recursivly to tempdir
114 /*! \brief Sets filepath, filename and mapname
116 If the filepath is "/home/tux/map.xml", then the filename will be set
117 to map.xml. The destname is needed for vymLinks, pointing to another map.
118 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
122 /*! \brief Set File path
124 The destname is needed to construct the references between maps
126 void setFilePath (QString filepath,QString destname);
127 void setFilePath (QString); //!< Overloaded for convenience
128 QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml"
129 QString getFileDir (); //!< e.g. "/home/tux"
130 QString getFileName (); //!< e.g. "map.xml"
131 QString getMapName (); //!< e.g. "map"
132 QString getDestPath (); //!< e.g. "/home/tux/map.vym"
134 bool parseVymText(const QString &s);
138 The data is read from file. Depending on LoadMode the current
139 selection gets replaced by data or the data is appended.
141 File::ErrorCode loadMap (
143 const LoadMode &lmode=NewMap, //!< New map, replace or add to selection
144 const FileType &ftype=VymMap, //!< VymMap or FreeMind
145 const int &contentFilter=0x0000,//!< For undo types of content can be filterd
146 int pos=-1 //!< Optionally tell position where to add data
150 /*! \brief Save the map to file */
151 File::ErrorCode save(const SaveMode &);
154 void loadImage (BranchItem *dst=NULL, const QString &fn="");
155 void saveImage (ImageItem *ii=NULL, QString format="", QString fn="");
158 void importDirInt(BranchItem *,QDir);
159 void importDirInt(const QString&);
164 bool renameMap( const QString &newPath); //! Rename map and change lockfile
165 void setReadOnly( bool b );
169 VymLock vymLock; //! Handle lockfiles and related information
170 bool readonly; //! if map is locked, it can be opened readonly
176 ////////////////////////////////////////////
177 // history (undo/redo)
178 ////////////////////////////////////////////
180 bool mapDefault; //!< Flag if map is untouched
181 bool mapChanged; //!< Flag if undo is possible
182 bool mapUnsaved; //!< Flag if map should be saved
184 QString histPath; //!< Path to history file
185 SimpleSettings undoSet; //!< undo/redo commands, saved in histPath
186 int stepsTotal; //!< total number of steps (undos+redos)
187 int curStep; //!< Current step in history (ring buffer)
188 int curClipboard; //!< number of history step, which is the current clipboard
189 int redosAvail; //!< Available number of redo steps
190 int undosAvail; //!< Available number of undo steps
191 bool blockReposition; //!< block while load or undo
192 bool blockSaveState; //!< block while load or undo
194 bool isDefault(); //!< true, if map is still the empty default map
195 void makeDefault(); //!< Reset changelog, declare this as default map
196 bool hasChanged() ; //!< true, if something has changed and is not saved yet
197 void setChanged(); //!< called from TextEditor via LinkableMapObj
199 /*! \brief Get name of object
201 Returns heading of a branch or name of an object for use in comment
204 QString getObjectName(LinkableMapObj*);
205 QString getObjectName(TreeItem*);
207 void redo(); //!< Redo last action
208 bool isRedoAvailable(); //!< True, if redo is available
209 void undo(); //!< Undo last action
210 bool isUndoAvailable(); //!< True, if undo is available
211 void gotoHistoryStep (int); //!< Goto a specifig step in history
214 QString getHistoryPath(); //!< Path to directory containing the history
215 void resetHistory(); //!< Initialize history
217 /*! \brief Save the current changes in map
219 Two commands and selections are saved:
221 - undocommand and undoselection to undo the change
222 - redocommand and redoselection to redo the action after an undo
224 Additionally a comment is logged.
228 const SaveMode& savemode,
229 const QString &undoSelection,
230 const QString &undoCommand,
231 const QString &redoSelection,
232 const QString &redoCommand,
233 const QString &comment,
234 TreeItem *saveSelection,
237 /*! Overloaded for convenience */
238 void saveStateChangingPart(
239 TreeItem *undoSelection,
240 TreeItem* redoSelection,
241 const QString &redoCommand,
242 const QString &comment);
244 /*! Overloaded for convenience */
245 void saveStateRemovingPart(
246 TreeItem *redoSelection,
247 const QString &comment);
249 /*! Overloaded for convenience */
251 TreeItem *undoSelection,
252 const QString &undoCommand,
253 TreeItem *redoSelection,
254 const QString &redoCommand,
255 const QString &comment);
257 /*! Overloaded for convenience */
259 const QString &undoSelection,
260 const QString &undoCommand,
261 const QString &redoSelection,
262 const QString &redoCommand,
263 const QString &comment) ;
265 /*! Overloaded for convenience */
267 const QString &undoCommand,
268 const QString &redoCommand,
269 const QString &comment) ;
271 /*! Save a change in string and merge
272 minor sequential changes */
273 void saveStateMinimal(
274 TreeItem *undoSelection,
275 const QString &undoCommand,
276 TreeItem *redoSelection,
277 const QString &redoCommand,
278 const QString &comment);
280 /*! Save state before loading a map */
281 void saveStateBeforeLoad (
283 const QString &fname);
285 ////////////////////////////////////////////
287 ////////////////////////////////////////////
289 QGraphicsScene *getScene();
291 TreeItem* findBySelectString (QString s);
292 TreeItem* findID (const uint &i); // find MapObj by unique ID
293 TreeItem* findUuid (const QUuid &i); // find MapObj by unique ID
296 ////////////////////////////////////////////
298 ////////////////////////////////////////////
300 void setVersion(const QString &);
301 QString getVersion();
302 void setTitle (const QString &);
304 void setAuthor (const QString &);
305 QString getAuthor ();
306 void setComment (const QString &);
307 QString getComment ();
311 void setSortFilter (const QString &);
312 QString getSortFilter ();
316 void sortFilterChanged (QString ); //!< Notify editors of new filter
319 void setHeading(const VymText &vt, BranchItem *bi=NULL); //!< Set heading of item
320 void setHeadingPlainText(const QString &s, BranchItem *bi=NULL); //!< Set heading of item
321 Heading getHeading(); //!< Get heading of item
322 void setNote(const VymNote &vn); //!< Set note text
323 VymNote getNote(); //!< Get note text
324 bool hasRichTextNote(); //!< Check type of vymText used
325 void loadNote (const QString &fn); //!< Load note from file
326 void saveNote (const QString &fn); //!< Save note to file
329 BranchItem* findCurrent; // next object in find process
330 BranchItem* findPrevious; // next object in find process
331 bool EOFind; // true, if search failed
334 void findDuplicateURLs(); // find duplicate URLs, testing only so far
335 bool findAll (FindResultModel*, QString s, Qt::CaseSensitivity cs=Qt::CaseInsensitive); // Search all objects at once, also notes
336 BranchItem* findText(QString s,Qt::CaseSensitivity cs); // Find object, also in note
337 void findReset(); // Reset Search
342 void setURL(QString url);
343 QString getURL(); // returns URL of selection or ""
344 QStringList getURLs(bool ignoreScrolled=true); // returns URLs of subtree
347 void setFrameType(const FrameObj::FrameType &);
348 void setFrameType(const QString &);
349 void toggleFrameIncludeChildren ();
350 void setFrameIncludeChildren (bool);
351 void setFramePenColor (const QColor &);
352 void setFrameBrushColor (const QColor &);
353 void setFramePadding (const int &);
354 void setFrameBorderWidth (const int &);
355 void setIncludeImagesVer(bool);
356 void setIncludeImagesHor(bool);
357 void setChildrenLayout(BranchItem::LayoutHint layoutHint);
358 void setHideLinkUnselected (bool);
360 /*! Should object be hidden in exports (clouded)? */
361 void setHideExport(bool, TreeItem* ti=NULL);
363 /*! Should object be hidden in exports (clouded)? */
364 void toggleHideExport();
366 /*! Toggle task for branch */
369 /*! Cycle through task states */
370 void cycleTaskStatus(bool reverse=false);
372 /*! Set task to sleep for number of days or until a given date*/
373 bool setTaskSleep(const QString &s);
374 /*! count tasks in this model */
379 void copy(); //!< Copy to clipboard
381 void paste(); //!< Paste clipboard to branch and backup
382 void cut(); //!< Cut to clipboard (and copy)
384 bool moveUp(BranchItem *bi); //!< Move branch up without saving state
385 void moveUp(); //!< Move branch up with saving state
386 bool moveDown(BranchItem *bi); //!< Move branch down without saving state
387 void moveDown(); //!< Move branch down
388 void detach(); //!< Detach branch and use as new mapcenter
389 void sortChildren(bool inverse=false); //!< Sort children lexically
391 // The create methods are used to quickly parse a XML file
392 BranchItem* createMapCenter(); //!< Create MapCenter
393 BranchItem* createBranch(BranchItem *dst); //!< Create Branch
394 ImageItem* createImage(BranchItem *dst); //!< Create image
397 bool createLink(Link *l); //!< Create XLink, will create MO automatically if needed
398 QColor getXLinkColor();
400 Qt::PenStyle getXLinkPenStyle();
401 QString getXLinkStyleBegin();
402 QString getXLinkStyleEnd();
404 AttributeItem* addAttribute();
405 AttributeItem* addAttribute(BranchItem *dst, AttributeItem* );
407 /*! \brief Add new mapcenter
409 Disclaimer: Still experimental, not fully supported yet.
411 BranchItem* addMapCenter(bool saveStateFlag=true);
413 BranchItem* addMapCenter(QPointF absPos);
415 /*! \brief Add new branch
417 Depending on num the new branch is created
419 -3 above selection as child of selections parent
420 -2 as child of selection
421 -1 below selection as child of selections parent
422 0..n insert at a specific position in selections parent
423 (needed for free relinking)
427 BranchItem* addNewBranchInt(BranchItem *dst, int pos); // pos allows to add above/below selection, or as child at pos
432 // -3 insert in children of parent above selection
433 // -2 add branch to selection
434 // -1 insert in children of parent below selection
435 // 0..n insert in children of parent at pos
437 BranchItem* addNewBranch(BranchItem *bi=NULL, int pos=-2);
438 BranchItem* addNewBranchBefore(); //!< Insert branch between selection and its parent
439 /*! \brief Relink a branch to a new destination dst
440 Relinks branch to dst at branch position pos. There is no saveState
441 here, as for example moveUp or moving in MapEditor have
442 different needs to call saveState
443 Returns true if relinking was successful.
449 bool updateSelection=false,
450 QPointF orgPos=QPointF()
452 bool relinkImage (ImageItem* image, BranchItem* dst);
455 bool cleaningUpLinks; //!< True while cleaning up to avoid recursion
457 void cleanupItems(); //!< Delete orphaned Items
458 void deleteLater (uint); //!< Delete later with new beginRemoveRow
459 void deleteSelection(); //!< Delete selection
460 void deleteKeepChildren(bool saveStateFlag=true); //!< remove branch, but keep children
462 void deleteChildren(); //!< keep branch, but remove children
464 TreeItem* deleteItem(TreeItem*); //!< Delete item and return parent (if parent!= rootItem)
465 void deleteLink (Link*); //!< Remove Link and related LinkItems in TreeModel
466 void clearItem (TreeItem* ti); //!< Remove all children of TreeItem ti
467 bool scrollBranch(BranchItem *);
468 bool unscrollBranch(BranchItem *);
470 void unscrollChildren();
471 void setScale (qreal,qreal);
472 void growSelectionSize();
473 void shrinkSelectionSize();
474 void resetSelectionSize();
475 void emitExpandAll();
476 void emitExpandOneLevel();
477 void emitCollapseOneLevel();
478 void emitCollapseUnselected();
481 void expandOneLevel();
482 void collapseOneLevel();
483 void collapseUnselected();
487 ItemList getTargets();
489 void toggleStandardFlag (const QString &name, FlagRow *master=NULL);
490 void addFloatImage(const QImage &img);
492 void colorBranch(QColor);
493 void colorSubtree(QColor,BranchItem *bi=NULL);
494 QColor getCurrentHeadingColor();
497 void note2URLs(); // get URLs from note
498 void editHeading2URL(); // copy heading to URL
499 void editBugzilla2URL(); // create URL to Bugzilla
500 void getBugzillaData(bool subtree); // get data from Novell Bugzilla
501 void editFATE2URL(); // create URL to FATE
502 void setVymLink (const QString &); // Set vymLink for selection
503 void deleteVymLink(); // delete link to another map
504 QString getVymLink(); // return path to map
505 QStringList getVymLinks(); // return paths in subtree
506 void followXLink (int);
508 void setXLinkColor(const QString &);
509 void setXLinkLineStyle(const QString &);
510 void setXLinkStyleBegin(const QString &);
511 void setXLinkStyleEnd(const QString &);
512 void setXLinkWidth(int);
514 ////////////////////////////////////////////
516 ////////////////////////////////////////////
519 /* \brief Process one command and its parameters */
520 QVariant parseAtom (const QString &atom, bool &noError, QString &errorMsg);
522 /* \brief Runs the script */
523 QVariant execute (const QString &script);
527 ////////////////////////////////////////////
529 ////////////////////////////////////////////
531 TreeItem::HideTmpMode hidemode; // true while exporting to hide some stuff
534 /*! Set or unset temporary hiding of objects during export */
535 void setExportMode (bool);
537 /*! Save as image. Returns offset to upper left corner of image */
538 QPointF exportImage (QString fname="",bool askForName=true,QString format="PNG");
540 /*! Save as PDF . Returns offset to upper left corner of image */
541 void exportPDF (QString fname="",bool askForName=true);
543 /*! Save as SVG . Returns offset to upper left corner of image */
544 QPointF exportSVG (QString fname="",bool askForName=true);
546 /*! Export as XTML to directory */
547 void exportXML(QString dir="", QString fname="", bool useDialog=true);
549 /*! Export as A&O report text to file */
550 void exportAO (QString fname="",bool askForName=true);
552 /*! Export as ASCII text to file */
553 void exportASCII (bool listTasks = false, const QString &fname = "",bool askForName = true);
555 /*! Export as CSV text to file */
556 void exportCSV (const QString &fname="",bool askForName=true);
558 /*! Export as HTML to directory */
559 void exportHTML(const QString &dir="", const QString &fname="", bool useDialog=true);
561 /*! Export as OpenOfficeOrg presentation */
562 void exportImpress (const QString &,const QString &);
564 /*! Returns if Export in recently used format is possible*/
565 bool exportLastAvailable(
566 QString &description,
571 /*! Export in recently used format (saved in map)*/
574 /*! Export as LaTeX */
575 void exportLaTeX (const QString& dir="", bool useDialog=true);
577 /*! Export as OrgMode input for emacs*/
578 void exportOrgMode (const QString& fname="", bool useDialog=true);
580 ////////////////////////////////////////////
582 ////////////////////////////////////////////
584 void registerEditor (QWidget *);
585 void unregisterEditor (QWidget *);
587 void setMapZoomFactor (const double &);
588 void setMapRotationAngle (const double&);
589 void setMapAnimDuration(const int &d);
590 void setMapAnimCurve(const QEasingCurve &c);
593 double rotationAngle;
595 QEasingCurve animCurve;
597 bool hasContextPos; //!< True, if we have a context pos
598 QPointF contextPos; //!< local position during context menu
600 void setContextPos (QPointF); //!< local position during context menu
601 void unsetContextPos (); //!< forget local position after context menu
603 void updateNoteFlag(); //!< Signal origination in TextEditor
604 void reposition(); //!< Call reposition for all MCOs
605 void setHideTmpMode (TreeItem::HideTmpMode mode);
607 void emitNoteChanged (TreeItem *ti);
608 void emitDataChanged (TreeItem *ti);
609 void emitUpdateQueries (); //!< tell MainWindow to update find results...
610 void emitUpdateLayout ();
613 void updateQueries(VymModel *m);
615 void noteChanged (QModelIndex ix);
616 void newChildObject(QModelIndex ix);
619 MapEditor *mapEditor;
621 QColor defLinkColor; // default color for links
622 QPen defXLinkPen; // default pen for xlinks
623 QString defXLinkStyleBegin; // default style begin
624 QString defXLinkStyleEnd; ; // default style end
625 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
626 LinkableMapObj::Style linkstyle; // default style for links
630 bool setMapLinkStyle (const QString &); // Set style of link
631 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
632 void setMapDefLinkColor(QColor); // default color of links
633 void setMapLinkColorHintInt(); // color of links
634 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
635 void toggleMapLinkColorHint(); // after changing linkStyles
636 void selectMapBackgroundImage();
637 void setMapBackgroundImage(const QString &);
638 void selectMapBackgroundColor();
639 void setMapBackgroundColor(QColor);
640 QColor getMapBackgroundColor();
642 QFont getMapDefaultFont();
643 void setMapDefaultFont (const QFont&);
645 LinkableMapObj::ColorHint getMapLinkColorHint();
646 QColor getMapDefLinkColor();
647 void setMapDefXLinkPen (const QPen &p);
648 QPen getMapDefXLinkPen();
650 void setMapDefXLinkStyleBegin( const QString &s);
651 QString getMapDefXLinkStyleBegin();
652 void setMapDefXLinkStyleEnd ( const QString &s);
653 QString getMapDefXLinkStyleEnd();
655 /*! Move absolutly to (x,y). */
656 void move (const double &x, const double &y);
658 /*! Move relativly to (x,y). */
659 void moveRel (const double &x, const double &y);
661 ////////////////////////////////////////////
662 // Animation **experimental**
663 ////////////////////////////////////////////
665 QTimer *animationTimer;
668 uint animationInterval;
669 int timerId; // animation timer
670 QList <MapObj*> animObjList;// list with animated objects
673 void animate(); //!< Called by timer to animate stuff
675 void startAnimation(BranchObj *bo, const QPointF &v);
676 void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
677 void stopAnimation(MapObj *mo);
678 void stopAllAnimation();
680 ////////////////////////////////////////////
682 ////////////////////////////////////////////
684 /*! \brief Networking states
686 In Network modus we want to switch of saveState, autosave, ...
689 Offline, //!< Offline
690 Client, //!< I am the client and connected to server
691 Server //!< I am the server
695 // Network connections **Experimental**
696 NetState netstate; // offline, client, server
697 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
698 QList <QTcpSocket*> clientList; // List of connected clients
699 quint16 sendCounter; // Increased with every sent command
701 QTcpSocket *clientSocket; // socket of this client
702 QString server; // server address of this client
703 int port; // server port of this client
706 void sendSelection();
710 void connectToServer();
714 void sendData(const QString &s);
716 void displayNetworkError (QAbstractSocket::SocketError);
719 void downloadImage (const QUrl &url, BranchItem *bi=NULL);
721 ////////////////////////////////////////////
723 ////////////////////////////////////////////
725 TreeItem *latestAddedItem; // latest added object, reset on setChanged()
726 QList <uint> selectionHistory;
727 int currentSelection;
728 bool keepSelectionHistory; // If set, selection doesn't change history
731 void updateSelection(QItemSelection ,QItemSelection); // update selection
734 void setSelectionModel(QItemSelectionModel *); // Set common selectionModel
735 QItemSelectionModel* getSelectionModel();
737 void setSelectionBlocked(bool);
738 bool isSelectionBlocked();
740 bool select (const QString &); //! Select by string
741 bool selectID (const QString &); //! select by unique ID (QUuid)
742 bool select (LinkableMapObj *lmo); //! Select by pointer to LMO
743 bool selectToggle (TreeItem *ti); //! Toggle select state
744 bool select (TreeItem *ti ); //! Select by pointer to TreeItem
745 bool select (const QModelIndex &index); //! Select by ModelIndex
747 void unselect (QItemSelection desel);
749 bool canSelectPrevious();
750 bool selectPrevious();
751 bool canSelectNext();
753 void resetSelectionHistory();
754 void appendSelection();
756 void emitShowSelection(); //!< Show selection in all views
758 void showSelection();
761 bool selectFirstBranch();
762 bool selectLastBranch();
763 bool selectLastSelectedBranch();
764 bool selectLastImage();
768 TreeItem::Type selectionType();
769 LinkableMapObj* getSelectedLMO();
770 BranchObj* getSelectedBranchObj();
771 BranchItem* getSelectedBranch();
772 QList <BranchItem*> getSelectedBranches();
773 ImageItem* getSelectedImage();
774 Task *getSelectedTask();
775 XLinkItem* getSelectedXLinkItem();
776 Link* getSelectedXLink();
777 AttributeItem* getSelectedAttribute();
778 TreeItem* getSelectedItem();
779 QList <TreeItem*> getSelectedItems();
780 QModelIndex getSelectedIndex();
781 QList <uint> getSelectedIDs();
782 bool isSelected(TreeItem*);
783 QString getSelectString ();
784 QString getSelectString (LinkableMapObj *lmo);
785 QString getSelectString (TreeItem *item);
786 QString getSelectString (BranchItem *item);
787 QString getSelectString (const uint &i);
791 void selectionChanged(const QItemSelection &newsel, const QItemSelection &oldsel);
794 void emitSelectionChanged(const QItemSelection &oldsel);
795 void emitSelectionChanged();
796 void selectMapLinkColor();
797 void selectMapSelectionColor();
799 void setSelectionColorInt(QColor);
800 QItemSelectionModel *selModel;
801 QString lastSelectString;
802 bool selectionBlocked; //! Used to block changes of selection while editing a heading
805 void setSelectionColor(QColor);
806 QColor getSelectionColor();
808 ////////////////////////////////////////////
810 ////////////////////////////////////////////
812 SlideModel* getSlideModel();
814 SlideItem* addSlide ();
815 void deleteSlide (SlideItem *si);
816 void deleteSlide (int n);
817 void relinkSlide (SlideItem *si, int pos);
818 void moveSlideUp( int n=-1);
819 void moveSlideDown( int n=-1);
820 SlideItem *findSlideID (uint id);
822 void updateSlideSelection (QItemSelection ,QItemSelection);
824 SlideModel* slideModel;
825 bool blockSlideSelection;