4 #include <QGraphicsScene>
7 #include <QtDBus/QDBusAbstractAdaptor>
8 #include <QtDBus/QDBusVariant>
10 #include <QTextCursor>
12 #include "adaptormodel.h"
14 #include "imageitem.h"
15 #include "mapeditor.h"
18 #include "treemodel.h"
22 class FindResultModel;
27 class VymModel : public TreeModel {
29 Q_CLASSINFO("D-Bus Interface", "org.insilmaril.vym.VymModel-h")
31 ////////////////////////////////////////////
32 // General housekeeping
33 ////////////////////////////////////////////
35 QString version; //!< version string saved in vym file
40 static uint idLast; //! the last used unique ID
48 void makeTmpDirectories(); //!< create temporary directories e.g. for history
50 MapEditor* getMapEditor();
51 uint getID(); //! Return unique ID of model
53 bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview
55 void updateActions(); //!< Update buttons in mainwindow
58 ////////////////////////////////////////////
60 ////////////////////////////////////////////
63 bool zipped; // should map be zipped
64 static int mapNum; // unique number for model used in save/undo
65 FileType fileType; // type of file, e.g. vym, freemind...
66 QString fileName; // short name of file (for tab)
67 QString filePath; // path to file which will be saved
68 QString fileDir; // dir where file is saved
69 QString destPath; // path to .vym file (needed for vymlinks)
70 QString mapName; // fileName without ".vym"
72 QString tmpMapDir; // tmp directory with undo history
74 QTimer *autosaveTimer;
75 QTimer *fileChangedTimer;
76 QDateTime fileChangedTime;
79 /*! This function saves all information of the map to disc.
80 saveToDir also calls the functions for all BranchObj and other objects in the map.
81 The structure of the map itself is returned as QString and passed back to Main,
82 where saveToDir is called initially
84 QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel);
86 /*! Save all data in tree*/
87 QString saveTreeToDir (const QString&,const QString&,const QPointF&,QList <Link*> &tmpLinks);// Save data recursivly to tempdir
90 /*! \brief Sets filepath, filename and mapname
92 If the filepath is "/home/tux/map.xml", then the filename will be set
93 to map.xml. The destname is needed for vymLinks, pointing to another map.
94 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
98 /*! \brief Set File path
100 The destname is needed to construct the references between maps
102 void setFilePath (QString filepath,QString destname);
103 void setFilePath (QString); //!< Overloaded for convenience
104 QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml"
105 QString getFileName (); //!< e.g. "map.xml"
106 QString getMapName (); //!< e.g. "map"
107 QString getDestPath (); //!< e.g. "/home/tux/map.vym"
111 The data is read from file. Depending on LoadMode the current
112 selection gets replaced by data or the data is appended.
116 const LoadMode &lmode=NewMap, //!< New map, replace or add to selection
117 bool saveStateFlag=true, //!< If called internally for history, don't save
118 const FileType &ftype=VymMap, //!< VymMap or FreeMind
119 int pos=-1 //!< Optionally tell position where to add data
123 /*! \brief Save the map to file */
124 ErrorCode save(const SaveMode &);
127 ImageItem* loadFloatImageInt (BranchItem *dst,QString);
128 void saveFloatImageInt (ImageItem*, const QString &, const QString &);
130 void loadFloatImage ();
131 void saveFloatImage ();
134 void importDirInt(BranchItem *,QDir);
135 void importDirInt(const QString&);
143 ////////////////////////////////////////////
144 // history (undo/redo)
145 ////////////////////////////////////////////
147 bool mapDefault; //!< Flag if map is untouched
148 bool mapChanged; //!< Flag if undo is possible
149 bool mapUnsaved; //!< Flag if map should be saved
151 QString histPath; //!< Path to history file
152 SimpleSettings undoSet; //!< undo/redo commands, saved in histPath
153 int stepsTotal; //!< total number of steps (undos+redos)
154 int curStep; //!< Current step in history (ring buffer)
155 int curClipboard; //!< number of history step, which is the current clipboard
156 int redosAvail; //!< Available number of redo steps
157 int undosAvail; //!< Available number of undo steps
158 bool blockReposition; //!< block while load or undo
159 bool blockSaveState; //!< block while load or undo
161 bool isDefault(); //!< true, if map is still the empty default map
162 void makeDefault(); //!< Reset changelog, declare this as default map
163 bool hasChanged() ; //!< true, if something has changed and is not saved yet
164 void setChanged(); //!< called from TextEditor via LinkableMapObj
166 /*! \brief Get name of object
168 Returns heading of a branch or name of an object for use in comment
171 QString getObjectName(LinkableMapObj*);
172 QString getObjectName(TreeItem*);
174 void redo(); //!< Redo last action
175 bool isRedoAvailable(); //!< True, if redo is available
176 void undo(); //!< Undo last action
177 bool isUndoAvailable(); //!< True, if undo is available
178 void gotoHistoryStep (int); //!< Goto a specifig step in history
181 QString getHistoryPath(); //!< Path to directory containing the history
183 /*! \brief Save the current changes in map
185 Two commands and selections are saved:
187 - undocommand and undoselection to undo the change
188 - redocommand and redoselection to redo the action after an undo
190 Additionally a comment is logged.
194 const SaveMode& savemode,
195 const QString &undoSelection,
196 const QString &undoCommand,
197 const QString &redoSelection,
198 const QString &redoCommand,
199 const QString &comment,
200 TreeItem *saveSelection);
201 /*! Overloaded for convenience */
202 void saveStateChangingPart(
203 TreeItem *undoSelection,
204 TreeItem* redoSelection,
205 const QString &redoCommand,
206 const QString &comment);
207 /*! Overloaded for convenience */
208 void saveStateRemovingPart(
209 TreeItem *redoSelection,
210 const QString &comment);
211 /*! Overloaded for convenience */
213 TreeItem *undoSelection,
214 const QString &undoCommand,
215 TreeItem *redoSelection,
216 const QString &redoCommand,
217 const QString &comment);
218 /*! Overloaded for convenience */
220 const QString &undoSelection,
221 const QString &undoCommand,
222 const QString &redoSelection,
223 const QString &redoCommand,
224 const QString &comment) ;
226 const QString &undoCommand,
227 const QString &redoCommand,
228 const QString &comment) ;
231 ////////////////////////////////////////////
233 ////////////////////////////////////////////
235 QGraphicsScene *mapScene;
237 void setScene(QGraphicsScene *s);
238 QGraphicsScene *getScene();
240 TreeItem* findBySelectString (QString s);
241 TreeItem* findID (const uint &i); // find MapObj by unique ID
244 ////////////////////////////////////////////
246 ////////////////////////////////////////////
248 void setVersion(const QString &);
249 QString getVersion();
250 void setAuthor (const QString &);
251 QString getAuthor ();
252 void setComment (const QString &);
253 QString getComment ();
257 void setSortFilter (const QString &);
258 QString getSortFilter ();
262 void sortFilterChanged (QString ); //!< Notify editors of new filter
265 void setHeading(const QString &); //!< Set heading of item
266 QString getHeading (); //!< Get heading of item
267 void setNote(const QString &s); //!< Set note text
268 QString getNote(); //!< Get note text
269 void loadNote (const QString &fn); //!< Load note from file
270 void saveNote (const QString &fn); //!< Save note to file
273 BranchItem* findCurrent; // next object in find process
274 BranchItem* findPrevious; // next object in find process
275 bool EOFind; // true, if search failed
278 void findDuplicateURLs(); // find duplicate URLs, testing only so far
279 void findAll (FindResultModel*, QString s, Qt::CaseSensitivity cs); // Search all objects at once, also notes
280 BranchItem* findText(QString s,Qt::CaseSensitivity cs); // Find object, also in note
281 void findReset(); // Reset Search
286 void setURL(const QString &url);
287 QString getURL(); // returns URL of selection or ""
288 QStringList getURLs(bool ignoreScrolled=true); // returns URLs of subtree
291 void setFrameType(const FrameObj::FrameType &);
292 void setFrameType(const QString &);
293 void setFramePenColor (const QColor &);
294 void setFrameBrushColor (const QColor &);
295 void setFramePadding (const int &);
296 void setFrameBorderWidth (const int &);
297 void setIncludeImagesVer(bool);
298 void setIncludeImagesHor(bool);
299 void setHideLinkUnselected (bool);
301 /*! Should object be hidden in exports (clouded)? */
302 void setHideExport(bool);
304 /*! Should object be hidden in exports (clouded)? */
305 void toggleHideExport();
309 void copy(); //!< Copy to clipboard
311 void pasteNoSave(const int &n); //!< paste clipboard to branch
313 void paste(); //!< Paste clipboard to branch and backup
314 void cut(); //!< Cut to clipboard (and copy)
316 bool moveUp(BranchItem *bi); //!< Move branch up without saving state
317 void moveUp(); //!< Move branch up with saving state
318 bool moveDown(BranchItem *bi); //!< Move branch down without saving state
319 void moveDown(); //!< Move branch down
320 void detach(); //!< Detach branch and use as new mapcenter
321 void sortChildren(bool inverse=false); //!< Sort children lexically
323 // The create methods are used to quickly parse a XML file
324 BranchItem* createMapCenter(); //!< Create MapCenter
325 BranchItem* createBranch(BranchItem *dst); //!< Create Branch
326 ImageItem* createImage(BranchItem *dst); //!< Create image
329 bool createLink(Link *l, bool createMO=false); //!< Create XLink
331 AttributeItem* addAttribute();
332 AttributeItem* addAttribute(AttributeItem* );
334 /*! \brief Add new mapcenter
336 Disclaimer: Still experimental, not fully supported yet.
338 BranchItem* addMapCenter();
340 BranchItem* addMapCenter(QPointF absPos);
342 /*! \brief Add new branch
344 Depending on num the new branch is created
346 -3 above selection as child of selections parent
347 -2 as child of selection
348 -1 below selection as child of selections parent
349 0..n insert at a specific position in selections parent
350 (needed for free relinking)
354 BranchItem* addNewBranchInt(BranchItem *dst, int pos); // pos allows to add above/below selection
358 Depending on num the new branch is created
360 0 as child of selection
363 BranchItem* addNewBranch(int pos=0);
364 BranchItem* addNewBranchBefore(); //!< Insert branch between selection and its parent
365 /*! \brief Relink a branch to a new destination dst
366 Relinks branch to dst at branch position pos. There is no saveState
367 here, as for example moveUp or moving in MapEditor have
368 different needs to call saveState
369 Returns true if relinking was successful.
371 bool relinkBranch (BranchItem* branch, BranchItem* dst, int pos =-1);
372 bool relinkImage (ImageItem* image, BranchItem* dst);
375 bool cleaningUpLinks; //!< True while cleaning up to avoid recursion
377 void cleanupLinks(); //!< Delete orphaned XLinkItems
378 void deleteSelection(); //!< Delete selection
379 void deleteKeepChildren(bool saveStateFlag=true); //!< remove branch, but keep children
381 void deleteChildren(); //!< keep branch, but remove children
383 TreeItem* deleteItem(TreeItem*); //!< Delete item and return parent (if parent!= rootItem)
384 void deleteLink (Link*); //!< Remove Link and related LinkItems in TreeModel
385 void clearItem (TreeItem* ti); //!< Remove all children of TreeItem ti
386 bool scrollBranch(BranchItem *);
387 bool unscrollBranch(BranchItem *);
389 void unscrollChildren();
390 void emitExpandAll();
391 void emitExpandOneLevel();
392 void emitCollapseOneLevel();
395 void expandOneLevel();
396 void collapseOneLevel();
399 void toggleStandardFlag (const QString &name, FlagRow *master=NULL);
400 void addFloatImage(const QPixmap &img);
402 void colorBranch(QColor);
403 void colorSubtree(QColor);
404 QColor getCurrentHeadingColor();
407 void editURL(); // edit URL
408 void editLocalURL(); // edit URL to local file
409 void editHeading2URL(); // copy heading to URL
410 void editBugzilla2URL(); // create URL to Bugzilla
411 void getBugzillaData(); // get data from Novell Bugzilla
412 void editFATE2URL(); // create URL to FATE
413 void editVymLink(); // edit link to another map
414 void setVymLink (const QString &); // Set vymLink for selection
415 void deleteVymLink(); // delete link to another map
416 QString getVymLink(); // return path to map
417 QStringList getVymLinks(); // return paths in subtree
418 void followXLink (int);
419 void editXLink (int i=0);
424 ////////////////////////////////////////////
426 ////////////////////////////////////////////
429 /* \brief Process one command and its parameters */
430 QVariant parseAtom (const QString &atom, bool &noError, QString &errorMsg);
432 /* \brief Runs the script */
433 QVariant runScript (const QString &script);
438 ////////////////////////////////////////////
440 ////////////////////////////////////////////
442 TreeItem::HideTmpMode hidemode; // true while exporting to hide some stuff
445 /*! Set or unset temporary hiding of objects during export */
446 void setExportMode (bool);
449 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
452 /*! Export as XTML to directory */
453 void exportXML(QString dir="", bool askForName=true);
455 /*! Export as A&O report text to file */
456 void exportAO (QString fname="",bool askForName=true);
458 /*! Export as ASCII text to file */
459 void exportASCII (QString fname="",bool askForName=true);
461 /*! Export as HTML to directory */
462 void exportHTML(const QString& dir="", bool useDialog=true);
464 /*! Export as OpenOfficeOrg presentation */
465 void exportOOPresentation(const QString &,const QString &);
468 ////////////////////////////////////////////
470 ////////////////////////////////////////////
472 void registerEditor (QWidget *);
473 void unregisterEditor (QWidget *);
475 void setMapZoomFactor (const double &);
478 QPointF contextPos; //!< local position during context menu
480 void setContextPos (QPointF); //!< local position during context menu
481 void unsetContextPos (); //!< forget local position after context menu
483 void updateNoteFlag(); //!< Signal origination in TextEditor
484 void reposition(); //!< Call reposition for all MCOs
485 void setHideTmpMode (TreeItem::HideTmpMode mode);
487 void emitNoteHasChanged (TreeItem *ti);
488 void emitDataHasChanged (TreeItem *ti);
489 void emitUpdateLayout ();
493 void noteHasChanged (QModelIndex ix);
494 void newChildObject(QModelIndex ix);
497 MapEditor *mapEditor;
499 QColor defLinkColor; // default color for links
500 QColor defXLinkColor; // default color for xlinks
501 int defXLinkWidth; // default width for xlinks
502 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
503 LinkableMapObj::Style linkstyle; // default style for links
506 void setMapLinkStyle (const QString &); // Set style of link
507 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
508 void setMapDefLinkColor(QColor); // default color of links
509 void setMapLinkColorHintInt(); // color of links
510 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
511 void toggleMapLinkColorHint(); // after changing linkStyles
512 void selectMapBackgroundImage();
513 void setMapBackgroundImage(const QString &);
514 void selectMapBackgroundColor();
515 void setMapBackgroundColor(QColor);
516 QColor getMapBackgroundColor();
519 LinkableMapObj::ColorHint getMapLinkColorHint();
520 QColor getMapDefLinkColor();
521 void setMapDefXLinkColor(QColor);
522 QColor getMapDefXLinkColor();
523 void setMapDefXLinkWidth (int);
524 int getMapDefXLinkWidth();
526 /*! Move absolutly to (x,y). */
527 void move (const double &x, const double &y);
529 /*! Move relativly to (x,y). */
530 void moveRel (const double &x, const double &y);
532 ////////////////////////////////////////////
533 // Animation **experimental**
534 ////////////////////////////////////////////
536 QTimer *animationTimer;
539 uint animationInterval;
540 int timerId; // animation timer
541 QList <MapObj*> animObjList;// list with animated objects //FIXME-2 should go to MapEditor
544 void animate(); //!< Called by timer to animate stuff
546 void startAnimation(BranchObj *bo, const QPointF &v);
547 void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
548 void stopAnimation(MapObj *mo);
549 void stopAllAnimation();
551 ////////////////////////////////////////////
553 ////////////////////////////////////////////
555 /*! \brief Networking states
557 In Network modus we want to switch of saveState, autosave, ...
560 Offline, //!< Offline
561 Client, //!< I am the client and connected to server
562 Server //!< I am the server
566 // Network connections **Experimental**
567 NetState netstate; // offline, client, server
568 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
569 QList <QTcpSocket*> clientList; // List of connected clients
570 quint16 sendCounter; // Increased with every sent command
572 QTcpSocket *clientSocket; // socket of this client
573 QString server; // server address of this client
574 int port; // server port of this client
579 void sendSelection();
583 void connectToServer();
587 void sendData(const QString &s);
589 void displayNetworkError (QAbstractSocket::SocketError);
591 ////////////////////////////////////////////
593 ////////////////////////////////////////////
596 AdaptorModel *adaptorModel; //FIXME-3
601 ////////////////////////////////////////////
603 ////////////////////////////////////////////
605 TreeItem *latestAddedItem; // latest added object, reset on setChanged()
608 void setSelectionModel(QItemSelectionModel *); // Set common selectionModel
609 QItemSelectionModel* getSelectionModel();
611 void setSelectionBlocked(bool);
612 bool isSelectionBlocked();
614 bool select (); //! select by using common QItemSelectionModel
615 bool select (const QString &); //! Select by string
616 bool select (LinkableMapObj *lmo); //! Select by pointer to LMO
617 bool select (TreeItem *ti ); //! Select by pointer to TreeItem
618 bool select (TreeItem *ti,int i ); //! Select by pointer to TreeItem and index in note
619 bool select (const QModelIndex &index); //! Select by ModelIndex
623 void emitShowSelection(); //!< Show selection in all views
625 void showSelection();
628 bool selectFirstBranch();
629 bool selectLastBranch();
630 bool selectLastSelectedBranch();
634 TreeItem::Type selectionType();
635 LinkableMapObj* getSelectedLMO();
636 BranchObj* getSelectedBranchObj(); // FIXME-3 replace by item...
637 BranchItem* getSelectedBranch();
638 ImageItem* getSelectedImage();
639 AttributeItem* getSelectedAttribute();
640 TreeItem* getSelectedItem();
641 QModelIndex getSelectedIndex();
642 QString getSelectString ();
643 QString getSelectString (LinkableMapObj *lmo);
644 QString getSelectString (TreeItem *item);
645 QString getSelectString (BranchItem *item);
649 void selectionChanged(const QItemSelection &newsel, const QItemSelection &oldsel);
652 void emitSelectionChanged(const QItemSelection &oldsel);
653 void emitSelectionChanged();
654 void selectMapLinkColor();
655 void selectMapSelectionColor();
657 void setSelectionColorInt(QColor);
658 QItemSelectionModel *selModel;
659 QString lastSelectString;
660 bool selectionBlocked; //! Used to block changes of selection while editing a heading
663 void setSelectionColor(QColor);
664 QColor getSelectionColor();