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;
26 class VymModel : public TreeModel {
28 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(); // FIXME-2 still necessary?
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&);// 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.
114 ErrorCode load (QString, const LoadMode &, const FileType& ); // newmap, import/replace selection
117 /*! \brief Save the map to file */
118 ErrorCode save(const SaveMode &);
121 void addMapReplaceInt(const QString & undoSel, const QString & path);
122 bool addMapInsertInt (const QString & path);
123 bool addMapInsertInt (const QString & path, int pos);
125 ImageItem* loadFloatImageInt (BranchItem *dst,QString);
126 void saveFloatImageInt (ImageItem*, const QString &, const QString &);
128 void loadFloatImage ();
129 void saveFloatImage ();
132 void importDirInt(BranchItem *,QDir);
133 void importDirInt(const QString&);
141 ////////////////////////////////////////////
142 // history (undo/redo)
143 ////////////////////////////////////////////
145 bool mapDefault; //!< Flag if map is untouched
146 bool mapChanged; //!< Flag if undo is possible
147 bool mapUnsaved; //!< Flag if map should be saved
149 QString histPath; //!< Path to history file
150 SimpleSettings undoSet; //!< undo/redo commands, saved in histPath
151 int stepsTotal; //!< total number of steps (undos+redos)
152 int curStep; //!< Current step in history (ring buffer)
153 int curClipboard; //!< number of history step, which is the current clipboard
154 int redosAvail; //!< Available number of redo steps
155 int undosAvail; //!< Available number of undo steps
156 bool blockReposition; //!< block while load or undo
157 bool blockSaveState; //!< block while load or undo
159 bool isDefault(); //!< true, if map is still the empty default map
160 void makeDefault(); //!< Reset changelog, declare this as default map
161 bool hasChanged() ; //!< true, if something has changed and is not saved yet
162 void setChanged(); //!< called from TextEditor via LinkableMapObj
164 /*! \brief Get name of object
166 Returns heading of a branch or name of an object for use in comment
169 QString getObjectName(LinkableMapObj*);
170 QString getObjectName(TreeItem*);
172 void redo(); //!< Redo last action
173 bool isRedoAvailable(); //!< True, if redo is available
174 void undo(); //!< Undo last action
175 bool isUndoAvailable(); //!< True, if undo is available
176 void gotoHistoryStep (int); //!< Goto a specifig step in history
179 QString getHistoryPath(); //!< Path to directory containing the history
181 /*! \brief Save the current changes in map
183 Two commands and selections are saved:
185 - undocommand and undoselection to undo the change
186 - redocommand and redoselection to redo the action after an undo
188 Additionally a comment is logged.
192 const SaveMode& savemode,
193 const QString &undoSelection,
194 const QString &undoCommand,
195 const QString &redoSelection,
196 const QString &redoCommand,
197 const QString &comment,
198 TreeItem *saveSelection);
199 /*! Overloaded for convenience */
200 void saveStateChangingPart(
201 TreeItem *undoSelection,
202 TreeItem* redoSelection,
203 const QString &redoCommand,
204 const QString &comment);
205 /*! Overloaded for convenience */
206 void saveStateRemovingPart(
207 TreeItem *redoSelection,
208 const QString &comment);
209 /*! Overloaded for convenience */
211 TreeItem *undoSelection,
212 const QString &undoCommand,
213 TreeItem *redoSelection,
214 const QString &redoCommand,
215 const QString &comment);
216 /*! Overloaded for convenience */
218 const QString &undoSelection,
219 const QString &undoCommand,
220 const QString &redoSelection,
221 const QString &redoCommand,
222 const QString &comment) ;
224 const QString &undoCommand,
225 const QString &redoCommand,
226 const QString &comment) ;
229 ////////////////////////////////////////////
231 ////////////////////////////////////////////
233 QGraphicsScene *mapScene;
235 void setScene(QGraphicsScene *s);
236 QGraphicsScene *getScene();
238 TreeItem* findBySelectString (QString s);
239 TreeItem* findID (const uint &i); // find MapObj by unique ID
242 ////////////////////////////////////////////
244 ////////////////////////////////////////////
246 void setVersion(const QString &);
247 QString getVersion();
248 void setAuthor (const QString &);
249 QString getAuthor ();
250 void setComment (const QString &);
251 QString getComment ();
255 void setSortFilter (const QString &);
256 QString getSortFilter ();
260 void sortFilterChanged (QString ); //!< Notify editors of new filter
263 void setHeading(const QString &); //!< Set heading of item
264 QString getHeading (); //!< Get heading of item
265 void setNote(const QString &s); //!< Set note text
266 QString getNote(); //!< Get note text
267 void loadNote (const QString &fn); //!< Load note from file
268 void saveNote (const QString &fn); //!< Save note to file
271 BranchItem* findCurrent; // next object in find process
272 BranchItem* findPrevious; // next object in find process
273 bool EOFind; // true, if search failed
276 void findDuplicateURLs(); // find duplicate URLs, testing only so far
277 void findAll (FindResultModel*, QString s, Qt::CaseSensitivity cs); // Search all objects at once, also notes
278 BranchItem* findText(QString s,Qt::CaseSensitivity cs,QTextCursor &cursor); // Find object, also in note
279 void findReset(); // Reset Search
284 void setURL(const QString &url);
285 QString getURL(); // returns URL of selection or ""
286 QStringList getURLs(bool ignoreScrolled=true); // returns URLs of subtree
289 void setFrameType(const FrameObj::FrameType &);
290 void setFrameType(const QString &);
291 void setFramePenColor (const QColor &);
292 void setFrameBrushColor (const QColor &);
293 void setFramePadding (const int &);
294 void setFrameBorderWidth (const int &);
295 void setIncludeImagesVer(bool);
296 void setIncludeImagesHor(bool);
297 void setHideLinkUnselected (bool);
299 /*! Should object be hidden in exports (clouded)? */
300 void setHideExport(bool);
302 /*! Should object be hidden in exports (clouded)? */
303 void toggleHideExport();
307 void copy(); //!< Copy to clipboard
309 void pasteNoSave(const int &n); //!< paste clipboard to branch
311 void paste(); //!< Paste clipboard to branch and backup
312 void cut(); //!< Cut to clipboard (and copy)
314 bool moveUp(BranchItem *bi); //!< Move branch up without saving state
315 void moveUp(); //!< Move branch up with saving state
316 bool moveDown(BranchItem *bi); //!< Move branch down without saving state
317 void moveDown(); //!< Move branch down
318 void detach(); //!< Detach branch and use as new mapcenter
319 void sortChildren(bool inverse=false); //!< Sort children lexically
321 // The create methods are used to quickly parse a XML file
322 BranchItem* createMapCenter(); //!< Create MapCenter
323 BranchItem* createBranch(BranchItem *dst); //!< Create Branch
324 ImageItem* createImage(BranchItem *dst); //!< Create image
325 XLinkItem* createXLink(BranchItem *dst,bool createMO=false); //!< Create XLink starting at dst
327 AttributeItem* addAttribute();
328 AttributeItem* addAttribute(AttributeItem* );
330 /*! \brief Add new mapcenter
332 Disclaimer: Still experimental, not fully supported yet.
334 BranchItem* addMapCenter();
336 BranchItem* addMapCenter(QPointF absPos);
338 /*! \brief Add new branch
340 Depending on num the new branch is created
342 -3 above selection as child of selections parent
343 -2 as child of selection
344 -1 below selection as child of selections parent
345 0..n insert at a specific position in selections parent
346 (needed for free relinking)
350 BranchItem* addNewBranchInt(BranchItem *dst, int pos); // pos allows to add above/below selection
354 Depending on num the new branch is created
356 0 as child of selection
359 BranchItem* addNewBranch(int pos=0);
360 BranchItem* addNewBranchBefore(); //!< Insert branch between selection and its parent
361 /*! \brief Relink a branch to a new destination dst
362 Relinks branch to dst at branch position pos. There is no saveState
363 here, as for example moveUp or moving in MapEditor have
364 different needs to call saveState
365 Returns true if relinking was successful.
367 bool relinkBranch (BranchItem* branch, BranchItem* dst, int pos =-1);
368 bool relinkImage (ImageItem* image, BranchItem* dst);
370 void deleteSelection(); //!< Delete selection
371 void deleteKeepChildren(); //!< remove branch, but keep children
372 void deleteChildren(); //!< keep branch, but remove children
374 TreeItem* deleteItem(TreeItem*); //!< Delete item and return parent (if parent!= rootItem)
375 void clearItem (TreeItem* ti); //!< Remove all children of TreeItem ti
376 bool scrollBranch(BranchItem *);
377 bool unscrollBranch(BranchItem *);
380 void unscrollChildren();
381 void emitExpandAll();
382 void emitExpandOneLevel();
383 void emitCollapseOneLevel();
386 void expandOneLevel();
387 void collapseOneLevel();
390 void toggleStandardFlag (const QString &name, FlagRow *master=NULL);
391 void addFloatImage(const QPixmap &img);
393 void colorBranch(QColor);
394 void colorSubtree(QColor);
395 QColor getCurrentHeadingColor();
398 void editURL(); // edit URL
399 void editLocalURL(); // edit URL to local file
400 void editHeading2URL(); // copy heading to URL
401 void editBugzilla2URL(); // create URL to Bugzilla
402 void getBugzillaData(); // get data from Novell Bugzilla
403 void editFATE2URL(); // create URL to FATE
404 void editVymLink(); // edit link to another map
405 void setVymLink (const QString &); // Set vymLink for selection
406 void deleteVymLink(); // delete link to another map
407 QString getVymLink(); // return path to map
408 QStringList getVymLinks(); // return paths in subtree
409 void followXLink (int);
410 void editXLink (int);
415 ////////////////////////////////////////////
417 ////////////////////////////////////////////
420 /* \brief Process one command and its parameters */
421 QVariant parseAtom (const QString &atom, bool &noError, QString &errorMsg);
423 /* \brief Runs the script */
424 QVariant runScript (const QString &script);
429 ////////////////////////////////////////////
431 ////////////////////////////////////////////
433 TreeItem::HideTmpMode hidemode; // true while exporting to hide some stuff
436 /*! Set or unset temporary hiding of objects during export */
437 void setExportMode (bool);
440 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
443 /*! Export as XTML to directory */
444 void exportXML(QString dir="", bool askForName=true);
446 /*! Export as A&O report text to file */
447 void exportAO (QString fname="",bool askForName=true);
449 /*! Export as ASCII text to file */
450 void exportASCII (QString fname="",bool askForName=true);
452 /*! Export as HTML to directory */
453 void exportHTML(const QString& dir="", bool useDialog=true);
454 void exportXHTML(const QString& dir="", bool askForName=true);
456 /*! Export as OpenOfficeOrg presentation */
457 void exportOOPresentation(const QString &,const QString &);
460 ////////////////////////////////////////////
462 ////////////////////////////////////////////
464 void registerEditor (QWidget *);
465 void unregisterEditor (QWidget *);
467 void setMapZoomFactor (const double &);
470 QPointF contextPos; //!< local position during context menu
472 void setContextPos (QPointF); //!< local position during context menu
473 void unsetContextPos (); //!< forget local position after context menu
475 void updateNoteFlag(); //!< Signal origination in TextEditor
476 void reposition(); //!< Call reposition for all MCOs
477 void setHideTmpMode (TreeItem::HideTmpMode mode);
479 void emitNoteHasChanged (TreeItem *ti);
480 void emitDataHasChanged (TreeItem *ti);
481 void emitUpdateLayout ();
485 void noteHasChanged (QModelIndex ix);
486 void newChildObject(QModelIndex ix);
489 MapEditor *mapEditor;
491 QColor defLinkColor; // default color for links
492 QColor defXLinkColor; // default color for xlinks
493 int defXLinkWidth; // default width for xlinks
494 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
495 LinkableMapObj::Style linkstyle; // default style for links
498 void setMapLinkStyle (const QString &); // Set style of link
499 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
500 void setMapDefLinkColor(QColor); // default color of links
501 void setMapLinkColorHintInt(); // color of links
502 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
503 void toggleMapLinkColorHint(); // after changing linkStyles
504 void selectMapBackgroundImage();
505 void setMapBackgroundImage(const QString &);
506 void selectMapBackgroundColor();
507 void setMapBackgroundColor(QColor);
508 QColor getMapBackgroundColor();
511 LinkableMapObj::ColorHint getMapLinkColorHint();
512 QColor getMapDefLinkColor();
513 void setMapDefXLinkColor(QColor);
514 QColor getMapDefXLinkColor();
515 void setMapDefXLinkWidth (int);
516 int getMapDefXLinkWidth();
518 /*! Move absolutly to (x,y). */
519 void move (const double &x, const double &y);
521 /*! Move relativly to (x,y). */
522 void moveRel (const double &x, const double &y);
524 ////////////////////////////////////////////
525 // Animation **experimental**
526 ////////////////////////////////////////////
528 QTimer *animationTimer;
531 uint animationInterval;
532 int timerId; // animation timer
533 QList <MapObj*> animObjList;// list with animated objects //FIXME-2 should go to MapEditor
536 void animate(); //!< Called by timer to animate stuff
538 void startAnimation(BranchObj *bo, const QPointF &v);
539 void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
540 void stopAnimation(MapObj *mo);
542 ////////////////////////////////////////////
544 ////////////////////////////////////////////
546 /*! \brief Networking states
548 In Network modus we want to switch of saveState, autosave, ...
551 Offline, //!< Offline
552 Client, //!< I am the client and connected to server
553 Server //!< I am the server
557 // Network connections **Experimental**
558 NetState netstate; // offline, client, server
559 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
560 QList <QTcpSocket*> clientList; // List of connected clients
561 quint16 sendCounter; // Increased with every sent command
563 QTcpSocket *clientSocket; // socket of this client
564 QString server; // server address of this client
565 int port; // server port of this client
570 void sendSelection();
574 void connectToServer();
578 void sendData(const QString &s);
580 void displayNetworkError (QAbstractSocket::SocketError);
582 ////////////////////////////////////////////
584 ////////////////////////////////////////////
587 AdaptorModel *adaptorModel; //FIXME-3
592 ////////////////////////////////////////////
594 ////////////////////////////////////////////
596 TreeItem *latestAddedItem; // latest added object, reset on setChanged()
599 void setSelectionModel(QItemSelectionModel *); // Set common selectionModel
600 QItemSelectionModel* getSelectionModel();
602 void setSelectionBlocked(bool);
603 bool isSelectionBlocked();
605 bool select (); //! select by using common QItemSelectionModel
606 bool select (const QString &); //! Select by string
607 bool select (LinkableMapObj *lmo); //! Select by pointer to LMO
608 bool select (TreeItem *ti ); //! Select by pointer to TreeItem
609 bool select (const QModelIndex &index); //! Select by ModelIndex
613 void emitShowSelection(); //!< Show selection in all views
615 void showSelection();
618 bool selectFirstBranch();
619 bool selectLastBranch();
620 bool selectLastSelectedBranch();
624 TreeItem::Type selectionType();
625 LinkableMapObj* getSelectedLMO();
626 BranchObj* getSelectedBranchObj(); // FIXME-3 replace by item...
627 BranchItem* getSelectedBranch();
628 ImageItem* getSelectedImage();
629 AttributeItem* getSelectedAttribute();
630 TreeItem* getSelectedItem();
631 QModelIndex getSelectedIndex();
632 QString getSelectString ();
633 QString getSelectString (LinkableMapObj *lmo);
634 QString getSelectString (TreeItem *item);
638 void selectionChanged(const QItemSelection &newsel, const QItemSelection &oldsel);
641 void emitSelectionChanged(const QItemSelection &oldsel);
642 void emitSelectionChanged();
643 void selectMapLinkColor();
644 void selectMapSelectionColor();
646 void setSelectionColorInt(QColor);
647 QItemSelectionModel *selModel;
648 QString lastSelectString;
649 bool selectionBlocked; //! Used to block changes of selection while editing a heading
652 void setSelectionColor(QColor);
653 QColor getSelectionColor();