4 #include <QGraphicsScene>
7 #include <QtDBus/QDBusAbstractAdaptor>
8 #include <QtDBus/QDBusVariant>
10 #include "adaptormodel.h"
12 #include "imageitem.h"
13 #include "mapeditor.h"
16 #include "treemodel.h"
23 class VymModel : public TreeModel {
25 Q_CLASSINFO("D-Bus Interface", "org.insilmaril.vym.VymModel-h")
28 ////////////////////////////////////////////
29 // General housekeeping
30 ////////////////////////////////////////////
32 QString version; //!< version string saved in vym file
37 static uint idLast; //! the last used unique ID
45 void makeTmpDirectories(); //!< create temporary directories e.g. for history
47 MapEditor* getMapEditor(); // FIXME-2 still necessary?
48 uint getID(); //! Return unique ID of model
50 bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview
52 void updateActions(); //!< Update buttons in mainwindow
55 ////////////////////////////////////////////
57 ////////////////////////////////////////////
60 bool zipped; // should map be zipped
61 static int mapNum; // unique number for model used in save/undo
62 FileType fileType; // type of file, e.g. vym, freemind...
63 QString fileName; // short name of file (for tab)
64 QString filePath; // path to file which will be saved
65 QString fileDir; // dir where file is saved
66 QString destPath; // path to .vym file (needed for vymlinks)
67 QString mapName; // fileName without ".vym"
69 QString tmpMapDir; // tmp directory with undo history
71 QTimer *autosaveTimer;
72 QTimer *fileChangedTimer;
73 QDateTime fileChangedTime;
76 /*! This function saves all information of the map to disc.
77 saveToDir also calls the functions for all BranchObj and other objects in the map.
78 The structure of the map itself is returned as QString and passed back to Main,
79 where saveToDir is called initially
81 QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel);
83 /*! Save all data in tree*/
84 QString saveTreeToDir (const QString&,const QString&,const QPointF&);// Save data recursivly to tempdir
87 /*! \brief Sets filepath, filename and mapname
89 If the filepath is "/home/tux/map.xml", then the filename will be set
90 to map.xml. The destname is needed for vymLinks, pointing to another map.
91 The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
95 /*! \brief Set File path
97 The destname is needed to construct the references between maps
99 void setFilePath (QString filepath,QString destname);
100 void setFilePath (QString); //!< Overloaded for convenience
101 QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml"
102 QString getFileName (); //!< e.g. "map.xml"
103 QString getMapName (); //!< e.g. "map"
104 QString getDestPath (); //!< e.g. "/home/tux/map.vym"
108 The data is read from file. Depending on LoadMode the current
109 selection gets replaced by data or the data is appended.
111 ErrorCode load (QString, const LoadMode &, const FileType& ); // newmap, import/replace selection
114 /*! \brief Save the map to file */
115 ErrorCode save(const SaveMode &);
118 void addMapReplaceInt(const QString & undoSel, const QString & path);
119 bool addMapInsertInt (const QString & path);
120 bool addMapInsertInt (const QString & path, int pos);
122 ImageItem* loadFloatImageInt (BranchItem *dst,QString);
123 void saveFloatImageInt (ImageItem*, const QString &, const QString &);
125 void loadFloatImage ();
126 void saveFloatImage ();
129 void importDirInt(BranchItem *,QDir);
130 void importDirInt(const QString&);
138 ////////////////////////////////////////////
139 // history (undo/redo)
140 ////////////////////////////////////////////
142 bool mapDefault; //!< Flag if map is untouched
143 bool mapChanged; //!< Flag if undo is possible
144 bool mapUnsaved; //!< Flag if map should be saved
146 QString histPath; //!< Path to history file
147 SimpleSettings undoSet; //!< undo/redo commands, saved in histPath
148 int stepsTotal; //!< total number of steps (undos+redos)
149 int curStep; //!< Current step in history (ring buffer)
150 int curClipboard; //!< number of history step, which is the current clipboard
151 int redosAvail; //!< Available number of redo steps
152 int undosAvail; //!< Available number of undo steps
153 bool blockReposition; //!< block while load or undo
154 bool blockSaveState; //!< block while load or undo
156 bool isDefault(); //!< true, if map is still the empty default map
157 void makeDefault(); //!< Reset changelog, declare this as default map
158 bool hasChanged() ; //!< true, if something has changed and is not saved yet
159 void setChanged(); //!< called from TextEditor via LinkableMapObj
161 /*! \brief Get name of object
163 Returns heading of a branch or name of an object for use in comment
166 QString getObjectName(LinkableMapObj*);
167 QString getObjectName(TreeItem*);
169 void redo(); //!< Redo last action
170 bool isRedoAvailable(); //!< True, if redo is available
171 void undo(); //!< Undo last action
172 bool isUndoAvailable(); //!< True, if undo is available
173 void gotoHistoryStep (int); //!< Goto a specifig step in history
176 QString getHistoryPath(); //!< Path to directory containing the history
178 /*! \brief Save the current changes in map
180 Two commands and selections are saved:
182 - undocommand and undoselection to undo the change
183 - redocommand and redoselection to redo the action after an undo
185 Additionally a comment is logged.
189 const SaveMode& savemode,
190 const QString &undoSelection,
191 const QString &undoCommand,
192 const QString &redoSelection,
193 const QString &redoCommand,
194 const QString &comment,
195 TreeItem *saveSelection);
196 /*! Overloaded for convenience */
197 void saveStateChangingPart(
198 TreeItem *undoSelection,
199 TreeItem* redoSelection,
200 const QString &redoCommand,
201 const QString &comment);
202 /*! Overloaded for convenience */
203 void saveStateRemovingPart(
204 TreeItem *redoSelection,
205 const QString &comment);
206 /*! Overloaded for convenience */
208 TreeItem *undoSelection,
209 const QString &undoCommand,
210 TreeItem *redoSelection,
211 const QString &redoCommand,
212 const QString &comment);
213 /*! Overloaded for convenience */
215 const QString &undoSelection,
216 const QString &undoCommand,
217 const QString &redoSelection,
218 const QString &redoCommand,
219 const QString &comment) ;
221 const QString &undoCommand,
222 const QString &redoCommand,
223 const QString &comment) ;
226 ////////////////////////////////////////////
228 ////////////////////////////////////////////
230 QGraphicsScene *mapScene;
232 void setScene(QGraphicsScene *s);
233 QGraphicsScene *getScene();
235 TreeItem* findBySelectString (QString s);
236 TreeItem* findID (const uint &i); // find MapObj by unique ID
239 ////////////////////////////////////////////
241 ////////////////////////////////////////////
243 void setVersion(const QString &);
244 QString getVersion();
245 void setAuthor (const QString &);
246 QString getAuthor ();
247 void setComment (const QString &);
248 QString getComment ();
252 void setSortFilter (const QString &);
253 QString getSortFilter ();
257 void sortFilterChanged (QString ); //!< Notify editors of new filter
260 void setHeading(const QString &); //!< Set heading of item
261 QString getHeading (); //!< Get heading of item
262 void setNote(const QString &s); //!< Set note text
263 QString getNote(); //!< Get note text
266 BranchItem* findCurrent; // next object in find process
267 BranchItem* findPrevious; // next object in find process
268 bool EOFind; // true, if search failed
271 void findDuplicateURLs(); // find duplicate URLs, testing only so far
272 BranchItem* findText(QString,bool); // Find object
273 void findReset(); // Reset Search
274 void emitShowFindWidget(); // Tell views to show FindWidget
278 void showFindWidget();
281 void setURL(const QString &url);
282 QString getURL(); // returns URL of selection or ""
283 QStringList getURLs(bool ignoreScrolled=true); // returns URLs of subtree
286 void setFrameType(const FrameObj::FrameType &);
287 void setFrameType(const QString &);
288 void setFramePenColor (const QColor &);
289 void setFrameBrushColor (const QColor &);
290 void setFramePadding (const int &);
291 void setFrameBorderWidth (const int &);
292 void setIncludeImagesVer(bool);
293 void setIncludeImagesHor(bool);
294 void setHideLinkUnselected (bool);
296 /*! Should object be hidden in exports (clouded)? */
297 void setHideExport(bool);
299 /*! Should object be hidden in exports (clouded)? */
300 void toggleHideExport();
304 void copy(); //!< Copy to clipboard
306 void pasteNoSave(const int &n); //!< paste clipboard to branch
308 void paste(); //!< Paste clipboard to branch and backup
309 void cut(); //!< Cut to clipboard (and copy)
311 bool moveUp(BranchItem *bi); //!< Move branch up without saving state
312 void moveUp(); //!< Move branch up with saving state
313 bool moveDown(BranchItem *bi); //!< Move branch down without saving state
314 void moveDown(); //!< Move branch down
315 void detach(); //!< Detach branch and use as new mapcenter
316 void sortChildren(bool inverse=false); //!< Sort children lexically
318 // The create methods are used to quickly parse a XML file
319 BranchItem* createMapCenter(); //!< Create MapCenter
320 BranchItem* createBranch(BranchItem *dst); //!< Create Branch
321 ImageItem* createImage(BranchItem *dst); //!< Create image
322 XLinkItem* createXLink(BranchItem *dst,bool createMO=false); //!< Create XLink starting at dst
324 AttributeItem* addAttribute();
325 AttributeItem* addAttribute(AttributeItem* );
327 /*! \brief Add new mapcenter
329 Disclaimer: Still experimental, not fully supported yet.
331 BranchItem* addMapCenter();
333 BranchItem* addMapCenter(QPointF absPos);
335 /*! \brief Add new branch
337 Depending on num the new branch is created
339 -3 above selection as child of selections parent
340 -2 as child of selection
341 -1 below selection as child of selections parent
342 0..n insert at a specific position in selections parent
343 (needed for free relinking)
347 BranchItem* addNewBranchInt(BranchItem *dst, int pos); // pos allows to add above/below selection
351 Depending on num the new branch is created
353 0 as child of selection
356 BranchItem* addNewBranch(int pos=0);
357 BranchItem* addNewBranchBefore(); //!< Insert branch between selection and its parent
358 /*! \brief Relink a branch to a new destination dst
359 Relinks branch to dst at branch position pos. There is no saveState
360 here, as for example moveUp or moving in MapEditor have
361 different needs to call saveState
362 Returns true if relinking was successful.
364 bool relinkBranch (BranchItem* branch, BranchItem* dst, int pos =-1);
365 bool relinkImage (ImageItem* image, BranchItem* dst);
367 void deleteSelection(); //!< Delete selection
368 void deleteKeepChildren(); //!< remove branch, but keep children
369 void deleteChildren(); //!< keep branch, but remove children
371 TreeItem* deleteItem(TreeItem*); //!< Delete item and return parent (if parent!= rootItem)
372 void clearItem (TreeItem* ti); //!< Remove all children of TreeItem ti
373 bool scrollBranch(BranchItem *);
374 bool unscrollBranch(BranchItem *);
377 void unscrollChildren();
378 void emitExpandAll();
379 void emitExpandOneLevel();
380 void emitCollapseOneLevel();
383 void expandOneLevel();
384 void collapseOneLevel();
387 void toggleStandardFlag (const QString &name, FlagRow *master=NULL);
388 void addFloatImage(const QPixmap &img);
390 void colorBranch(QColor);
391 void colorSubtree(QColor);
392 QColor getCurrentHeadingColor();
395 void editURL(); // edit URL
396 void editLocalURL(); // edit URL to local file
397 void editHeading2URL(); // copy heading to URL
398 void editBugzilla2URL(); // create URL to Bugzilla
399 void getBugzillaData(); // get data from Novell Bugzilla
400 void editFATE2URL(); // create URL to FATE
401 void editVymLink(); // edit link to another map
402 void setVymLink (const QString &); // Set vymLink for selection
403 void deleteVymLink(); // delete link to another map
404 QString getVymLink(); // return path to map
405 QStringList getVymLinks(); // return paths in subtree
406 void followXLink (int);
407 void editXLink (int);
412 ////////////////////////////////////////////
414 ////////////////////////////////////////////
417 /* \brief Process one command and its parameters */
418 QVariant parseAtom (const QString &atom, bool &noError, QString &errorMsg);
420 /* \brief Runs the script */
421 QVariant runScript (const QString &script);
426 ////////////////////////////////////////////
428 ////////////////////////////////////////////
430 TreeItem::HideTmpMode hidemode; // true while exporting to hide some stuff
433 /*! Set or unset temporary hiding of objects during export */
434 void setExportMode (bool);
437 void exportImage (QString fname="",bool askForName=true,QString format="PNG");
440 /*! Export as XTML to directory */
441 void exportXML(QString dir="", bool askForName=true);
443 /*! Export as A&O report text to file */
444 void exportAO (QString fname="",bool askForName=true);
446 /*! Export as ASCII text to file */
447 void exportASCII (QString fname="",bool askForName=true);
449 /*! Export as HTML to directory */
450 void exportHTML(const QString& dir="", bool useDialog=true);
451 void exportXHTML(const QString& dir="", bool askForName=true);
453 /*! Export as OpenOfficeOrg presentation */
454 void exportOOPresentation(const QString &,const QString &);
457 ////////////////////////////////////////////
459 ////////////////////////////////////////////
461 void registerEditor (QWidget *);
462 void unregisterEditor (QWidget *);
465 QPointF contextPos; //!< local position during context menu
467 void setContextPos (QPointF); //!< local position during context menu
468 void unsetContextPos (); //!< forget local position after context menu
470 void updateNoteFlag(); //!< Signal origination in TextEditor
471 void reposition(); //!< Call reposition for all MCOs
472 void setHideTmpMode (TreeItem::HideTmpMode mode);
474 void emitNoteHasChanged (TreeItem *ti);
475 void emitDataHasChanged (TreeItem *ti);
478 void noteHasChanged (QModelIndex ix);
479 void newChildObject(QModelIndex ix);
482 MapEditor *mapEditor;
484 QColor defLinkColor; // default color for links
485 QColor defXLinkColor; // default color for xlinks
486 int defXLinkWidth; // default width for xlinks
487 LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
488 LinkableMapObj::Style linkstyle; // default style for links
491 void setMapLinkStyle (const QString &); // Set style of link
492 LinkableMapObj::Style getMapLinkStyle (); // requested in LMO
493 void setMapDefLinkColor(QColor); // default color of links
494 void setMapLinkColorHintInt(); // color of links
495 void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
496 void toggleMapLinkColorHint(); // after changing linkStyles
497 void selectMapBackgroundImage();
498 void setMapBackgroundImage(const QString &);
499 void selectMapBackgroundColor();
500 void setMapBackgroundColor(QColor);
501 QColor getMapBackgroundColor();
504 LinkableMapObj::ColorHint getMapLinkColorHint();
505 QColor getMapDefLinkColor();
506 void setMapDefXLinkColor(QColor);
507 QColor getMapDefXLinkColor();
508 void setMapDefXLinkWidth (int);
509 int getMapDefXLinkWidth();
511 /*! Move absolutly to (x,y). */
512 void move (const double &x, const double &y);
514 /*! Move relativly to (x,y). */
515 void moveRel (const double &x, const double &y);
517 ////////////////////////////////////////////
518 // Animation **experimental**
519 ////////////////////////////////////////////
521 QTimer *animationTimer;
524 uint animationInterval;
525 int timerId; // animation timer
526 QList <MapObj*> animObjList;// list with animated objects //FIXME-2 should go to MapEditor
529 void animate(); //!< Called by timer to animate stuff
531 void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
532 void stopAnimation(MapObj *mo);
534 ////////////////////////////////////////////
536 ////////////////////////////////////////////
538 /*! \brief Networking states
540 In Network modus we want to switch of saveState, autosave, ...
543 Offline, //!< Offline
544 Client, //!< I am the client and connected to server
545 Server //!< I am the server
549 // Network connections **Experimental**
550 NetState netstate; // offline, client, server
551 QTcpServer *tcpServer; // Act as server in conference mode (experimental)
552 QList <QTcpSocket*> clientList; // List of connected clients
553 quint16 sendCounter; // Increased with every sent command
555 QTcpSocket *clientSocket; // socket of this client
556 QString server; // server address of this client
557 int port; // server port of this client
562 void sendSelection();
566 void connectToServer();
570 void sendData(const QString &s);
572 void displayNetworkError (QAbstractSocket::SocketError);
574 ////////////////////////////////////////////
576 ////////////////////////////////////////////
579 AdaptorModel *adaptorModel; //FIXME-3
584 ////////////////////////////////////////////
586 ////////////////////////////////////////////
588 TreeItem *latestAddedItem; // latest added object, reset on setChanged()
591 void setSelectionModel(QItemSelectionModel *); // Set common selectionModel
592 QItemSelectionModel* getSelectionModel();
594 void setSelectionBlocked(bool);
595 bool isSelectionBlocked();
597 bool select (); //! select by using common QItemSelectionModel
598 bool select (const QString &); //! Select by string
599 bool select (LinkableMapObj *lmo); //! Select by pointer to LMO
600 bool select (TreeItem *ti ); //! Select by pointer to TreeItem
601 bool select (const QModelIndex &index); //! Select by ModelIndex
605 void emitShowSelection(); //!< Show selection in all views
607 void showSelection();
610 bool selectFirstBranch();
611 bool selectLastBranch();
612 bool selectLastSelectedBranch();
616 TreeItem::Type selectionType();
617 LinkableMapObj* getSelectedLMO();
618 BranchObj* getSelectedBranchObj(); // FIXME-3 replace by item...
619 BranchItem* getSelectedBranch();
620 ImageItem* getSelectedImage();
621 AttributeItem* getSelectedAttribute();
622 TreeItem* getSelectedItem();
623 QModelIndex getSelectedIndex();
624 QString getSelectString ();
625 QString getSelectString (LinkableMapObj *lmo);
626 QString getSelectString (TreeItem *item);
630 void selectionChanged(const QItemSelection &newsel, const QItemSelection &oldsel);
633 void emitSelectionChanged(const QItemSelection &oldsel);
634 void emitSelectionChanged();
635 void selectMapLinkColor();
636 void selectMapSelectionColor();
638 void setSelectionColorInt(QColor);
639 QItemSelectionModel *selModel;
640 QString lastSelectString;
641 bool selectionBlocked; //! Used to block changes of selection while editing a heading
644 void setSelectionColor(QColor);
645 QColor getSelectionColor();