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")
30 ////////////////////////////////////////////
31 // General housekeeping
32 ////////////////////////////////////////////
34 QString version; //!< version string saved in vym file
39 static uint idLast; //! the last used unique ID
47 void makeTmpDirectories(); //!< create temporary directories e.g. for history
49 MapEditor* getMapEditor(); // FIXME-2 still necessary?
50 uint getID(); //! Return unique ID of model
52 bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview
54 void updateActions(); //!< Update buttons in mainwindow
57 ////////////////////////////////////////////
59 ////////////////////////////////////////////
62 bool zipped; // should map be zipped
63 static int mapNum; // unique number for model used in save/undo
64 FileType fileType; // type of file, e.g. vym, freemind...
65 QString fileName; // short name of file (for tab)
66 QString filePath; // path to file which will be saved
67 QString fileDir; // dir where file is saved
68 QString destPath; // path to .vym file (needed for vymlinks)
69 QString mapName; // fileName without ".vym"
71 QString tmpMapDir; // tmp directory with undo history
73 QTimer *autosaveTimer;
74 QTimer *fileChangedTimer;
75 QDateTime fileChangedTime;
78 /*! This function saves all information of the map to disc.
79 saveToDir also calls the functions for all BranchObj and other objects in the map.
80 The structure of the map itself is returned as QString and passed back to Main,
81 where saveToDir is called initially
83 QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel);
85 /*! Save all data in tree*/
86 QString saveTreeToDir (const QString&,const QString&,const QPointF&);// Save data recursivly to tempdir
89 /*! \brief Sets filepath, filename and mapname
91 If the filepath is "/home/tux/map.xml", then the filename will be set
92 to map.xml. The destname is needed for vymLinks, pointing to another map.
93 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
97 /*! \brief Set File path
99 The destname is needed to construct the references between maps
101 void setFilePath (QString filepath,QString destname);
102 void setFilePath (QString); //!< Overloaded for convenience
103 QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml"
104 QString getFileName (); //!< e.g. "map.xml"
105 QString getMapName (); //!< e.g. "map"
106 QString getDestPath (); //!< e.g. "/home/tux/map.vym"
110 The data is read from file. Depending on LoadMode the current
111 selection gets replaced by data or the data is appended.
113 ErrorCode load (QString, const LoadMode &, const FileType& ); // newmap, import/replace selection
116 /*! \brief Save the map to file */
117 ErrorCode save(const SaveMode &);
120 void addMapReplaceInt(const QString & undoSel, const QString & path);
121 bool addMapInsertInt (const QString & path);
122 bool addMapInsertInt (const QString & path, int pos);
124 ImageItem* loadFloatImageInt (BranchItem *dst,QString);
125 void saveFloatImageInt (ImageItem*, const QString &, const QString &);
127 void loadFloatImage ();
128 void saveFloatImage ();
131 void importDirInt(BranchItem *,QDir);
132 void importDirInt(const QString&);
140 ////////////////////////////////////////////
141 // history (undo/redo)
142 ////////////////////////////////////////////
144 bool mapDefault; //!< Flag if map is untouched
145 bool mapChanged; //!< Flag if undo is possible
146 bool mapUnsaved; //!< Flag if map should be saved
148 QString histPath; //!< Path to history file
149 SimpleSettings undoSet; //!< undo/redo commands, saved in histPath
150 int stepsTotal; //!< total number of steps (undos+redos)
151 int curStep; //!< Current step in history (ring buffer)
152 int curClipboard; //!< number of history step, which is the current clipboard
153 int redosAvail; //!< Available number of redo steps
154 int undosAvail; //!< Available number of undo steps
155 bool blockReposition; //!< block while load or undo
156 bool blockSaveState; //!< block while load or undo
158 bool isDefault(); //!< true, if map is still the empty default map
159 void makeDefault(); //!< Reset changelog, declare this as default map
160 bool hasChanged() ; //!< true, if something has changed and is not saved yet
161 void setChanged(); //!< called from TextEditor via LinkableMapObj
163 /*! \brief Get name of object
165 Returns heading of a branch or name of an object for use in comment
168 QString getObjectName(LinkableMapObj*);
169 QString getObjectName(TreeItem*);
171 void redo(); //!< Redo last action
172 bool isRedoAvailable(); //!< True, if redo is available
173 void undo(); //!< Undo last action
174 bool isUndoAvailable(); //!< True, if undo is available
175 void gotoHistoryStep (int); //!< Goto a specifig step in history
178 QString getHistoryPath(); //!< Path to directory containing the history
180 /*! \brief Save the current changes in map
182 Two commands and selections are saved:
184 - undocommand and undoselection to undo the change
185 - redocommand and redoselection to redo the action after an undo
187 Additionally a comment is logged.
191 const SaveMode& savemode,
192 const QString &undoSelection,
193 const QString &undoCommand,
194 const QString &redoSelection,
195 const QString &redoCommand,
196 const QString &comment,
197 TreeItem *saveSelection);
198 /*! Overloaded for convenience */
199 void saveStateChangingPart(
200 TreeItem *undoSelection,
201 TreeItem* redoSelection,
202 const QString &redoCommand,
203 const QString &comment);
204 /*! Overloaded for convenience */
205 void saveStateRemovingPart(
206 TreeItem *redoSelection,
207 const QString &comment);
208 /*! Overloaded for convenience */
210 TreeItem *undoSelection,
211 const QString &undoCommand,
212 TreeItem *redoSelection,
213 const QString &redoCommand,
214 const QString &comment);
215 /*! Overloaded for convenience */
217 const QString &undoSelection,
218 const QString &undoCommand,
219 const QString &redoSelection,
220 const QString &redoCommand,
221 const QString &comment) ;
223 const QString &undoCommand,
224 const QString &redoCommand,
225 const QString &comment) ;
228 ////////////////////////////////////////////
230 ////////////////////////////////////////////
232 QGraphicsScene *mapScene;
234 void setScene(QGraphicsScene *s);
235 QGraphicsScene *getScene();
237 TreeItem* findBySelectString (QString s);
238 TreeItem* findID (const uint &i); // find MapObj by unique ID
241 ////////////////////////////////////////////
243 ////////////////////////////////////////////
245 void setVersion(const QString &);
246 QString getVersion();
247 void setAuthor (const QString &);
248 QString getAuthor ();
249 void setComment (const QString &);
250 QString getComment ();
254 void setSortFilter (const QString &);
255 QString getSortFilter ();
259 void sortFilterChanged (QString ); //!< Notify editors of new filter
262 void setHeading(const QString &); //!< Set heading of item
263 QString getHeading (); //!< Get heading of item
264 void setNote(const QString &s); //!< Set note text
265 QString getNote(); //!< Get note text
266 void loadNote (const QString &fn); //!< Load note from file
267 void saveNote (const QString &fn); //!< Save note to file
270 BranchItem* findCurrent; // next object in find process
271 BranchItem* findPrevious; // next object in find process
272 bool EOFind; // true, if search failed
275 void findDuplicateURLs(); // find duplicate URLs, testing only so far
276 void findAll (FindResultModel*, QString s, Qt::CaseSensitivity cs); // Search all objects at once, also notes
277 BranchItem* findText(QString s,Qt::CaseSensitivity cs); // Find object, also in note
278 void findReset(); // Reset Search
283 void setURL(const QString &url);
284 QString getURL(); // returns URL of selection or ""
285 QStringList getURLs(bool ignoreScrolled=true); // returns URLs of subtree
288 void setFrameType(const FrameObj::FrameType &);
289 void setFrameType(const QString &);
290 void setFramePenColor (const QColor &);
291 void setFrameBrushColor (const QColor &);
292 void setFramePadding (const int &);
293 void setFrameBorderWidth (const int &);
294 void setIncludeImagesVer(bool);
295 void setIncludeImagesHor(bool);
296 void setHideLinkUnselected (bool);
298 /*! Should object be hidden in exports (clouded)? */
299 void setHideExport(bool);
301 /*! Should object be hidden in exports (clouded)? */
302 void toggleHideExport();
306 void copy(); //!< Copy to clipboard
308 void pasteNoSave(const int &n); //!< paste clipboard to branch
310 void paste(); //!< Paste clipboard to branch and backup
311 void cut(); //!< Cut to clipboard (and copy)
313 bool moveUp(BranchItem *bi); //!< Move branch up without saving state
314 void moveUp(); //!< Move branch up with saving state
315 bool moveDown(BranchItem *bi); //!< Move branch down without saving state
316 void moveDown(); //!< Move branch down
317 void detach(); //!< Detach branch and use as new mapcenter
318 void sortChildren(bool inverse=false); //!< Sort children lexically
320 // The create methods are used to quickly parse a XML file
321 BranchItem* createMapCenter(); //!< Create MapCenter
322 BranchItem* createBranch(BranchItem *dst); //!< Create Branch
323 ImageItem* createImage(BranchItem *dst); //!< Create image
324 XLinkItem* createXLink(BranchItem *dst,bool createMO=false); //!< Create XLink starting at dst
326 AttributeItem* addAttribute();
327 AttributeItem* addAttribute(AttributeItem* );
329 /*! \brief Add new mapcenter
331 Disclaimer: Still experimental, not fully supported yet.
333 BranchItem* addMapCenter();
335 BranchItem* addMapCenter(QPointF absPos);
337 /*! \brief Add new branch
339 Depending on num the new branch is created
341 -3 above selection as child of selections parent
342 -2 as child of selection
343 -1 below selection as child of selections parent
344 0..n insert at a specific position in selections parent
345 (needed for free relinking)
349 BranchItem* addNewBranchInt(BranchItem *dst, int pos); // pos allows to add above/below selection
353 Depending on num the new branch is created
355 0 as child of selection
358 BranchItem* addNewBranch(int pos=0);
359 BranchItem* addNewBranchBefore(); //!< Insert branch between selection and its parent
360 /*! \brief Relink a branch to a new destination dst
361 Relinks branch to dst at branch position pos. There is no saveState
362 here, as for example moveUp or moving in MapEditor have
363 different needs to call saveState
364 Returns true if relinking was successful.
366 bool relinkBranch (BranchItem* branch, BranchItem* dst, int pos =-1);
367 bool relinkImage (ImageItem* image, BranchItem* dst);
369 void deleteSelection(); //!< Delete selection
370 void deleteKeepChildren(); //!< remove branch, but keep children
371 void deleteChildren(); //!< keep branch, but remove children
373 TreeItem* deleteItem(TreeItem*); //!< Delete item and return parent (if parent!= rootItem)
374 void clearItem (TreeItem* ti); //!< Remove all children of TreeItem ti
375 bool scrollBranch(BranchItem *);
376 bool unscrollBranch(BranchItem *);
379 void unscrollChildren();
380 void emitExpandAll();
381 void emitExpandOneLevel();
382 void emitCollapseOneLevel();
385 void expandOneLevel();
386 void collapseOneLevel();
389 void toggleStandardFlag (const QString &name, FlagRow *master=NULL);
390 void addFloatImage(const QPixmap &img);
392 void colorBranch(QColor);
393 void colorSubtree(QColor);
394 QColor getCurrentHeadingColor();
397 void editURL(); // edit URL
398 void editLocalURL(); // edit URL to local file
399 void editHeading2URL(); // copy heading to URL
400 void editBugzilla2URL(); // create URL to Bugzilla
401 void getBugzillaData(); // get data from Novell Bugzilla
402 void editFATE2URL(); // create URL to FATE
403 void editVymLink(); // edit link to another map
404 void setVymLink (const QString &); // Set vymLink for selection
405 void deleteVymLink(); // delete link to another map
406 QString getVymLink(); // return path to map
407 QStringList getVymLinks(); // return paths in subtree
408 void followXLink (int);
409 void editXLink (int);
414 ////////////////////////////////////////////
416 ////////////////////////////////////////////
419 /* \brief Process one command and its parameters */
420 QVariant parseAtom (const QString &atom, bool &noError, QString &errorMsg);
422 /* \brief Runs the script */
423 QVariant runScript (const QString &script);
428 ////////////////////////////////////////////
430 ////////////////////////////////////////////
432 TreeItem::HideTmpMode hidemode; // true while exporting to hide some stuff
435 /*! Set or unset temporary hiding of objects during export */
436 void setExportMode (bool);
439 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
442 /*! Export as XTML to directory */
443 void exportXML(QString dir="", bool askForName=true);
445 /*! Export as A&O report text to file */
446 void exportAO (QString fname="",bool askForName=true);
448 /*! Export as ASCII text to file */
449 void exportASCII (QString fname="",bool askForName=true);
451 /*! Export as HTML to directory */
452 void exportHTML(const QString& dir="", bool useDialog=true);
453 void exportXHTML(const QString& dir="", bool askForName=true);
455 /*! Export as OpenOfficeOrg presentation */
456 void exportOOPresentation(const QString &,const QString &);
459 ////////////////////////////////////////////
461 ////////////////////////////////////////////
463 void registerEditor (QWidget *);
464 void unregisterEditor (QWidget *);
466 void setMapZoomFactor (const double &);
469 QPointF contextPos; //!< local position during context menu
471 void setContextPos (QPointF); //!< local position during context menu
472 void unsetContextPos (); //!< forget local position after context menu
474 void updateNoteFlag(); //!< Signal origination in TextEditor
475 void reposition(); //!< Call reposition for all MCOs
476 void setHideTmpMode (TreeItem::HideTmpMode mode);
478 void emitNoteHasChanged (TreeItem *ti);
479 void emitDataHasChanged (TreeItem *ti);
480 void emitUpdateLayout ();
484 void noteHasChanged (QModelIndex ix);
485 void newChildObject(QModelIndex ix);
488 MapEditor *mapEditor;
490 QColor defLinkColor; // default color for links
491 QColor defXLinkColor; // default color for xlinks
492 int defXLinkWidth; // default width for xlinks
493 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
494 LinkableMapObj::Style linkstyle; // default style for links
497 void setMapLinkStyle (const QString &); // Set style of link
498 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
499 void setMapDefLinkColor(QColor); // default color of links
500 void setMapLinkColorHintInt(); // color of links
501 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
502 void toggleMapLinkColorHint(); // after changing linkStyles
503 void selectMapBackgroundImage();
504 void setMapBackgroundImage(const QString &);
505 void selectMapBackgroundColor();
506 void setMapBackgroundColor(QColor);
507 QColor getMapBackgroundColor();
510 LinkableMapObj::ColorHint getMapLinkColorHint();
511 QColor getMapDefLinkColor();
512 void setMapDefXLinkColor(QColor);
513 QColor getMapDefXLinkColor();
514 void setMapDefXLinkWidth (int);
515 int getMapDefXLinkWidth();
517 /*! Move absolutly to (x,y). */
518 void move (const double &x, const double &y);
520 /*! Move relativly to (x,y). */
521 void moveRel (const double &x, const double &y);
523 ////////////////////////////////////////////
524 // Animation **experimental**
525 ////////////////////////////////////////////
527 QTimer *animationTimer;
530 uint animationInterval;
531 int timerId; // animation timer
532 QList <MapObj*> animObjList;// list with animated objects //FIXME-2 should go to MapEditor
535 void animate(); //!< Called by timer to animate stuff
537 void startAnimation(BranchObj *bo, const QPointF &v);
538 void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
539 void stopAnimation(MapObj *mo);
541 ////////////////////////////////////////////
543 ////////////////////////////////////////////
545 /*! \brief Networking states
547 In Network modus we want to switch of saveState, autosave, ...
550 Offline, //!< Offline
551 Client, //!< I am the client and connected to server
552 Server //!< I am the server
556 // Network connections **Experimental**
557 NetState netstate; // offline, client, server
558 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
559 QList <QTcpSocket*> clientList; // List of connected clients
560 quint16 sendCounter; // Increased with every sent command
562 QTcpSocket *clientSocket; // socket of this client
563 QString server; // server address of this client
564 int port; // server port of this client
569 void sendSelection();
573 void connectToServer();
577 void sendData(const QString &s);
579 void displayNetworkError (QAbstractSocket::SocketError);
581 ////////////////////////////////////////////
583 ////////////////////////////////////////////
586 AdaptorModel *adaptorModel; //FIXME-3
591 ////////////////////////////////////////////
593 ////////////////////////////////////////////
595 TreeItem *latestAddedItem; // latest added object, reset on setChanged()
598 void setSelectionModel(QItemSelectionModel *); // Set common selectionModel
599 QItemSelectionModel* getSelectionModel();
601 void setSelectionBlocked(bool);
602 bool isSelectionBlocked();
604 bool select (); //! select by using common QItemSelectionModel
605 bool select (const QString &); //! Select by string
606 bool select (LinkableMapObj *lmo); //! Select by pointer to LMO
607 bool select (TreeItem *ti ); //! Select by pointer to TreeItem
608 bool select (TreeItem *ti,int i ); //! Select by pointer to TreeItem and index in note
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();