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
182 void resetHistory(); //!< Initialize history
184 /*! \brief Save the current changes in map
186 Two commands and selections are saved:
188 - undocommand and undoselection to undo the change
189 - redocommand and redoselection to redo the action after an undo
191 Additionally a comment is logged.
195 const SaveMode& savemode,
196 const QString &undoSelection,
197 const QString &undoCommand,
198 const QString &redoSelection,
199 const QString &redoCommand,
200 const QString &comment,
201 TreeItem *saveSelection);
202 /*! Overloaded for convenience */
203 void saveStateChangingPart(
204 TreeItem *undoSelection,
205 TreeItem* redoSelection,
206 const QString &redoCommand,
207 const QString &comment);
208 /*! Overloaded for convenience */
209 void saveStateRemovingPart(
210 TreeItem *redoSelection,
211 const QString &comment);
212 /*! Overloaded for convenience */
214 TreeItem *undoSelection,
215 const QString &undoCommand,
216 TreeItem *redoSelection,
217 const QString &redoCommand,
218 const QString &comment);
219 /*! Overloaded for convenience */
221 const QString &undoSelection,
222 const QString &undoCommand,
223 const QString &redoSelection,
224 const QString &redoCommand,
225 const QString &comment) ;
227 const QString &undoCommand,
228 const QString &redoCommand,
229 const QString &comment) ;
232 ////////////////////////////////////////////
234 ////////////////////////////////////////////
236 QGraphicsScene *mapScene;
238 void setScene(QGraphicsScene *s);
239 QGraphicsScene *getScene();
241 TreeItem* findBySelectString (QString s);
242 TreeItem* findID (const uint &i); // find MapObj by unique ID
245 ////////////////////////////////////////////
247 ////////////////////////////////////////////
249 void setVersion(const QString &);
250 QString getVersion();
251 void setAuthor (const QString &);
252 QString getAuthor ();
253 void setComment (const QString &);
254 QString getComment ();
258 void setSortFilter (const QString &);
259 QString getSortFilter ();
263 void sortFilterChanged (QString ); //!< Notify editors of new filter
266 void setHeading(const QString &); //!< Set heading of item
267 QString getHeading (); //!< Get heading of item
268 void setNote(const QString &s); //!< Set note text
269 QString getNote(); //!< Get note text
270 void loadNote (const QString &fn); //!< Load note from file
271 void saveNote (const QString &fn); //!< Save note to file
274 BranchItem* findCurrent; // next object in find process
275 BranchItem* findPrevious; // next object in find process
276 bool EOFind; // true, if search failed
279 void findDuplicateURLs(); // find duplicate URLs, testing only so far
280 void findAll (FindResultModel*, QString s, Qt::CaseSensitivity cs); // Search all objects at once, also notes
281 BranchItem* findText(QString s,Qt::CaseSensitivity cs); // Find object, also in note
282 void findReset(); // Reset Search
287 void setURL(const QString &url);
288 QString getURL(); // returns URL of selection or ""
289 QStringList getURLs(bool ignoreScrolled=true); // returns URLs of subtree
292 void setFrameType(const FrameObj::FrameType &);
293 void setFrameType(const QString &);
294 void setFramePenColor (const QColor &);
295 void setFrameBrushColor (const QColor &);
296 void setFramePadding (const int &);
297 void setFrameBorderWidth (const int &);
298 void setIncludeImagesVer(bool);
299 void setIncludeImagesHor(bool);
300 void setHideLinkUnselected (bool);
302 /*! Should object be hidden in exports (clouded)? */
303 void setHideExport(bool);
305 /*! Should object be hidden in exports (clouded)? */
306 void toggleHideExport();
310 void copy(); //!< Copy to clipboard
312 void pasteNoSave(const int &n); //!< paste clipboard to branch
314 void paste(); //!< Paste clipboard to branch and backup
315 void cut(); //!< Cut to clipboard (and copy)
317 bool moveUp(BranchItem *bi); //!< Move branch up without saving state
318 void moveUp(); //!< Move branch up with saving state
319 bool moveDown(BranchItem *bi); //!< Move branch down without saving state
320 void moveDown(); //!< Move branch down
321 void detach(); //!< Detach branch and use as new mapcenter
322 void sortChildren(bool inverse=false); //!< Sort children lexically
324 // The create methods are used to quickly parse a XML file
325 BranchItem* createMapCenter(); //!< Create MapCenter
326 BranchItem* createBranch(BranchItem *dst); //!< Create Branch
327 ImageItem* createImage(BranchItem *dst); //!< Create image
330 bool createLink(Link *l, bool createMO=false); //!< Create XLink
332 AttributeItem* addAttribute();
333 AttributeItem* addAttribute(AttributeItem* );
335 /*! \brief Add new mapcenter
337 Disclaimer: Still experimental, not fully supported yet.
339 BranchItem* addMapCenter(bool saveStateFlag=true);
341 BranchItem* addMapCenter(QPointF absPos);
343 /*! \brief Add new branch
345 Depending on num the new branch is created
347 -3 above selection as child of selections parent
348 -2 as child of selection
349 -1 below selection as child of selections parent
350 0..n insert at a specific position in selections parent
351 (needed for free relinking)
355 BranchItem* addNewBranchInt(BranchItem *dst, int pos); // pos allows to add above/below selection
359 Depending on num the new branch is created
361 0 as child of selection
364 BranchItem* addNewBranch(int pos=0);
365 BranchItem* addNewBranchBefore(); //!< Insert branch between selection and its parent
366 /*! \brief Relink a branch to a new destination dst
367 Relinks branch to dst at branch position pos. There is no saveState
368 here, as for example moveUp or moving in MapEditor have
369 different needs to call saveState
370 Returns true if relinking was successful.
372 bool relinkBranch (BranchItem* branch, BranchItem* dst, int pos =-1);
373 bool relinkImage (ImageItem* image, BranchItem* dst);
376 bool cleaningUpLinks; //!< True while cleaning up to avoid recursion
378 void cleanupLinks(); //!< Delete orphaned XLinkItems
379 void deleteSelection(); //!< Delete selection
380 void deleteKeepChildren(bool saveStateFlag=true); //!< remove branch, but keep children
382 void deleteChildren(); //!< keep branch, but remove children
384 TreeItem* deleteItem(TreeItem*); //!< Delete item and return parent (if parent!= rootItem)
385 void deleteLink (Link*); //!< Remove Link and related LinkItems in TreeModel
386 void clearItem (TreeItem* ti); //!< Remove all children of TreeItem ti
387 bool scrollBranch(BranchItem *);
388 bool unscrollBranch(BranchItem *);
390 void unscrollChildren();
391 void emitExpandAll();
392 void emitExpandOneLevel();
393 void emitCollapseOneLevel();
396 void expandOneLevel();
397 void collapseOneLevel();
400 void toggleStandardFlag (const QString &name, FlagRow *master=NULL);
401 void addFloatImage(const QPixmap &img);
403 void colorBranch(QColor);
404 void colorSubtree(QColor);
405 QColor getCurrentHeadingColor();
408 void editURL(); // edit URL
409 void editLocalURL(); // edit URL to local file
410 void editHeading2URL(); // copy heading to URL
411 void editBugzilla2URL(); // create URL to Bugzilla
412 void getBugzillaData(); // get data from Novell Bugzilla
413 void editFATE2URL(); // create URL to FATE
414 void editVymLink(); // edit link to another map
415 void setVymLink (const QString &); // Set vymLink for selection
416 void deleteVymLink(); // delete link to another map
417 QString getVymLink(); // return path to map
418 QStringList getVymLinks(); // return paths in subtree
419 void followXLink (int);
420 void editXLink (int i=0);
425 ////////////////////////////////////////////
427 ////////////////////////////////////////////
430 /* \brief Process one command and its parameters */
431 QVariant parseAtom (const QString &atom, bool &noError, QString &errorMsg);
433 /* \brief Runs the script */
434 QVariant runScript (const QString &script);
439 ////////////////////////////////////////////
441 ////////////////////////////////////////////
443 TreeItem::HideTmpMode hidemode; // true while exporting to hide some stuff
446 /*! Set or unset temporary hiding of objects during export */
447 void setExportMode (bool);
450 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
453 /*! Export as XTML to directory */
454 void exportXML(QString dir="", bool askForName=true);
456 /*! Export as A&O report text to file */
457 void exportAO (QString fname="",bool askForName=true);
459 /*! Export as ASCII text to file */
460 void exportASCII (QString fname="",bool askForName=true);
462 /*! Export as HTML to directory */
463 void exportHTML(const QString& dir="", bool useDialog=true);
465 /*! Export as OpenOfficeOrg presentation */
466 void exportOOPresentation(const QString &,const QString &);
469 ////////////////////////////////////////////
471 ////////////////////////////////////////////
473 void registerEditor (QWidget *);
474 void unregisterEditor (QWidget *);
476 void setMapZoomFactor (const double &);
479 QPointF contextPos; //!< local position during context menu
481 void setContextPos (QPointF); //!< local position during context menu
482 void unsetContextPos (); //!< forget local position after context menu
484 void updateNoteFlag(); //!< Signal origination in TextEditor
485 void reposition(); //!< Call reposition for all MCOs
486 void setHideTmpMode (TreeItem::HideTmpMode mode);
488 void emitNoteHasChanged (TreeItem *ti);
489 void emitDataHasChanged (TreeItem *ti);
490 void emitUpdateLayout ();
494 void noteHasChanged (QModelIndex ix);
495 void newChildObject(QModelIndex ix);
498 MapEditor *mapEditor;
500 QColor defLinkColor; // default color for links
501 QColor defXLinkColor; // default color for xlinks
502 int defXLinkWidth; // default width for xlinks
503 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
504 LinkableMapObj::Style linkstyle; // default style for links
507 void setMapLinkStyle (const QString &); // Set style of link
508 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
509 void setMapDefLinkColor(QColor); // default color of links
510 void setMapLinkColorHintInt(); // color of links
511 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
512 void toggleMapLinkColorHint(); // after changing linkStyles
513 void selectMapBackgroundImage();
514 void setMapBackgroundImage(const QString &);
515 void selectMapBackgroundColor();
516 void setMapBackgroundColor(QColor);
517 QColor getMapBackgroundColor();
520 LinkableMapObj::ColorHint getMapLinkColorHint();
521 QColor getMapDefLinkColor();
522 void setMapDefXLinkColor(QColor);
523 QColor getMapDefXLinkColor();
524 void setMapDefXLinkWidth (int);
525 int getMapDefXLinkWidth();
527 /*! Move absolutly to (x,y). */
528 void move (const double &x, const double &y);
530 /*! Move relativly to (x,y). */
531 void moveRel (const double &x, const double &y);
533 ////////////////////////////////////////////
534 // Animation **experimental**
535 ////////////////////////////////////////////
537 QTimer *animationTimer;
540 uint animationInterval;
541 int timerId; // animation timer
542 QList <MapObj*> animObjList;// list with animated objects //FIXME-2 should go to MapEditor
545 void animate(); //!< Called by timer to animate stuff
547 void startAnimation(BranchObj *bo, const QPointF &v);
548 void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
549 void stopAnimation(MapObj *mo);
550 void stopAllAnimation();
552 ////////////////////////////////////////////
554 ////////////////////////////////////////////
556 /*! \brief Networking states
558 In Network modus we want to switch of saveState, autosave, ...
561 Offline, //!< Offline
562 Client, //!< I am the client and connected to server
563 Server //!< I am the server
567 // Network connections **Experimental**
568 NetState netstate; // offline, client, server
569 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
570 QList <QTcpSocket*> clientList; // List of connected clients
571 quint16 sendCounter; // Increased with every sent command
573 QTcpSocket *clientSocket; // socket of this client
574 QString server; // server address of this client
575 int port; // server port of this client
580 void sendSelection();
584 void connectToServer();
588 void sendData(const QString &s);
590 void displayNetworkError (QAbstractSocket::SocketError);
592 ////////////////////////////////////////////
594 ////////////////////////////////////////////
597 AdaptorModel *adaptorModel; //FIXME-3
602 ////////////////////////////////////////////
604 ////////////////////////////////////////////
606 TreeItem *latestAddedItem; // latest added object, reset on setChanged()
609 void setSelectionModel(QItemSelectionModel *); // Set common selectionModel
610 QItemSelectionModel* getSelectionModel();
612 void setSelectionBlocked(bool);
613 bool isSelectionBlocked();
615 bool select (); //! select by using common QItemSelectionModel
616 bool select (const QString &); //! Select by string
617 bool select (LinkableMapObj *lmo); //! Select by pointer to LMO
618 bool select (TreeItem *ti ); //! Select by pointer to TreeItem
619 bool select (TreeItem *ti,int i ); //! Select by pointer to TreeItem and index in note
620 bool select (const QModelIndex &index); //! Select by ModelIndex
624 void emitShowSelection(); //!< Show selection in all views
626 void showSelection();
629 bool selectFirstBranch();
630 bool selectLastBranch();
631 bool selectLastSelectedBranch();
632 bool selectLastImage();
636 TreeItem::Type selectionType();
637 LinkableMapObj* getSelectedLMO();
638 BranchObj* getSelectedBranchObj(); // FIXME-3 replace by item...
639 BranchItem* getSelectedBranch();
640 ImageItem* getSelectedImage();
641 AttributeItem* getSelectedAttribute();
642 TreeItem* getSelectedItem();
643 QModelIndex getSelectedIndex();
644 QString getSelectString ();
645 QString getSelectString (LinkableMapObj *lmo);
646 QString getSelectString (TreeItem *item);
647 QString getSelectString (BranchItem *item);
651 void selectionChanged(const QItemSelection &newsel, const QItemSelection &oldsel);
654 void emitSelectionChanged(const QItemSelection &oldsel);
655 void emitSelectionChanged();
656 void selectMapLinkColor();
657 void selectMapSelectionColor();
659 void setSelectionColorInt(QColor);
660 QItemSelectionModel *selModel;
661 QString lastSelectString;
662 bool selectionBlocked; //! Used to block changes of selection while editing a heading
665 void setSelectionColor(QColor);
666 QColor getSelectionColor();