insilmaril@650
|
1 |
#include <QApplication>
|
insilmaril@687
|
2 |
#include <typeinfo>
|
insilmaril@650
|
3 |
|
insilmaril@721
|
4 |
#include "vymmodel.h"
|
insilmaril@721
|
5 |
|
insilmaril@753
|
6 |
#include "treeitem.h"
|
insilmaril@749
|
7 |
#include "branchitem.h"
|
insilmaril@749
|
8 |
#include "mapcenteritem.h"
|
insilmaril@721
|
9 |
#include "editxlinkdialog.h"
|
insilmaril@721
|
10 |
#include "exports.h"
|
insilmaril@721
|
11 |
#include "exportxhtmldialog.h"
|
insilmaril@721
|
12 |
#include "file.h"
|
insilmaril@650
|
13 |
#include "geometry.h" // for addBBox
|
insilmaril@721
|
14 |
#include "mainwindow.h"
|
insilmaril@721
|
15 |
#include "mapcenterobj.h"
|
insilmaril@721
|
16 |
#include "misc.h"
|
insilmaril@721
|
17 |
#include "parser.h"
|
insilmaril@721
|
18 |
#include "selection.h"
|
insilmaril@721
|
19 |
|
insilmaril@721
|
20 |
|
insilmaril@721
|
21 |
#include "warningdialog.h"
|
insilmaril@721
|
22 |
#include "xml-freemind.h"
|
insilmaril@726
|
23 |
#include "xmlobj.h"
|
insilmaril@721
|
24 |
#include "xml-vym.h"
|
insilmaril@721
|
25 |
|
insilmaril@721
|
26 |
|
insilmaril@721
|
27 |
extern bool debug;
|
insilmaril@721
|
28 |
extern Main *mainWindow;
|
insilmaril@696
|
29 |
extern Settings settings;
|
insilmaril@721
|
30 |
extern QString tmpVymDir;
|
insilmaril@721
|
31 |
|
insilmaril@721
|
32 |
extern TextEditor *textEditor;
|
insilmaril@721
|
33 |
|
insilmaril@721
|
34 |
extern QString clipboardDir;
|
insilmaril@721
|
35 |
extern QString clipboardFile;
|
insilmaril@721
|
36 |
extern bool clipboardEmpty;
|
insilmaril@721
|
37 |
|
insilmaril@721
|
38 |
extern ImageIO imageIO;
|
insilmaril@721
|
39 |
|
insilmaril@721
|
40 |
extern QString vymName;
|
insilmaril@721
|
41 |
extern QString vymVersion;
|
insilmaril@721
|
42 |
extern QDir vymBaseDir;
|
insilmaril@721
|
43 |
|
insilmaril@721
|
44 |
extern QDir lastImageDir;
|
insilmaril@721
|
45 |
extern QDir lastFileDir;
|
insilmaril@721
|
46 |
|
insilmaril@721
|
47 |
extern FlagRowObj *standardFlagsDefault;
|
insilmaril@721
|
48 |
|
insilmaril@721
|
49 |
extern Settings settings;
|
insilmaril@721
|
50 |
|
insilmaril@721
|
51 |
|
insilmaril@721
|
52 |
|
insilmaril@721
|
53 |
int VymModel::mapNum=0; // make instance
|
insilmaril@696
|
54 |
|
insilmaril@650
|
55 |
VymModel::VymModel()
|
insilmaril@650
|
56 |
{
|
insilmaril@650
|
57 |
// cout << "Const VymModel\n";
|
insilmaril@721
|
58 |
init();
|
insilmaril@746
|
59 |
rootItem->setModel (this);
|
insilmaril@650
|
60 |
}
|
insilmaril@650
|
61 |
|
insilmaril@650
|
62 |
|
insilmaril@650
|
63 |
VymModel::~VymModel()
|
insilmaril@650
|
64 |
{
|
insilmaril@650
|
65 |
// cout << "Destr VymModel\n";
|
insilmaril@721
|
66 |
autosaveTimer->stop();
|
insilmaril@721
|
67 |
fileChangedTimer->stop();
|
insilmaril@721
|
68 |
clear();
|
insilmaril@650
|
69 |
}
|
insilmaril@650
|
70 |
|
insilmaril@650
|
71 |
void VymModel::clear()
|
insilmaril@650
|
72 |
{
|
insilmaril@735
|
73 |
selModel->clearSelection();
|
insilmaril@721
|
74 |
|
insilmaril@754
|
75 |
//QModelIndex ri=index(rootItem);
|
insilmaril@746
|
76 |
//removeRows (0, rowCount(ri),ri); // FIXME-2 here should be at least a beginRemoveRows...
|
insilmaril@650
|
77 |
}
|
insilmaril@650
|
78 |
|
insilmaril@650
|
79 |
void VymModel::init ()
|
insilmaril@650
|
80 |
{
|
insilmaril@721
|
81 |
// We should have at least one map center to start with
|
insilmaril@746
|
82 |
// addMapCenter(); FIXME-2 VM create this in MapEditor as long as model is part of that
|
insilmaril@727
|
83 |
|
insilmaril@727
|
84 |
// No MapEditor yet
|
insilmaril@727
|
85 |
mapEditor=NULL;
|
insilmaril@721
|
86 |
|
insilmaril@746
|
87 |
// Also no scene yet (should not be needed anyway) FIXME-3 VM
|
insilmaril@728
|
88 |
mapScene=NULL;
|
insilmaril@728
|
89 |
|
insilmaril@721
|
90 |
// History
|
insilmaril@721
|
91 |
mapNum++;
|
insilmaril@721
|
92 |
mapChanged=false;
|
insilmaril@721
|
93 |
mapDefault=true;
|
insilmaril@721
|
94 |
mapUnsaved=false;
|
insilmaril@721
|
95 |
|
insilmaril@721
|
96 |
curStep=0;
|
insilmaril@721
|
97 |
redosAvail=0;
|
insilmaril@721
|
98 |
undosAvail=0;
|
insilmaril@721
|
99 |
|
insilmaril@721
|
100 |
stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
|
insilmaril@721
|
101 |
undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
|
insilmaril@721
|
102 |
mainWindow->updateHistory (undoSet);
|
insilmaril@721
|
103 |
|
insilmaril@721
|
104 |
// Create tmp dirs
|
insilmaril@721
|
105 |
makeTmpDirectories();
|
insilmaril@721
|
106 |
|
insilmaril@721
|
107 |
// Files
|
insilmaril@721
|
108 |
zipped=true;
|
insilmaril@721
|
109 |
filePath="";
|
insilmaril@721
|
110 |
fileName=tr("unnamed");
|
insilmaril@721
|
111 |
mapName="";
|
insilmaril@721
|
112 |
blockReposition=false;
|
insilmaril@721
|
113 |
blockSaveState=false;
|
insilmaril@721
|
114 |
|
insilmaril@721
|
115 |
autosaveTimer=new QTimer (this);
|
insilmaril@721
|
116 |
connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
|
insilmaril@721
|
117 |
|
insilmaril@721
|
118 |
fileChangedTimer=new QTimer (this);
|
insilmaril@721
|
119 |
fileChangedTimer->start(3000);
|
insilmaril@721
|
120 |
connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
|
insilmaril@721
|
121 |
|
insilmaril@721
|
122 |
|
insilmaril@721
|
123 |
// selections
|
insilmaril@728
|
124 |
selModel=NULL;
|
insilmaril@721
|
125 |
|
insilmaril@721
|
126 |
// find routine
|
insilmaril@741
|
127 |
findCurrent=NULL;
|
insilmaril@741
|
128 |
findPrevious=NULL;
|
insilmaril@721
|
129 |
EOFind=false;
|
insilmaril@696
|
130 |
|
insilmaril@696
|
131 |
// animations
|
insilmaril@696
|
132 |
animationUse=settings.readBoolEntry("/animation/use",false);
|
insilmaril@696
|
133 |
animationTicks=settings.readNumEntry("/animation/ticks",10);
|
insilmaril@696
|
134 |
animationInterval=settings.readNumEntry("/animation/interval",50);
|
insilmaril@696
|
135 |
animObjList.clear();
|
insilmaril@696
|
136 |
animationTimer=new QTimer (this);
|
insilmaril@696
|
137 |
connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
|
insilmaril@696
|
138 |
|
insilmaril@721
|
139 |
// View - map
|
insilmaril@721
|
140 |
defLinkColor=QColor (0,0,255);
|
insilmaril@721
|
141 |
defXLinkColor=QColor (180,180,180);
|
insilmaril@721
|
142 |
linkcolorhint=LinkableMapObj::DefaultColor;
|
insilmaril@721
|
143 |
linkstyle=LinkableMapObj::PolyParabel;
|
insilmaril@721
|
144 |
defXLinkWidth=1;
|
insilmaril@721
|
145 |
defXLinkColor=QColor (230,230,230);
|
insilmaril@721
|
146 |
|
insilmaril@753
|
147 |
hidemode=TreeItem::HideNone;
|
insilmaril@721
|
148 |
|
insilmaril@721
|
149 |
// Network
|
insilmaril@721
|
150 |
netstate=Offline;
|
insilmaril@721
|
151 |
|
insilmaril@721
|
152 |
// Create MapCenter
|
insilmaril@746
|
153 |
// addMapCenter(); FIXME-2 VM create this in MapEditor until BO and MCO are independent of scene
|
insilmaril@721
|
154 |
|
insilmaril@650
|
155 |
}
|
insilmaril@650
|
156 |
|
insilmaril@721
|
157 |
void VymModel::makeTmpDirectories()
|
insilmaril@721
|
158 |
{
|
insilmaril@721
|
159 |
// Create unique temporary directories
|
insilmaril@721
|
160 |
tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
|
insilmaril@721
|
161 |
histPath = tmpMapDir+"/history";
|
insilmaril@721
|
162 |
QDir d;
|
insilmaril@721
|
163 |
d.mkdir (tmpMapDir);
|
insilmaril@721
|
164 |
}
|
insilmaril@721
|
165 |
|
insilmaril@721
|
166 |
|
insilmaril@746
|
167 |
MapEditor* VymModel::getMapEditor() // FIXME-2 VM better return favourite editor here
|
insilmaril@650
|
168 |
{
|
insilmaril@650
|
169 |
return mapEditor;
|
insilmaril@650
|
170 |
}
|
insilmaril@650
|
171 |
|
insilmaril@721
|
172 |
bool VymModel::isRepositionBlocked()
|
insilmaril@650
|
173 |
{
|
insilmaril@721
|
174 |
return blockReposition;
|
insilmaril@650
|
175 |
}
|
insilmaril@650
|
176 |
|
insilmaril@746
|
177 |
void VymModel::updateActions() // FIXME-2 maybe don't update if blockReposition is set
|
insilmaril@650
|
178 |
{
|
insilmaril@756
|
179 |
//cout << "VM::updateActions \n";
|
insilmaril@721
|
180 |
// Tell mainwindow to update states of actions
|
insilmaril@721
|
181 |
mainWindow->updateActions();
|
insilmaril@650
|
182 |
}
|
insilmaril@650
|
183 |
|
insilmaril@721
|
184 |
|
insilmaril@721
|
185 |
|
insilmaril@753
|
186 |
QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel)
|
insilmaril@650
|
187 |
{
|
insilmaril@721
|
188 |
// tmpdir temporary directory to which data will be written
|
insilmaril@721
|
189 |
// prefix mapname, which will be appended to images etc.
|
insilmaril@721
|
190 |
// writeflags Only write flags for "real" save of map, not undo
|
insilmaril@721
|
191 |
// offset offset of bbox of whole map in scene.
|
insilmaril@721
|
192 |
// Needed for XML export
|
insilmaril@721
|
193 |
|
insilmaril@726
|
194 |
|
insilmaril@726
|
195 |
XMLObj xml;
|
insilmaril@726
|
196 |
|
insilmaril@721
|
197 |
// Save Header
|
insilmaril@721
|
198 |
QString ls;
|
insilmaril@721
|
199 |
switch (linkstyle)
|
insilmaril@721
|
200 |
{
|
insilmaril@721
|
201 |
case LinkableMapObj::Line:
|
insilmaril@721
|
202 |
ls="StyleLine";
|
insilmaril@721
|
203 |
break;
|
insilmaril@721
|
204 |
case LinkableMapObj::Parabel:
|
insilmaril@721
|
205 |
ls="StyleParabel";
|
insilmaril@721
|
206 |
break;
|
insilmaril@721
|
207 |
case LinkableMapObj::PolyLine:
|
insilmaril@721
|
208 |
ls="StylePolyLine";
|
insilmaril@721
|
209 |
break;
|
insilmaril@721
|
210 |
default:
|
insilmaril@721
|
211 |
ls="StylePolyParabel";
|
insilmaril@721
|
212 |
break;
|
insilmaril@721
|
213 |
}
|
insilmaril@721
|
214 |
|
insilmaril@721
|
215 |
QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
|
insilmaril@721
|
216 |
QString colhint="";
|
insilmaril@721
|
217 |
if (linkcolorhint==LinkableMapObj::HeadingColor)
|
insilmaril@726
|
218 |
colhint=xml.attribut("linkColorHint","HeadingColor");
|
insilmaril@726
|
219 |
|
insilmaril@726
|
220 |
QString mapAttr=xml.attribut("version",vymVersion);
|
insilmaril@721
|
221 |
if (!saveSel)
|
insilmaril@726
|
222 |
mapAttr+= xml.attribut("author",author) +
|
insilmaril@726
|
223 |
xml.attribut("comment",comment) +
|
insilmaril@726
|
224 |
xml.attribut("date",getDate()) +
|
insilmaril@749
|
225 |
xml.attribut("branchCount", QString().number(branchCount())) +
|
insilmaril@726
|
226 |
xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
|
insilmaril@728
|
227 |
xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
|
insilmaril@726
|
228 |
xml.attribut("linkStyle", ls ) +
|
insilmaril@726
|
229 |
xml.attribut("linkColor", defLinkColor.name() ) +
|
insilmaril@726
|
230 |
xml.attribut("defXLinkColor", defXLinkColor.name() ) +
|
insilmaril@726
|
231 |
xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
|
insilmaril@721
|
232 |
colhint;
|
insilmaril@726
|
233 |
s+=xml.beginElement("vymmap",mapAttr);
|
insilmaril@726
|
234 |
xml.incIndent();
|
insilmaril@721
|
235 |
|
insilmaril@746
|
236 |
// Find the used flags while traversing the tree // FIXME-2 this can be done local to vymmodel maybe...
|
insilmaril@721
|
237 |
standardFlagsDefault->resetUsedCounter();
|
insilmaril@721
|
238 |
|
insilmaril@721
|
239 |
// Reset the counters before saving
|
insilmaril@721
|
240 |
// TODO constr. of FIO creates lots of objects, better do this in some other way...
|
insilmaril@746
|
241 |
FloatImageObj (mapScene).resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe...
|
insilmaril@721
|
242 |
|
insilmaril@760
|
243 |
cout << "VM::saveToDir 0 " <<saveSel<<endl;
|
insilmaril@721
|
244 |
// Build xml recursivly
|
insilmaril@759
|
245 |
if (!saveSel || saveSel->getType()==TreeItem::MapCenter)
|
insilmaril@745
|
246 |
// Save all mapcenters as complete map, if saveSel not set
|
insilmaril@745
|
247 |
s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
|
insilmaril@721
|
248 |
else
|
insilmaril@721
|
249 |
{
|
insilmaril@759
|
250 |
if (saveSel->getType()==TreeItem::Branch)
|
insilmaril@721
|
251 |
// Save Subtree
|
insilmaril@759
|
252 |
s+=saveSel->saveToDir(tmpdir,prefix,offset);
|
insilmaril@759
|
253 |
//FIXME-2 else if (saveSel->getType()==TreeItem::Image)
|
insilmaril@721
|
254 |
// Save image
|
insilmaril@759
|
255 |
//s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
|
insilmaril@721
|
256 |
}
|
insilmaril@721
|
257 |
|
insilmaril@760
|
258 |
cout << "VM::saveToDir 1 \n";
|
insilmaril@721
|
259 |
// Save local settings
|
insilmaril@721
|
260 |
s+=settings.getDataXML (destPath);
|
insilmaril@721
|
261 |
|
insilmaril@760
|
262 |
cout << "VM::saveToDir 2 \n";
|
insilmaril@721
|
263 |
// Save selection
|
insilmaril@759
|
264 |
if (getSelectedItem() && !saveSel )
|
insilmaril@759
|
265 |
s+=xml.valueElement("select",getSelectString());
|
insilmaril@726
|
266 |
|
insilmaril@726
|
267 |
xml.decIndent();
|
insilmaril@726
|
268 |
s+=xml.endElement("vymmap");
|
insilmaril@721
|
269 |
|
insilmaril@721
|
270 |
if (writeflags)
|
insilmaril@721
|
271 |
standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
|
insilmaril@721
|
272 |
return s;
|
insilmaril@650
|
273 |
}
|
insilmaril@650
|
274 |
|
insilmaril@754
|
275 |
QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) // FIXME-4 verbose not needed (used to write icons)
|
insilmaril@745
|
276 |
{
|
insilmaril@745
|
277 |
QString s;
|
insilmaril@745
|
278 |
|
insilmaril@757
|
279 |
for (int i=0; i<rootItem->branchCount(); i++)
|
insilmaril@754
|
280 |
s+=((MapCenterItem*)rootItem->getBranchNum(i))->saveToDir (tmpdir,prefix,offset);
|
insilmaril@745
|
281 |
return s;
|
insilmaril@745
|
282 |
}
|
insilmaril@745
|
283 |
|
insilmaril@721
|
284 |
void VymModel::setFilePath(QString fpath, QString destname)
|
insilmaril@650
|
285 |
{
|
insilmaril@721
|
286 |
if (fpath.isEmpty() || fpath=="")
|
insilmaril@721
|
287 |
{
|
insilmaril@721
|
288 |
filePath="";
|
insilmaril@721
|
289 |
fileName="";
|
insilmaril@721
|
290 |
destPath="";
|
insilmaril@721
|
291 |
} else
|
insilmaril@721
|
292 |
{
|
insilmaril@721
|
293 |
filePath=fpath; // becomes absolute path
|
insilmaril@721
|
294 |
fileName=fpath; // gets stripped of path
|
insilmaril@721
|
295 |
destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
|
insilmaril@721
|
296 |
|
insilmaril@721
|
297 |
// If fpath is not an absolute path, complete it
|
insilmaril@721
|
298 |
filePath=QDir(fpath).absPath();
|
insilmaril@721
|
299 |
fileDir=filePath.left (1+filePath.findRev ("/"));
|
insilmaril@721
|
300 |
|
insilmaril@721
|
301 |
// Set short name, too. Search from behind:
|
insilmaril@721
|
302 |
int i=fileName.findRev("/");
|
insilmaril@721
|
303 |
if (i>=0) fileName=fileName.remove (0,i+1);
|
insilmaril@721
|
304 |
|
insilmaril@721
|
305 |
// Forget the .vym (or .xml) for name of map
|
insilmaril@721
|
306 |
mapName=fileName.left(fileName.findRev(".",-1,true) );
|
insilmaril@721
|
307 |
}
|
insilmaril@650
|
308 |
}
|
insilmaril@650
|
309 |
|
insilmaril@721
|
310 |
void VymModel::setFilePath(QString fpath)
|
insilmaril@650
|
311 |
{
|
insilmaril@721
|
312 |
setFilePath (fpath,fpath);
|
insilmaril@650
|
313 |
}
|
insilmaril@650
|
314 |
|
insilmaril@721
|
315 |
QString VymModel::getFilePath()
|
insilmaril@650
|
316 |
{
|
insilmaril@721
|
317 |
return filePath;
|
insilmaril@650
|
318 |
}
|
insilmaril@650
|
319 |
|
insilmaril@721
|
320 |
QString VymModel::getFileName()
|
insilmaril@650
|
321 |
{
|
insilmaril@721
|
322 |
return fileName;
|
insilmaril@650
|
323 |
}
|
insilmaril@650
|
324 |
|
insilmaril@721
|
325 |
QString VymModel::getMapName()
|
insilmaril@721
|
326 |
{
|
insilmaril@721
|
327 |
return mapName;
|
insilmaril@721
|
328 |
}
|
insilmaril@721
|
329 |
|
insilmaril@721
|
330 |
QString VymModel::getDestPath()
|
insilmaril@721
|
331 |
{
|
insilmaril@721
|
332 |
return destPath;
|
insilmaril@721
|
333 |
}
|
insilmaril@721
|
334 |
|
insilmaril@721
|
335 |
ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
|
insilmaril@721
|
336 |
{
|
insilmaril@721
|
337 |
ErrorCode err=success;
|
insilmaril@721
|
338 |
|
insilmaril@721
|
339 |
parseBaseHandler *handler;
|
insilmaril@721
|
340 |
fileType=ftype;
|
insilmaril@721
|
341 |
switch (fileType)
|
insilmaril@721
|
342 |
{
|
insilmaril@721
|
343 |
case VymMap: handler=new parseVYMHandler; break;
|
insilmaril@721
|
344 |
case FreemindMap : handler=new parseFreemindHandler; break;
|
insilmaril@721
|
345 |
default:
|
insilmaril@721
|
346 |
QMessageBox::critical( 0, tr( "Critical Parse Error" ),
|
insilmaril@721
|
347 |
"Unknown FileType in VymModel::load()");
|
insilmaril@721
|
348 |
return aborted;
|
insilmaril@721
|
349 |
}
|
insilmaril@729
|
350 |
|
insilmaril@729
|
351 |
bool zipped_org=zipped;
|
insilmaril@729
|
352 |
|
insilmaril@721
|
353 |
if (lmode==NewMap)
|
insilmaril@721
|
354 |
{
|
insilmaril@735
|
355 |
selModel->clearSelection();
|
insilmaril@746
|
356 |
// FIXME-2 VM not needed??? model->setMapEditor(this);
|
insilmaril@721
|
357 |
// (map state is set later at end of load...)
|
insilmaril@721
|
358 |
} else
|
insilmaril@721
|
359 |
{
|
insilmaril@753
|
360 |
BranchItem *bi=getSelectedBranchItem();
|
insilmaril@753
|
361 |
if (!bi) return aborted;
|
insilmaril@721
|
362 |
if (lmode==ImportAdd)
|
insilmaril@721
|
363 |
saveStateChangingPart(
|
insilmaril@753
|
364 |
bi,
|
insilmaril@753
|
365 |
bi,
|
insilmaril@721
|
366 |
QString("addMapInsert (%1)").arg(fname),
|
insilmaril@753
|
367 |
QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
|
insilmaril@721
|
368 |
else
|
insilmaril@721
|
369 |
saveStateChangingPart(
|
insilmaril@753
|
370 |
bi,
|
insilmaril@753
|
371 |
bi,
|
insilmaril@721
|
372 |
QString("addMapReplace(%1)").arg(fname),
|
insilmaril@753
|
373 |
QString("Add map %1 to %2").arg(fname).arg(getObjectName(bi)));
|
insilmaril@721
|
374 |
}
|
insilmaril@721
|
375 |
|
insilmaril@721
|
376 |
|
insilmaril@721
|
377 |
// Create temporary directory for packing
|
insilmaril@721
|
378 |
bool ok;
|
insilmaril@721
|
379 |
QString tmpZipDir=makeTmpDir (ok,"vym-pack");
|
insilmaril@721
|
380 |
if (!ok)
|
insilmaril@721
|
381 |
{
|
insilmaril@721
|
382 |
QMessageBox::critical( 0, tr( "Critical Load Error" ),
|
insilmaril@721
|
383 |
tr("Couldn't create temporary directory before load\n"));
|
insilmaril@721
|
384 |
return aborted;
|
insilmaril@721
|
385 |
}
|
insilmaril@721
|
386 |
|
insilmaril@721
|
387 |
// Try to unzip file
|
insilmaril@721
|
388 |
err=unzipDir (tmpZipDir,fname);
|
insilmaril@721
|
389 |
QString xmlfile;
|
insilmaril@721
|
390 |
if (err==nozip)
|
insilmaril@721
|
391 |
{
|
insilmaril@721
|
392 |
xmlfile=fname;
|
insilmaril@721
|
393 |
zipped=false;
|
insilmaril@721
|
394 |
} else
|
insilmaril@721
|
395 |
{
|
insilmaril@721
|
396 |
zipped=true;
|
insilmaril@721
|
397 |
|
insilmaril@721
|
398 |
// Look for mapname.xml
|
insilmaril@721
|
399 |
xmlfile= fname.left(fname.findRev(".",-1,true));
|
insilmaril@721
|
400 |
xmlfile=xmlfile.section( '/', -1 );
|
insilmaril@721
|
401 |
QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
|
insilmaril@721
|
402 |
if (!mfile.exists() )
|
insilmaril@721
|
403 |
{
|
insilmaril@721
|
404 |
// mapname.xml does not exist, well,
|
insilmaril@721
|
405 |
// maybe someone renamed the mapname.vym file...
|
insilmaril@721
|
406 |
// Try to find any .xml in the toplevel
|
insilmaril@721
|
407 |
// directory of the .vym file
|
insilmaril@721
|
408 |
QStringList flist=QDir (tmpZipDir).entryList("*.xml");
|
insilmaril@721
|
409 |
if (flist.count()==1)
|
insilmaril@721
|
410 |
{
|
insilmaril@721
|
411 |
// Only one entry, take this one
|
insilmaril@721
|
412 |
xmlfile=tmpZipDir + "/"+flist.first();
|
insilmaril@721
|
413 |
} else
|
insilmaril@721
|
414 |
{
|
insilmaril@721
|
415 |
for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
|
insilmaril@721
|
416 |
*it=tmpZipDir + "/" + *it;
|
insilmaril@721
|
417 |
// TODO Multiple entries, load all (but only the first one into this ME)
|
insilmaril@721
|
418 |
//mainWindow->fileLoadFromTmp (flist);
|
insilmaril@721
|
419 |
//returnCode=1; // Silently forget this attempt to load
|
insilmaril@721
|
420 |
qWarning ("MainWindow::load (fn) multimap found...");
|
insilmaril@721
|
421 |
}
|
insilmaril@721
|
422 |
|
insilmaril@721
|
423 |
if (flist.isEmpty() )
|
insilmaril@721
|
424 |
{
|
insilmaril@721
|
425 |
QMessageBox::critical( 0, tr( "Critical Load Error" ),
|
insilmaril@721
|
426 |
tr("Couldn't find a map (*.xml) in .vym archive.\n"));
|
insilmaril@721
|
427 |
err=aborted;
|
insilmaril@721
|
428 |
}
|
insilmaril@721
|
429 |
} //file doesn't exist
|
insilmaril@721
|
430 |
else
|
insilmaril@721
|
431 |
xmlfile=mfile.name();
|
insilmaril@721
|
432 |
}
|
insilmaril@721
|
433 |
|
insilmaril@721
|
434 |
QFile file( xmlfile);
|
insilmaril@721
|
435 |
|
insilmaril@721
|
436 |
// I am paranoid: file should exist anyway
|
insilmaril@721
|
437 |
// according to check in mainwindow.
|
insilmaril@721
|
438 |
if (!file.exists() )
|
insilmaril@721
|
439 |
{
|
insilmaril@721
|
440 |
QMessageBox::critical( 0, tr( "Critical Parse Error" ),
|
insilmaril@721
|
441 |
tr(QString("Couldn't open map %1").arg(file.name())));
|
insilmaril@721
|
442 |
err=aborted;
|
insilmaril@721
|
443 |
} else
|
insilmaril@721
|
444 |
{
|
insilmaril@721
|
445 |
bool blockSaveStateOrg=blockSaveState;
|
insilmaril@721
|
446 |
blockReposition=true;
|
insilmaril@721
|
447 |
blockSaveState=true;
|
insilmaril@762
|
448 |
mapEditor->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
|
insilmaril@721
|
449 |
QXmlInputSource source( file);
|
insilmaril@721
|
450 |
QXmlSimpleReader reader;
|
insilmaril@721
|
451 |
reader.setContentHandler( handler );
|
insilmaril@721
|
452 |
reader.setErrorHandler( handler );
|
insilmaril@721
|
453 |
handler->setModel ( this);
|
insilmaril@721
|
454 |
|
insilmaril@721
|
455 |
|
insilmaril@721
|
456 |
// We need to set the tmpDir in order to load files with rel. path
|
insilmaril@721
|
457 |
QString tmpdir;
|
insilmaril@721
|
458 |
if (zipped)
|
insilmaril@721
|
459 |
tmpdir=tmpZipDir;
|
insilmaril@721
|
460 |
else
|
insilmaril@721
|
461 |
tmpdir=fname.left(fname.findRev("/",-1));
|
insilmaril@721
|
462 |
handler->setTmpDir (tmpdir);
|
insilmaril@721
|
463 |
handler->setInputFile (file.name());
|
insilmaril@721
|
464 |
handler->setLoadMode (lmode);
|
insilmaril@721
|
465 |
bool ok = reader.parse( source );
|
insilmaril@721
|
466 |
blockReposition=false;
|
insilmaril@721
|
467 |
blockSaveState=blockSaveStateOrg;
|
insilmaril@762
|
468 |
mapEditor->setViewportUpdateMode (QGraphicsView::MinimalViewportUpdate);
|
insilmaril@721
|
469 |
file.close();
|
insilmaril@721
|
470 |
if ( ok )
|
insilmaril@721
|
471 |
{
|
insilmaril@746
|
472 |
reposition(); // FIXME-2 VM reposition the view instead...
|
insilmaril@721
|
473 |
selection.update();
|
insilmaril@721
|
474 |
if (lmode==NewMap)
|
insilmaril@721
|
475 |
{
|
insilmaril@721
|
476 |
mapDefault=false;
|
insilmaril@721
|
477 |
mapChanged=false;
|
insilmaril@721
|
478 |
mapUnsaved=false;
|
insilmaril@721
|
479 |
autosaveTimer->stop();
|
insilmaril@721
|
480 |
}
|
insilmaril@721
|
481 |
|
insilmaril@721
|
482 |
// Reset timestamp to check for later updates of file
|
insilmaril@721
|
483 |
fileChangedTime=QFileInfo (destPath).lastModified();
|
insilmaril@721
|
484 |
} else
|
insilmaril@721
|
485 |
{
|
insilmaril@721
|
486 |
QMessageBox::critical( 0, tr( "Critical Parse Error" ),
|
insilmaril@721
|
487 |
tr( handler->errorProtocol() ) );
|
insilmaril@721
|
488 |
// returnCode=1;
|
insilmaril@721
|
489 |
// Still return "success": the map maybe at least
|
insilmaril@721
|
490 |
// partially read by the parser
|
insilmaril@721
|
491 |
}
|
insilmaril@721
|
492 |
}
|
insilmaril@721
|
493 |
|
insilmaril@721
|
494 |
// Delete tmpZipDir
|
insilmaril@721
|
495 |
removeDir (QDir(tmpZipDir));
|
insilmaril@721
|
496 |
|
insilmaril@729
|
497 |
// Restore original zip state
|
insilmaril@729
|
498 |
zipped=zipped_org;
|
insilmaril@729
|
499 |
|
insilmaril@721
|
500 |
updateActions();
|
insilmaril@721
|
501 |
return err;
|
insilmaril@721
|
502 |
}
|
insilmaril@721
|
503 |
|
insilmaril@721
|
504 |
ErrorCode VymModel::save (const SaveMode &savemode)
|
insilmaril@721
|
505 |
{
|
insilmaril@721
|
506 |
QString tmpZipDir;
|
insilmaril@721
|
507 |
QString mapFileName;
|
insilmaril@721
|
508 |
QString safeFilePath;
|
insilmaril@721
|
509 |
|
insilmaril@721
|
510 |
ErrorCode err=success;
|
insilmaril@721
|
511 |
|
insilmaril@721
|
512 |
if (zipped)
|
insilmaril@721
|
513 |
// save as .xml
|
insilmaril@721
|
514 |
mapFileName=mapName+".xml";
|
insilmaril@721
|
515 |
else
|
insilmaril@721
|
516 |
// use name given by user, even if he chooses .doc
|
insilmaril@721
|
517 |
mapFileName=fileName;
|
insilmaril@721
|
518 |
|
insilmaril@721
|
519 |
// Look, if we should zip the data:
|
insilmaril@721
|
520 |
if (!zipped)
|
insilmaril@721
|
521 |
{
|
insilmaril@721
|
522 |
QMessageBox mb( vymName,
|
insilmaril@721
|
523 |
tr("The map %1\ndid not use the compressed "
|
insilmaril@721
|
524 |
"vym file format.\nWriting it uncompressed will also write images \n"
|
insilmaril@721
|
525 |
"and flags and thus may overwrite files in the "
|
insilmaril@721
|
526 |
"given directory\n\nDo you want to write the map").arg(filePath),
|
insilmaril@721
|
527 |
QMessageBox::Warning,
|
insilmaril@721
|
528 |
QMessageBox::Yes | QMessageBox::Default,
|
insilmaril@721
|
529 |
QMessageBox::No ,
|
insilmaril@721
|
530 |
QMessageBox::Cancel | QMessageBox::Escape);
|
insilmaril@721
|
531 |
mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
|
insilmaril@721
|
532 |
mb.setButtonText( QMessageBox::No, tr("uncompressed") );
|
insilmaril@721
|
533 |
mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
|
insilmaril@721
|
534 |
switch( mb.exec() )
|
insilmaril@721
|
535 |
{
|
insilmaril@721
|
536 |
case QMessageBox::Yes:
|
insilmaril@721
|
537 |
// save compressed (default file format)
|
insilmaril@721
|
538 |
zipped=true;
|
insilmaril@721
|
539 |
break;
|
insilmaril@721
|
540 |
case QMessageBox::No:
|
insilmaril@721
|
541 |
// save uncompressed
|
insilmaril@721
|
542 |
zipped=false;
|
insilmaril@721
|
543 |
break;
|
insilmaril@721
|
544 |
case QMessageBox::Cancel:
|
insilmaril@721
|
545 |
// do nothing
|
insilmaril@721
|
546 |
return aborted;
|
insilmaril@721
|
547 |
break;
|
insilmaril@721
|
548 |
}
|
insilmaril@721
|
549 |
}
|
insilmaril@721
|
550 |
|
insilmaril@721
|
551 |
// First backup existing file, we
|
insilmaril@721
|
552 |
// don't want to add to old zip archives
|
insilmaril@721
|
553 |
QFile f(destPath);
|
insilmaril@721
|
554 |
if (f.exists())
|
insilmaril@721
|
555 |
{
|
insilmaril@721
|
556 |
if ( settings.value ("/mapeditor/writeBackupFile").toBool())
|
insilmaril@721
|
557 |
{
|
insilmaril@721
|
558 |
QString backupFileName(destPath + "~");
|
insilmaril@721
|
559 |
QFile backupFile(backupFileName);
|
insilmaril@721
|
560 |
if (backupFile.exists() && !backupFile.remove())
|
insilmaril@721
|
561 |
{
|
insilmaril@721
|
562 |
QMessageBox::warning(0, tr("Save Error"),
|
insilmaril@721
|
563 |
tr("%1\ncould not be removed before saving").arg(backupFileName));
|
insilmaril@721
|
564 |
}
|
insilmaril@721
|
565 |
else if (!f.rename(backupFileName))
|
insilmaril@721
|
566 |
{
|
insilmaril@721
|
567 |
QMessageBox::warning(0, tr("Save Error"),
|
insilmaril@721
|
568 |
tr("%1\ncould not be renamed before saving").arg(destPath));
|
insilmaril@721
|
569 |
}
|
insilmaril@721
|
570 |
}
|
insilmaril@721
|
571 |
}
|
insilmaril@721
|
572 |
|
insilmaril@721
|
573 |
if (zipped)
|
insilmaril@721
|
574 |
{
|
insilmaril@721
|
575 |
// Create temporary directory for packing
|
insilmaril@721
|
576 |
bool ok;
|
insilmaril@721
|
577 |
tmpZipDir=makeTmpDir (ok,"vym-zip");
|
insilmaril@721
|
578 |
if (!ok)
|
insilmaril@721
|
579 |
{
|
insilmaril@721
|
580 |
QMessageBox::critical( 0, tr( "Critical Load Error" ),
|
insilmaril@721
|
581 |
tr("Couldn't create temporary directory before save\n"));
|
insilmaril@721
|
582 |
return aborted;
|
insilmaril@721
|
583 |
}
|
insilmaril@721
|
584 |
|
insilmaril@721
|
585 |
safeFilePath=filePath;
|
insilmaril@721
|
586 |
setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
|
insilmaril@721
|
587 |
} // zipped
|
insilmaril@721
|
588 |
|
insilmaril@721
|
589 |
// Create mapName and fileDir
|
insilmaril@721
|
590 |
makeSubDirs (fileDir);
|
insilmaril@721
|
591 |
|
insilmaril@721
|
592 |
QString saveFile;
|
insilmaril@721
|
593 |
if (savemode==CompleteMap || selection.isEmpty())
|
insilmaril@721
|
594 |
{
|
insilmaril@721
|
595 |
// Save complete map
|
insilmaril@721
|
596 |
saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
|
insilmaril@721
|
597 |
mapChanged=false;
|
insilmaril@721
|
598 |
mapUnsaved=false;
|
insilmaril@721
|
599 |
autosaveTimer->stop();
|
insilmaril@721
|
600 |
}
|
insilmaril@721
|
601 |
else
|
insilmaril@721
|
602 |
{
|
insilmaril@721
|
603 |
// Save part of map
|
insilmaril@735
|
604 |
if (selectionType()==TreeItem::Image)
|
insilmaril@721
|
605 |
saveFloatImage();
|
insilmaril@721
|
606 |
else
|
insilmaril@753
|
607 |
saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranchItem());
|
insilmaril@721
|
608 |
// TODO take care of multiselections
|
insilmaril@721
|
609 |
}
|
insilmaril@721
|
610 |
|
insilmaril@721
|
611 |
if (!saveStringToDisk(fileDir+mapFileName,saveFile))
|
insilmaril@721
|
612 |
{
|
insilmaril@721
|
613 |
err=aborted;
|
insilmaril@721
|
614 |
qWarning ("ME::saveStringToDisk failed!");
|
insilmaril@721
|
615 |
}
|
insilmaril@721
|
616 |
|
insilmaril@721
|
617 |
if (zipped)
|
insilmaril@721
|
618 |
{
|
insilmaril@721
|
619 |
// zip
|
insilmaril@721
|
620 |
if (err==success) err=zipDir (tmpZipDir,destPath);
|
insilmaril@721
|
621 |
|
insilmaril@721
|
622 |
// Delete tmpDir
|
insilmaril@721
|
623 |
removeDir (QDir(tmpZipDir));
|
insilmaril@721
|
624 |
|
insilmaril@721
|
625 |
// Restore original filepath outside of tmp zip dir
|
insilmaril@721
|
626 |
setFilePath (safeFilePath);
|
insilmaril@721
|
627 |
}
|
insilmaril@721
|
628 |
|
insilmaril@721
|
629 |
updateActions();
|
insilmaril@721
|
630 |
fileChangedTime=QFileInfo (destPath).lastModified();
|
insilmaril@721
|
631 |
return err;
|
insilmaril@721
|
632 |
}
|
insilmaril@721
|
633 |
|
insilmaril@721
|
634 |
void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
|
insilmaril@721
|
635 |
{
|
insilmaril@721
|
636 |
QString pathDir=path.left(path.findRev("/"));
|
insilmaril@721
|
637 |
QDir d(pathDir);
|
insilmaril@721
|
638 |
QFile file (path);
|
insilmaril@721
|
639 |
|
insilmaril@721
|
640 |
if (d.exists() )
|
insilmaril@721
|
641 |
{
|
insilmaril@721
|
642 |
// We need to parse saved XML data
|
insilmaril@721
|
643 |
parseVYMHandler handler;
|
insilmaril@721
|
644 |
QXmlInputSource source( file);
|
insilmaril@721
|
645 |
QXmlSimpleReader reader;
|
insilmaril@721
|
646 |
reader.setContentHandler( &handler );
|
insilmaril@721
|
647 |
reader.setErrorHandler( &handler );
|
insilmaril@721
|
648 |
handler.setModel ( this);
|
insilmaril@721
|
649 |
handler.setTmpDir ( pathDir ); // needed to load files with rel. path
|
insilmaril@721
|
650 |
if (undoSel.isEmpty())
|
insilmaril@721
|
651 |
{
|
insilmaril@721
|
652 |
unselect();
|
insilmaril@721
|
653 |
clear();
|
insilmaril@721
|
654 |
handler.setLoadMode (NewMap);
|
insilmaril@721
|
655 |
} else
|
insilmaril@721
|
656 |
{
|
insilmaril@721
|
657 |
select (undoSel);
|
insilmaril@721
|
658 |
handler.setLoadMode (ImportReplace);
|
insilmaril@721
|
659 |
}
|
insilmaril@721
|
660 |
blockReposition=true;
|
insilmaril@721
|
661 |
bool ok = reader.parse( source );
|
insilmaril@721
|
662 |
blockReposition=false;
|
insilmaril@721
|
663 |
if (! ok )
|
insilmaril@721
|
664 |
{
|
insilmaril@721
|
665 |
// This should never ever happen
|
insilmaril@721
|
666 |
QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
|
insilmaril@721
|
667 |
handler.errorProtocol());
|
insilmaril@721
|
668 |
}
|
insilmaril@721
|
669 |
} else
|
insilmaril@721
|
670 |
QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
|
insilmaril@721
|
671 |
}
|
insilmaril@721
|
672 |
|
insilmaril@721
|
673 |
void VymModel::addMapInsertInt (const QString &path, int pos)
|
insilmaril@721
|
674 |
{
|
insilmaril@750
|
675 |
/* FIXME-2 addMapInsertInt not ported yet
|
insilmaril@735
|
676 |
BranchObj *sel=getSelectedBranch();
|
insilmaril@721
|
677 |
if (sel)
|
insilmaril@721
|
678 |
{
|
insilmaril@721
|
679 |
QString pathDir=path.left(path.findRev("/"));
|
insilmaril@721
|
680 |
QDir d(pathDir);
|
insilmaril@721
|
681 |
QFile file (path);
|
insilmaril@721
|
682 |
|
insilmaril@721
|
683 |
if (d.exists() )
|
insilmaril@721
|
684 |
{
|
insilmaril@721
|
685 |
// We need to parse saved XML data
|
insilmaril@721
|
686 |
parseVYMHandler handler;
|
insilmaril@721
|
687 |
QXmlInputSource source( file);
|
insilmaril@721
|
688 |
QXmlSimpleReader reader;
|
insilmaril@721
|
689 |
reader.setContentHandler( &handler );
|
insilmaril@721
|
690 |
reader.setErrorHandler( &handler );
|
insilmaril@721
|
691 |
handler.setModel (this);
|
insilmaril@721
|
692 |
handler.setTmpDir ( pathDir ); // needed to load files with rel. path
|
insilmaril@721
|
693 |
handler.setLoadMode (ImportAdd);
|
insilmaril@721
|
694 |
blockReposition=true;
|
insilmaril@721
|
695 |
bool ok = reader.parse( source );
|
insilmaril@721
|
696 |
blockReposition=false;
|
insilmaril@721
|
697 |
if (! ok )
|
insilmaril@721
|
698 |
{
|
insilmaril@721
|
699 |
// This should never ever happen
|
insilmaril@721
|
700 |
QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
|
insilmaril@721
|
701 |
handler.errorProtocol());
|
insilmaril@721
|
702 |
}
|
insilmaril@721
|
703 |
if (sel->getDepth()>0)
|
insilmaril@721
|
704 |
sel->getLastBranch()->linkTo (sel,pos);
|
insilmaril@721
|
705 |
} else
|
insilmaril@721
|
706 |
QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
|
insilmaril@721
|
707 |
}
|
insilmaril@750
|
708 |
*/
|
insilmaril@721
|
709 |
}
|
insilmaril@721
|
710 |
|
insilmaril@721
|
711 |
FloatImageObj* VymModel::loadFloatImageInt (QString fn)
|
insilmaril@721
|
712 |
{
|
insilmaril@739
|
713 |
TreeItem *fi=createImage();
|
insilmaril@739
|
714 |
if (fi)
|
insilmaril@721
|
715 |
{
|
insilmaril@739
|
716 |
FloatImageObj *fio= ((FloatImageObj*)fi->getLMO());
|
insilmaril@739
|
717 |
fio->load (fn);
|
insilmaril@721
|
718 |
reposition();
|
insilmaril@721
|
719 |
return fio;
|
insilmaril@721
|
720 |
}
|
insilmaril@721
|
721 |
return NULL;
|
insilmaril@740
|
722 |
}
|
insilmaril@721
|
723 |
|
insilmaril@753
|
724 |
void VymModel::loadFloatImage () // FIXME-2
|
insilmaril@753
|
725 |
{
|
insilmaril@753
|
726 |
/*
|
insilmaril@735
|
727 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
728 |
if (bo)
|
insilmaril@721
|
729 |
{
|
insilmaril@721
|
730 |
|
insilmaril@721
|
731 |
Q3FileDialog *fd=new Q3FileDialog( NULL);
|
insilmaril@721
|
732 |
fd->setMode (Q3FileDialog::ExistingFiles);
|
insilmaril@721
|
733 |
fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
|
insilmaril@721
|
734 |
ImagePreview *p =new ImagePreview (fd);
|
insilmaril@721
|
735 |
fd->setContentsPreviewEnabled( TRUE );
|
insilmaril@721
|
736 |
fd->setContentsPreview( p, p );
|
insilmaril@721
|
737 |
fd->setPreviewMode( Q3FileDialog::Contents );
|
insilmaril@721
|
738 |
fd->setCaption(vymName+" - " +tr("Load image"));
|
insilmaril@721
|
739 |
fd->setDir (lastImageDir);
|
insilmaril@721
|
740 |
fd->show();
|
insilmaril@721
|
741 |
|
insilmaril@721
|
742 |
if ( fd->exec() == QDialog::Accepted )
|
insilmaril@721
|
743 |
{
|
insilmaril@721
|
744 |
// TODO loadFIO in QT4 use: lastImageDir=fd->directory();
|
insilmaril@721
|
745 |
lastImageDir=QDir (fd->dirPath());
|
insilmaril@721
|
746 |
QString s;
|
insilmaril@721
|
747 |
FloatImageObj *fio;
|
insilmaril@721
|
748 |
for (int j=0; j<fd->selectedFiles().count(); j++)
|
insilmaril@721
|
749 |
{
|
insilmaril@721
|
750 |
s=fd->selectedFiles().at(j);
|
insilmaril@721
|
751 |
fio=loadFloatImageInt (s);
|
insilmaril@721
|
752 |
if (fio)
|
insilmaril@721
|
753 |
saveState(
|
insilmaril@721
|
754 |
(LinkableMapObj*)fio,
|
insilmaril@721
|
755 |
"delete ()",
|
insilmaril@721
|
756 |
bo,
|
insilmaril@721
|
757 |
QString ("loadImage (%1)").arg(s ),
|
insilmaril@721
|
758 |
QString("Add image %1 to %2").arg(s).arg(getObjectName(bo))
|
insilmaril@721
|
759 |
);
|
insilmaril@721
|
760 |
else
|
insilmaril@721
|
761 |
// TODO loadFIO error handling
|
insilmaril@721
|
762 |
qWarning ("Failed to load "+s);
|
insilmaril@721
|
763 |
}
|
insilmaril@721
|
764 |
}
|
insilmaril@721
|
765 |
delete (p);
|
insilmaril@721
|
766 |
delete (fd);
|
insilmaril@721
|
767 |
}
|
insilmaril@753
|
768 |
*/
|
insilmaril@721
|
769 |
}
|
insilmaril@721
|
770 |
|
insilmaril@721
|
771 |
void VymModel::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
|
insilmaril@721
|
772 |
{
|
insilmaril@721
|
773 |
fio->save (fn,type);
|
insilmaril@721
|
774 |
}
|
insilmaril@721
|
775 |
|
insilmaril@721
|
776 |
void VymModel::saveFloatImage ()
|
insilmaril@721
|
777 |
{
|
insilmaril@721
|
778 |
FloatImageObj *fio=selection.getFloatImage();
|
insilmaril@721
|
779 |
if (fio)
|
insilmaril@721
|
780 |
{
|
insilmaril@721
|
781 |
QFileDialog *fd=new QFileDialog( NULL);
|
insilmaril@721
|
782 |
fd->setFilters (imageIO.getFilters());
|
insilmaril@721
|
783 |
fd->setCaption(vymName+" - " +tr("Save image"));
|
insilmaril@721
|
784 |
fd->setFileMode( QFileDialog::AnyFile );
|
insilmaril@721
|
785 |
fd->setDirectory (lastImageDir);
|
insilmaril@721
|
786 |
// fd->setSelection (fio->getOriginalFilename());
|
insilmaril@721
|
787 |
fd->show();
|
insilmaril@721
|
788 |
|
insilmaril@721
|
789 |
QString fn;
|
insilmaril@721
|
790 |
if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
|
insilmaril@721
|
791 |
{
|
insilmaril@721
|
792 |
fn=fd->selectedFiles().at(0);
|
insilmaril@721
|
793 |
if (QFile (fn).exists() )
|
insilmaril@721
|
794 |
{
|
insilmaril@721
|
795 |
QMessageBox mb( vymName,
|
insilmaril@721
|
796 |
tr("The file %1 exists already.\n"
|
insilmaril@721
|
797 |
"Do you want to overwrite it?").arg(fn),
|
insilmaril@721
|
798 |
QMessageBox::Warning,
|
insilmaril@721
|
799 |
QMessageBox::Yes | QMessageBox::Default,
|
insilmaril@721
|
800 |
QMessageBox::Cancel | QMessageBox::Escape,
|
insilmaril@721
|
801 |
QMessageBox::NoButton );
|
insilmaril@721
|
802 |
|
insilmaril@721
|
803 |
mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
|
insilmaril@721
|
804 |
mb.setButtonText( QMessageBox::No, tr("Cancel"));
|
insilmaril@721
|
805 |
switch( mb.exec() )
|
insilmaril@721
|
806 |
{
|
insilmaril@721
|
807 |
case QMessageBox::Yes:
|
insilmaril@721
|
808 |
// save
|
insilmaril@721
|
809 |
break;
|
insilmaril@721
|
810 |
case QMessageBox::Cancel:
|
insilmaril@721
|
811 |
// do nothing
|
insilmaril@721
|
812 |
delete (fd);
|
insilmaril@721
|
813 |
return;
|
insilmaril@721
|
814 |
break;
|
insilmaril@721
|
815 |
}
|
insilmaril@721
|
816 |
}
|
insilmaril@721
|
817 |
saveFloatImageInt (fio,fd->selectedFilter(),fn );
|
insilmaril@721
|
818 |
}
|
insilmaril@721
|
819 |
delete (fd);
|
insilmaril@721
|
820 |
}
|
insilmaril@721
|
821 |
}
|
insilmaril@721
|
822 |
|
insilmaril@721
|
823 |
|
insilmaril@721
|
824 |
void VymModel::importDirInt(BranchObj *dst, QDir d)
|
insilmaril@721
|
825 |
{
|
insilmaril@750
|
826 |
/* FIXME-2 importDirInt not ported yet
|
insilmaril@735
|
827 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
828 |
if (bo)
|
insilmaril@721
|
829 |
{
|
insilmaril@721
|
830 |
// Traverse directories
|
insilmaril@721
|
831 |
d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
|
insilmaril@721
|
832 |
QFileInfoList list = d.entryInfoList();
|
insilmaril@721
|
833 |
QFileInfo fi;
|
insilmaril@721
|
834 |
|
insilmaril@721
|
835 |
for (int i = 0; i < list.size(); ++i)
|
insilmaril@721
|
836 |
{
|
insilmaril@721
|
837 |
fi=list.at(i);
|
insilmaril@721
|
838 |
if (fi.fileName() != "." && fi.fileName() != ".." )
|
insilmaril@721
|
839 |
{
|
insilmaril@721
|
840 |
dst->addBranch();
|
insilmaril@721
|
841 |
bo=dst->getLastBranch();
|
insilmaril@749
|
842 |
BranchItem *bi=(BranchItem*)(bo->getTreeItem());
|
insilmaril@749
|
843 |
bi->setHeading (fi.fileName() ); // FIXME-3 check this
|
insilmaril@721
|
844 |
bo->setColor (QColor("blue"));
|
insilmaril@749
|
845 |
bi->toggleScroll();
|
insilmaril@721
|
846 |
if ( !d.cd(fi.fileName()) )
|
insilmaril@721
|
847 |
QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
|
insilmaril@721
|
848 |
else
|
insilmaril@721
|
849 |
{
|
insilmaril@721
|
850 |
// Recursively add subdirs
|
insilmaril@721
|
851 |
importDirInt (bo,d);
|
insilmaril@721
|
852 |
d.cdUp();
|
insilmaril@721
|
853 |
}
|
insilmaril@721
|
854 |
}
|
insilmaril@721
|
855 |
}
|
insilmaril@721
|
856 |
// Traverse files
|
insilmaril@721
|
857 |
d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
|
insilmaril@721
|
858 |
list = d.entryInfoList();
|
insilmaril@721
|
859 |
|
insilmaril@721
|
860 |
for (int i = 0; i < list.size(); ++i)
|
insilmaril@721
|
861 |
{
|
insilmaril@721
|
862 |
fi=list.at(i);
|
insilmaril@721
|
863 |
dst->addBranch();
|
insilmaril@721
|
864 |
bo=dst->getLastBranch();
|
insilmaril@721
|
865 |
bo->setHeading (fi.fileName() );
|
insilmaril@721
|
866 |
bo->setColor (QColor("black"));
|
insilmaril@721
|
867 |
if (fi.fileName().right(4) == ".vym" )
|
insilmaril@721
|
868 |
bo->setVymLink (fi.filePath());
|
insilmaril@721
|
869 |
}
|
insilmaril@721
|
870 |
}
|
insilmaril@750
|
871 |
*/
|
insilmaril@721
|
872 |
}
|
insilmaril@721
|
873 |
|
insilmaril@753
|
874 |
void VymModel::importDirInt (const QString &s) // FIXME-2
|
insilmaril@753
|
875 |
{
|
insilmaril@753
|
876 |
/*
|
insilmaril@735
|
877 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
878 |
if (bo)
|
insilmaril@721
|
879 |
{
|
insilmaril@721
|
880 |
saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
|
insilmaril@721
|
881 |
|
insilmaril@721
|
882 |
QDir d(s);
|
insilmaril@721
|
883 |
importDirInt (bo,d);
|
insilmaril@721
|
884 |
}
|
insilmaril@753
|
885 |
*/
|
insilmaril@721
|
886 |
}
|
insilmaril@721
|
887 |
|
insilmaril@753
|
888 |
void VymModel::importDir() //FIXME-2
|
insilmaril@753
|
889 |
{
|
insilmaril@753
|
890 |
/*
|
insilmaril@735
|
891 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
892 |
if (bo)
|
insilmaril@721
|
893 |
{
|
insilmaril@721
|
894 |
QStringList filters;
|
insilmaril@721
|
895 |
filters <<"VYM map (*.vym)";
|
insilmaril@721
|
896 |
QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
|
insilmaril@721
|
897 |
fd->setMode (QFileDialog::DirectoryOnly);
|
insilmaril@721
|
898 |
fd->setFilters (filters);
|
insilmaril@721
|
899 |
fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
|
insilmaril@721
|
900 |
fd->show();
|
insilmaril@721
|
901 |
|
insilmaril@721
|
902 |
QString fn;
|
insilmaril@721
|
903 |
if ( fd->exec() == QDialog::Accepted )
|
insilmaril@721
|
904 |
{
|
insilmaril@721
|
905 |
importDirInt (fd->selectedFile() );
|
insilmaril@721
|
906 |
reposition();
|
insilmaril@746
|
907 |
//FIXME-3 VM needed? scene()->update();
|
insilmaril@721
|
908 |
}
|
insilmaril@721
|
909 |
}
|
insilmaril@753
|
910 |
*/
|
insilmaril@721
|
911 |
}
|
insilmaril@721
|
912 |
|
insilmaril@721
|
913 |
|
insilmaril@721
|
914 |
void VymModel::autosave()
|
insilmaril@721
|
915 |
{
|
insilmaril@742
|
916 |
if (filePath=="")
|
insilmaril@742
|
917 |
{
|
insilmaril@742
|
918 |
if (debug)
|
insilmaril@742
|
919 |
cout << "VymModel::autosave rejected due to missing filePath\n";
|
insilmaril@742
|
920 |
}
|
insilmaril@742
|
921 |
|
insilmaril@721
|
922 |
QDateTime now=QDateTime().currentDateTime();
|
insilmaril@721
|
923 |
|
insilmaril@721
|
924 |
// Disable autosave, while we have gone back in history
|
insilmaril@721
|
925 |
int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
|
insilmaril@721
|
926 |
if (redosAvail>0) return;
|
insilmaril@721
|
927 |
|
insilmaril@721
|
928 |
// Also disable autosave for new map without filename
|
insilmaril@721
|
929 |
if (filePath.isEmpty()) return;
|
insilmaril@721
|
930 |
|
insilmaril@721
|
931 |
|
insilmaril@742
|
932 |
if (mapUnsaved &&mapChanged && settings.value ("/mainwindow/autosave/use",true).toBool() )
|
insilmaril@721
|
933 |
{
|
insilmaril@721
|
934 |
if (QFileInfo(filePath).lastModified()<=fileChangedTime)
|
insilmaril@721
|
935 |
mainWindow->fileSave (this);
|
insilmaril@721
|
936 |
else
|
insilmaril@721
|
937 |
if (debug)
|
insilmaril@721
|
938 |
cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
|
insilmaril@721
|
939 |
|
insilmaril@721
|
940 |
}
|
insilmaril@721
|
941 |
}
|
insilmaril@721
|
942 |
|
insilmaril@721
|
943 |
void VymModel::fileChanged()
|
insilmaril@721
|
944 |
{
|
insilmaril@721
|
945 |
// Check if file on disk has changed meanwhile
|
insilmaril@721
|
946 |
if (!filePath.isEmpty())
|
insilmaril@721
|
947 |
{
|
insilmaril@721
|
948 |
QDateTime tmod=QFileInfo (filePath).lastModified();
|
insilmaril@721
|
949 |
if (tmod>fileChangedTime)
|
insilmaril@721
|
950 |
{
|
insilmaril@746
|
951 |
// FIXME-2 VM switch to current mapeditor and finish lineedits...
|
insilmaril@721
|
952 |
QMessageBox mb( vymName,
|
insilmaril@721
|
953 |
tr("The file of the map on disk has changed:\n\n"
|
insilmaril@721
|
954 |
" %1\n\nDo you want to reload that map with the new file?").arg(filePath),
|
insilmaril@721
|
955 |
QMessageBox::Question,
|
insilmaril@721
|
956 |
QMessageBox::Yes ,
|
insilmaril@721
|
957 |
QMessageBox::Cancel | QMessageBox::Default,
|
insilmaril@721
|
958 |
QMessageBox::NoButton );
|
insilmaril@721
|
959 |
|
insilmaril@721
|
960 |
mb.setButtonText( QMessageBox::Yes, tr("Reload"));
|
insilmaril@721
|
961 |
mb.setButtonText( QMessageBox::No, tr("Ignore"));
|
insilmaril@721
|
962 |
switch( mb.exec() )
|
insilmaril@721
|
963 |
{
|
insilmaril@721
|
964 |
case QMessageBox::Yes:
|
insilmaril@721
|
965 |
// Reload map
|
insilmaril@721
|
966 |
load (filePath,NewMap,fileType);
|
insilmaril@721
|
967 |
case QMessageBox::Cancel:
|
insilmaril@721
|
968 |
fileChangedTime=tmod; // allow autosave to overwrite newer file!
|
insilmaril@721
|
969 |
}
|
insilmaril@721
|
970 |
}
|
insilmaril@721
|
971 |
}
|
insilmaril@721
|
972 |
}
|
insilmaril@721
|
973 |
|
insilmaril@721
|
974 |
bool VymModel::isDefault()
|
insilmaril@721
|
975 |
{
|
insilmaril@721
|
976 |
return mapDefault;
|
insilmaril@721
|
977 |
}
|
insilmaril@721
|
978 |
|
insilmaril@721
|
979 |
void VymModel::makeDefault()
|
insilmaril@721
|
980 |
{
|
insilmaril@721
|
981 |
mapChanged=false;
|
insilmaril@721
|
982 |
mapDefault=true;
|
insilmaril@721
|
983 |
}
|
insilmaril@721
|
984 |
|
insilmaril@721
|
985 |
bool VymModel::hasChanged()
|
insilmaril@721
|
986 |
{
|
insilmaril@721
|
987 |
return mapChanged;
|
insilmaril@721
|
988 |
}
|
insilmaril@721
|
989 |
|
insilmaril@721
|
990 |
void VymModel::setChanged()
|
insilmaril@721
|
991 |
{
|
insilmaril@721
|
992 |
if (!mapChanged)
|
insilmaril@742
|
993 |
autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
|
insilmaril@721
|
994 |
mapChanged=true;
|
insilmaril@721
|
995 |
mapDefault=false;
|
insilmaril@721
|
996 |
mapUnsaved=true;
|
insilmaril@761
|
997 |
latestAddedItem=NULL;
|
insilmaril@721
|
998 |
findReset();
|
insilmaril@721
|
999 |
}
|
insilmaril@721
|
1000 |
|
insilmaril@753
|
1001 |
QString VymModel::getObjectName (const LinkableMapObj *lmo) // FIXME-3 should be obsolete
|
insilmaril@721
|
1002 |
{
|
insilmaril@721
|
1003 |
QString s;
|
insilmaril@721
|
1004 |
if (!lmo) return QString("Error: NULL has no name!");
|
insilmaril@721
|
1005 |
|
insilmaril@721
|
1006 |
if ((typeid(*lmo) == typeid(BranchObj) ||
|
insilmaril@721
|
1007 |
typeid(*lmo) == typeid(MapCenterObj)))
|
insilmaril@721
|
1008 |
{
|
insilmaril@721
|
1009 |
|
insilmaril@753
|
1010 |
s=lmo->getTreeItem()->getHeading();
|
insilmaril@721
|
1011 |
if (s=="") s="unnamed";
|
insilmaril@721
|
1012 |
return QString("branch (%1)").arg(s);
|
insilmaril@721
|
1013 |
}
|
insilmaril@721
|
1014 |
if ((typeid(*lmo) == typeid(FloatImageObj) ))
|
insilmaril@721
|
1015 |
return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
|
insilmaril@721
|
1016 |
return QString("Unknown type has no name!");
|
insilmaril@721
|
1017 |
}
|
insilmaril@721
|
1018 |
|
insilmaril@753
|
1019 |
|
insilmaril@753
|
1020 |
QString VymModel::getObjectName (const TreeItem *ti)
|
insilmaril@753
|
1021 |
{
|
insilmaril@753
|
1022 |
QString s;
|
insilmaril@753
|
1023 |
if (!ti) return QString("Error: NULL has no name!");
|
insilmaril@753
|
1024 |
|
insilmaril@753
|
1025 |
if (ti->isBranchLikeType() )
|
insilmaril@753
|
1026 |
{
|
insilmaril@753
|
1027 |
s=ti->getHeading();
|
insilmaril@753
|
1028 |
if (s=="") s="unnamed";
|
insilmaril@753
|
1029 |
return QString("branch (%1)").arg(s);
|
insilmaril@753
|
1030 |
}
|
insilmaril@753
|
1031 |
/* FIXME-2 move floatimage to TreeModel first
|
insilmaril@753
|
1032 |
if (type==TreeItem::Image)
|
insilmaril@753
|
1033 |
return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
|
insilmaril@753
|
1034 |
*/
|
insilmaril@753
|
1035 |
return QString("Unknown type has no name!");
|
insilmaril@753
|
1036 |
}
|
insilmaril@753
|
1037 |
|
insilmaril@721
|
1038 |
void VymModel::redo()
|
insilmaril@721
|
1039 |
{
|
insilmaril@721
|
1040 |
// Can we undo at all?
|
insilmaril@721
|
1041 |
if (redosAvail<1) return;
|
insilmaril@721
|
1042 |
|
insilmaril@721
|
1043 |
bool blockSaveStateOrg=blockSaveState;
|
insilmaril@721
|
1044 |
blockSaveState=true;
|
insilmaril@721
|
1045 |
|
insilmaril@721
|
1046 |
redosAvail--;
|
insilmaril@721
|
1047 |
|
insilmaril@721
|
1048 |
if (undosAvail<stepsTotal) undosAvail++;
|
insilmaril@721
|
1049 |
curStep++;
|
insilmaril@721
|
1050 |
if (curStep>stepsTotal) curStep=1;
|
insilmaril@721
|
1051 |
QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
|
insilmaril@721
|
1052 |
QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
|
insilmaril@721
|
1053 |
QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
|
insilmaril@721
|
1054 |
QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
|
insilmaril@721
|
1055 |
QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
|
insilmaril@721
|
1056 |
QString version=undoSet.readEntry ("/history/version");
|
insilmaril@721
|
1057 |
|
insilmaril@721
|
1058 |
/* TODO Maybe check for version, if we save the history
|
insilmaril@721
|
1059 |
if (!checkVersion(version))
|
insilmaril@721
|
1060 |
QMessageBox::warning(0,tr("Warning"),
|
insilmaril@721
|
1061 |
tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
|
insilmaril@721
|
1062 |
*/
|
insilmaril@721
|
1063 |
|
insilmaril@721
|
1064 |
// Find out current undo directory
|
insilmaril@721
|
1065 |
QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
|
insilmaril@721
|
1066 |
|
insilmaril@721
|
1067 |
if (debug)
|
insilmaril@721
|
1068 |
{
|
insilmaril@721
|
1069 |
cout << "VymModel::redo() begin\n";
|
insilmaril@721
|
1070 |
cout << " undosAvail="<<undosAvail<<endl;
|
insilmaril@721
|
1071 |
cout << " redosAvail="<<redosAvail<<endl;
|
insilmaril@721
|
1072 |
cout << " curStep="<<curStep<<endl;
|
insilmaril@721
|
1073 |
cout << " ---------------------------"<<endl;
|
insilmaril@721
|
1074 |
cout << " comment="<<comment.toStdString()<<endl;
|
insilmaril@721
|
1075 |
cout << " undoCom="<<undoCommand.toStdString()<<endl;
|
insilmaril@721
|
1076 |
cout << " undoSel="<<undoSelection.toStdString()<<endl;
|
insilmaril@721
|
1077 |
cout << " redoCom="<<redoCommand.toStdString()<<endl;
|
insilmaril@721
|
1078 |
cout << " redoSel="<<redoSelection.toStdString()<<endl;
|
insilmaril@721
|
1079 |
cout << " ---------------------------"<<endl<<endl;
|
insilmaril@721
|
1080 |
}
|
insilmaril@721
|
1081 |
|
insilmaril@721
|
1082 |
// select object before redo
|
insilmaril@721
|
1083 |
if (!redoSelection.isEmpty())
|
insilmaril@721
|
1084 |
select (redoSelection);
|
insilmaril@721
|
1085 |
|
insilmaril@721
|
1086 |
|
insilmaril@721
|
1087 |
parseAtom (redoCommand);
|
insilmaril@721
|
1088 |
reposition();
|
insilmaril@721
|
1089 |
|
insilmaril@721
|
1090 |
blockSaveState=blockSaveStateOrg;
|
insilmaril@721
|
1091 |
|
insilmaril@721
|
1092 |
undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
|
insilmaril@721
|
1093 |
undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
|
insilmaril@721
|
1094 |
undoSet.setEntry ("/history/curStep",QString::number(curStep));
|
insilmaril@721
|
1095 |
undoSet.writeSettings(histPath);
|
insilmaril@721
|
1096 |
|
insilmaril@721
|
1097 |
mainWindow->updateHistory (undoSet);
|
insilmaril@721
|
1098 |
updateActions();
|
insilmaril@721
|
1099 |
|
insilmaril@721
|
1100 |
/* TODO remove testing
|
insilmaril@721
|
1101 |
cout << "ME::redo() end\n";
|
insilmaril@721
|
1102 |
cout << " undosAvail="<<undosAvail<<endl;
|
insilmaril@721
|
1103 |
cout << " redosAvail="<<redosAvail<<endl;
|
insilmaril@721
|
1104 |
cout << " curStep="<<curStep<<endl;
|
insilmaril@721
|
1105 |
cout << " ---------------------------"<<endl<<endl;
|
insilmaril@721
|
1106 |
*/
|
insilmaril@721
|
1107 |
|
insilmaril@721
|
1108 |
|
insilmaril@721
|
1109 |
}
|
insilmaril@721
|
1110 |
|
insilmaril@721
|
1111 |
bool VymModel::isRedoAvailable()
|
insilmaril@721
|
1112 |
{
|
insilmaril@721
|
1113 |
if (undoSet.readNumEntry("/history/redosAvail",0)>0)
|
insilmaril@721
|
1114 |
return true;
|
insilmaril@721
|
1115 |
else
|
insilmaril@721
|
1116 |
return false;
|
insilmaril@721
|
1117 |
}
|
insilmaril@721
|
1118 |
|
insilmaril@721
|
1119 |
void VymModel::undo()
|
insilmaril@721
|
1120 |
{
|
insilmaril@721
|
1121 |
// Can we undo at all?
|
insilmaril@721
|
1122 |
if (undosAvail<1) return;
|
insilmaril@721
|
1123 |
|
insilmaril@721
|
1124 |
mainWindow->statusMessage (tr("Autosave disabled during undo."));
|
insilmaril@721
|
1125 |
|
insilmaril@721
|
1126 |
bool blockSaveStateOrg=blockSaveState;
|
insilmaril@721
|
1127 |
blockSaveState=true;
|
insilmaril@721
|
1128 |
|
insilmaril@721
|
1129 |
QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
|
insilmaril@721
|
1130 |
QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
|
insilmaril@721
|
1131 |
QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
|
insilmaril@721
|
1132 |
QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
|
insilmaril@721
|
1133 |
QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
|
insilmaril@721
|
1134 |
QString version=undoSet.readEntry ("/history/version");
|
insilmaril@721
|
1135 |
|
insilmaril@721
|
1136 |
/* TODO Maybe check for version, if we save the history
|
insilmaril@721
|
1137 |
if (!checkVersion(version))
|
insilmaril@721
|
1138 |
QMessageBox::warning(0,tr("Warning"),
|
insilmaril@721
|
1139 |
tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
|
insilmaril@721
|
1140 |
*/
|
insilmaril@721
|
1141 |
|
insilmaril@721
|
1142 |
// Find out current undo directory
|
insilmaril@721
|
1143 |
QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
|
insilmaril@721
|
1144 |
|
insilmaril@721
|
1145 |
// select object before undo
|
insilmaril@721
|
1146 |
if (!undoSelection.isEmpty())
|
insilmaril@721
|
1147 |
select (undoSelection);
|
insilmaril@721
|
1148 |
|
insilmaril@721
|
1149 |
if (debug)
|
insilmaril@721
|
1150 |
{
|
insilmaril@721
|
1151 |
cout << "VymModel::undo() begin\n";
|
insilmaril@721
|
1152 |
cout << " undosAvail="<<undosAvail<<endl;
|
insilmaril@721
|
1153 |
cout << " redosAvail="<<redosAvail<<endl;
|
insilmaril@721
|
1154 |
cout << " curStep="<<curStep<<endl;
|
insilmaril@721
|
1155 |
cout << " ---------------------------"<<endl;
|
insilmaril@721
|
1156 |
cout << " comment="<<comment.toStdString()<<endl;
|
insilmaril@721
|
1157 |
cout << " undoCom="<<undoCommand.toStdString()<<endl;
|
insilmaril@721
|
1158 |
cout << " undoSel="<<undoSelection.toStdString()<<endl;
|
insilmaril@721
|
1159 |
cout << " redoCom="<<redoCommand.toStdString()<<endl;
|
insilmaril@721
|
1160 |
cout << " redoSel="<<redoSelection.toStdString()<<endl;
|
insilmaril@721
|
1161 |
cout << " ---------------------------"<<endl<<endl;
|
insilmaril@721
|
1162 |
}
|
insilmaril@721
|
1163 |
parseAtom (undoCommand);
|
insilmaril@721
|
1164 |
reposition();
|
insilmaril@721
|
1165 |
|
insilmaril@721
|
1166 |
undosAvail--;
|
insilmaril@721
|
1167 |
curStep--;
|
insilmaril@721
|
1168 |
if (curStep<1) curStep=stepsTotal;
|
insilmaril@721
|
1169 |
|
insilmaril@721
|
1170 |
redosAvail++;
|
insilmaril@721
|
1171 |
|
insilmaril@721
|
1172 |
blockSaveState=blockSaveStateOrg;
|
insilmaril@721
|
1173 |
/* TODO remove testing
|
insilmaril@721
|
1174 |
cout << "VymModel::undo() end\n";
|
insilmaril@721
|
1175 |
cout << " undosAvail="<<undosAvail<<endl;
|
insilmaril@721
|
1176 |
cout << " redosAvail="<<redosAvail<<endl;
|
insilmaril@721
|
1177 |
cout << " curStep="<<curStep<<endl;
|
insilmaril@721
|
1178 |
cout << " ---------------------------"<<endl<<endl;
|
insilmaril@721
|
1179 |
*/
|
insilmaril@721
|
1180 |
|
insilmaril@721
|
1181 |
undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
|
insilmaril@721
|
1182 |
undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
|
insilmaril@721
|
1183 |
undoSet.setEntry ("/history/curStep",QString::number(curStep));
|
insilmaril@721
|
1184 |
undoSet.writeSettings(histPath);
|
insilmaril@721
|
1185 |
|
insilmaril@721
|
1186 |
mainWindow->updateHistory (undoSet);
|
insilmaril@721
|
1187 |
updateActions();
|
insilmaril@721
|
1188 |
selection.update();
|
insilmaril@721
|
1189 |
ensureSelectionVisible();
|
insilmaril@721
|
1190 |
}
|
insilmaril@721
|
1191 |
|
insilmaril@721
|
1192 |
bool VymModel::isUndoAvailable()
|
insilmaril@721
|
1193 |
{
|
insilmaril@721
|
1194 |
if (undoSet.readNumEntry("/history/undosAvail",0)>0)
|
insilmaril@721
|
1195 |
return true;
|
insilmaril@721
|
1196 |
else
|
insilmaril@721
|
1197 |
return false;
|
insilmaril@721
|
1198 |
}
|
insilmaril@721
|
1199 |
|
insilmaril@721
|
1200 |
void VymModel::gotoHistoryStep (int i)
|
insilmaril@721
|
1201 |
{
|
insilmaril@721
|
1202 |
// Restore variables
|
insilmaril@721
|
1203 |
int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
|
insilmaril@721
|
1204 |
int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
|
insilmaril@721
|
1205 |
|
insilmaril@721
|
1206 |
if (i<0) i=undosAvail+redosAvail;
|
insilmaril@721
|
1207 |
|
insilmaril@721
|
1208 |
// Clicking above current step makes us undo things
|
insilmaril@721
|
1209 |
if (i<undosAvail)
|
insilmaril@721
|
1210 |
{
|
insilmaril@721
|
1211 |
for (int j=0; j<undosAvail-i; j++) undo();
|
insilmaril@721
|
1212 |
return;
|
insilmaril@721
|
1213 |
}
|
insilmaril@721
|
1214 |
// Clicking below current step makes us redo things
|
insilmaril@721
|
1215 |
if (i>undosAvail)
|
insilmaril@721
|
1216 |
for (int j=undosAvail; j<i; j++)
|
insilmaril@721
|
1217 |
{
|
insilmaril@721
|
1218 |
if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
|
insilmaril@721
|
1219 |
redo();
|
insilmaril@721
|
1220 |
}
|
insilmaril@721
|
1221 |
|
insilmaril@721
|
1222 |
// And ignore clicking the current row ;-)
|
insilmaril@721
|
1223 |
}
|
insilmaril@721
|
1224 |
|
insilmaril@721
|
1225 |
|
insilmaril@721
|
1226 |
QString VymModel::getHistoryPath()
|
insilmaril@721
|
1227 |
{
|
insilmaril@721
|
1228 |
QString histName(QString("history-%1").arg(curStep));
|
insilmaril@721
|
1229 |
return (tmpMapDir+"/"+histName);
|
insilmaril@721
|
1230 |
}
|
insilmaril@721
|
1231 |
|
insilmaril@753
|
1232 |
void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
|
insilmaril@721
|
1233 |
{
|
insilmaril@746
|
1234 |
sendData(redoCom); //FIXME-3 testing
|
insilmaril@721
|
1235 |
|
insilmaril@721
|
1236 |
// Main saveState
|
insilmaril@721
|
1237 |
|
insilmaril@721
|
1238 |
|
insilmaril@721
|
1239 |
if (blockSaveState) return;
|
insilmaril@721
|
1240 |
|
insilmaril@760
|
1241 |
if (debug) cout << "VM::saveState() for "<<qPrintable (mapName)<<endl;
|
insilmaril@721
|
1242 |
|
insilmaril@721
|
1243 |
// Find out current undo directory
|
insilmaril@721
|
1244 |
if (undosAvail<stepsTotal) undosAvail++;
|
insilmaril@721
|
1245 |
curStep++;
|
insilmaril@721
|
1246 |
if (curStep>stepsTotal) curStep=1;
|
insilmaril@721
|
1247 |
|
insilmaril@721
|
1248 |
QString backupXML="";
|
insilmaril@721
|
1249 |
QString histDir=getHistoryPath();
|
insilmaril@721
|
1250 |
QString bakMapPath=histDir+"/map.xml";
|
insilmaril@721
|
1251 |
|
insilmaril@721
|
1252 |
// Create histDir if not available
|
insilmaril@721
|
1253 |
QDir d(histDir);
|
insilmaril@721
|
1254 |
if (!d.exists())
|
insilmaril@721
|
1255 |
makeSubDirs (histDir);
|
insilmaril@721
|
1256 |
|
insilmaril@721
|
1257 |
// Save depending on how much needs to be saved
|
insilmaril@721
|
1258 |
if (saveSel)
|
insilmaril@721
|
1259 |
backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
|
insilmaril@721
|
1260 |
|
insilmaril@721
|
1261 |
QString undoCommand="";
|
insilmaril@721
|
1262 |
if (savemode==UndoCommand)
|
insilmaril@721
|
1263 |
{
|
insilmaril@721
|
1264 |
undoCommand=undoCom;
|
insilmaril@721
|
1265 |
}
|
insilmaril@721
|
1266 |
else if (savemode==PartOfMap )
|
insilmaril@721
|
1267 |
{
|
insilmaril@721
|
1268 |
undoCommand=undoCom;
|
insilmaril@721
|
1269 |
undoCommand.replace ("PATH",bakMapPath);
|
insilmaril@721
|
1270 |
}
|
insilmaril@721
|
1271 |
|
insilmaril@760
|
1272 |
|
insilmaril@721
|
1273 |
if (!backupXML.isEmpty())
|
insilmaril@721
|
1274 |
// Write XML Data to disk
|
insilmaril@721
|
1275 |
saveStringToDisk (bakMapPath,backupXML);
|
insilmaril@721
|
1276 |
|
insilmaril@721
|
1277 |
// We would have to save all actions in a tree, to keep track of
|
insilmaril@721
|
1278 |
// possible redos after a action. Possible, but we are too lazy: forget about redos.
|
insilmaril@721
|
1279 |
redosAvail=0;
|
insilmaril@721
|
1280 |
|
insilmaril@721
|
1281 |
// Write the current state to disk
|
insilmaril@721
|
1282 |
undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
|
insilmaril@721
|
1283 |
undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
|
insilmaril@721
|
1284 |
undoSet.setEntry ("/history/curStep",QString::number(curStep));
|
insilmaril@721
|
1285 |
undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
|
insilmaril@721
|
1286 |
undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
|
insilmaril@721
|
1287 |
undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
|
insilmaril@721
|
1288 |
undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
|
insilmaril@721
|
1289 |
undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
|
insilmaril@721
|
1290 |
undoSet.setEntry (QString("/history/version"),vymVersion);
|
insilmaril@721
|
1291 |
undoSet.writeSettings(histPath);
|
insilmaril@721
|
1292 |
|
insilmaril@721
|
1293 |
if (debug)
|
insilmaril@721
|
1294 |
{
|
insilmaril@721
|
1295 |
// TODO remove after testing
|
insilmaril@721
|
1296 |
//cout << " into="<< histPath.toStdString()<<endl;
|
insilmaril@721
|
1297 |
cout << " stepsTotal="<<stepsTotal<<
|
insilmaril@721
|
1298 |
", undosAvail="<<undosAvail<<
|
insilmaril@721
|
1299 |
", redosAvail="<<redosAvail<<
|
insilmaril@721
|
1300 |
", curStep="<<curStep<<endl;
|
insilmaril@721
|
1301 |
cout << " ---------------------------"<<endl;
|
insilmaril@721
|
1302 |
cout << " comment="<<comment.toStdString()<<endl;
|
insilmaril@721
|
1303 |
cout << " undoCom="<<undoCommand.toStdString()<<endl;
|
insilmaril@721
|
1304 |
cout << " undoSel="<<undoSelection.toStdString()<<endl;
|
insilmaril@721
|
1305 |
cout << " redoCom="<<redoCom.toStdString()<<endl;
|
insilmaril@721
|
1306 |
cout << " redoSel="<<redoSelection.toStdString()<<endl;
|
insilmaril@721
|
1307 |
if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
|
insilmaril@721
|
1308 |
cout << " ---------------------------"<<endl;
|
insilmaril@721
|
1309 |
}
|
insilmaril@721
|
1310 |
|
insilmaril@721
|
1311 |
mainWindow->updateHistory (undoSet);
|
insilmaril@721
|
1312 |
setChanged();
|
insilmaril@721
|
1313 |
updateActions();
|
insilmaril@721
|
1314 |
}
|
insilmaril@721
|
1315 |
|
insilmaril@721
|
1316 |
|
insilmaril@753
|
1317 |
void VymModel::saveStateChangingPart(TreeItem *undoSel, TreeItem* redoSel, const QString &rc, const QString &comment)
|
insilmaril@721
|
1318 |
{
|
insilmaril@721
|
1319 |
// save the selected part of the map, Undo will replace part of map
|
insilmaril@721
|
1320 |
QString undoSelection="";
|
insilmaril@721
|
1321 |
if (undoSel)
|
insilmaril@721
|
1322 |
undoSelection=getSelectString(undoSel);
|
insilmaril@721
|
1323 |
else
|
insilmaril@721
|
1324 |
qWarning ("VymModel::saveStateChangingPart no undoSel given!");
|
insilmaril@721
|
1325 |
QString redoSelection="";
|
insilmaril@721
|
1326 |
if (redoSel)
|
insilmaril@721
|
1327 |
redoSelection=getSelectString(undoSel);
|
insilmaril@721
|
1328 |
else
|
insilmaril@721
|
1329 |
qWarning ("VymModel::saveStateChangingPart no redoSel given!");
|
insilmaril@721
|
1330 |
|
insilmaril@721
|
1331 |
|
insilmaril@721
|
1332 |
saveState (PartOfMap,
|
insilmaril@721
|
1333 |
undoSelection, "addMapReplace (\"PATH\")",
|
insilmaril@721
|
1334 |
redoSelection, rc,
|
insilmaril@721
|
1335 |
comment,
|
insilmaril@721
|
1336 |
undoSel);
|
insilmaril@721
|
1337 |
}
|
insilmaril@721
|
1338 |
|
insilmaril@760
|
1339 |
void VymModel::saveStateRemovingPart(TreeItem* redoSel, const QString &comment)
|
insilmaril@721
|
1340 |
{
|
insilmaril@721
|
1341 |
if (!redoSel)
|
insilmaril@721
|
1342 |
{
|
insilmaril@721
|
1343 |
qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
|
insilmaril@721
|
1344 |
return;
|
insilmaril@721
|
1345 |
}
|
insilmaril@753
|
1346 |
QString undoSelection=getSelectString (redoSel->parent() );
|
insilmaril@721
|
1347 |
QString redoSelection=getSelectString(redoSel);
|
insilmaril@753
|
1348 |
if (redoSel->getType()==TreeItem::Branch)
|
insilmaril@721
|
1349 |
{
|
insilmaril@721
|
1350 |
// save the selected branch of the map, Undo will insert part of map
|
insilmaril@721
|
1351 |
saveState (PartOfMap,
|
insilmaril@753
|
1352 |
undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
|
insilmaril@721
|
1353 |
redoSelection, "delete ()",
|
insilmaril@721
|
1354 |
comment,
|
insilmaril@721
|
1355 |
redoSel);
|
insilmaril@721
|
1356 |
}
|
insilmaril@721
|
1357 |
}
|
insilmaril@721
|
1358 |
|
insilmaril@721
|
1359 |
|
insilmaril@753
|
1360 |
void VymModel::saveState(TreeItem *undoSel, const QString &uc, TreeItem *redoSel, const QString &rc, const QString &comment)
|
insilmaril@721
|
1361 |
{
|
insilmaril@721
|
1362 |
// "Normal" savestate: save commands, selections and comment
|
insilmaril@721
|
1363 |
// so just save commands for undo and redo
|
insilmaril@721
|
1364 |
// and use current selection
|
insilmaril@721
|
1365 |
|
insilmaril@721
|
1366 |
QString redoSelection="";
|
insilmaril@721
|
1367 |
if (redoSel) redoSelection=getSelectString(redoSel);
|
insilmaril@721
|
1368 |
QString undoSelection="";
|
insilmaril@721
|
1369 |
if (undoSel) undoSelection=getSelectString(undoSel);
|
insilmaril@721
|
1370 |
|
insilmaril@721
|
1371 |
saveState (UndoCommand,
|
insilmaril@721
|
1372 |
undoSelection, uc,
|
insilmaril@721
|
1373 |
redoSelection, rc,
|
insilmaril@721
|
1374 |
comment,
|
insilmaril@721
|
1375 |
NULL);
|
insilmaril@721
|
1376 |
}
|
insilmaril@721
|
1377 |
|
insilmaril@721
|
1378 |
void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
|
insilmaril@721
|
1379 |
{
|
insilmaril@721
|
1380 |
// "Normal" savestate: save commands, selections and comment
|
insilmaril@721
|
1381 |
// so just save commands for undo and redo
|
insilmaril@721
|
1382 |
// and use current selection
|
insilmaril@721
|
1383 |
saveState (UndoCommand,
|
insilmaril@721
|
1384 |
undoSel, uc,
|
insilmaril@721
|
1385 |
redoSel, rc,
|
insilmaril@721
|
1386 |
comment,
|
insilmaril@721
|
1387 |
NULL);
|
insilmaril@721
|
1388 |
}
|
insilmaril@721
|
1389 |
|
insilmaril@721
|
1390 |
void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
|
insilmaril@721
|
1391 |
{
|
insilmaril@721
|
1392 |
// "Normal" savestate applied to model (no selection needed):
|
insilmaril@721
|
1393 |
// save commands and comment
|
insilmaril@721
|
1394 |
saveState (UndoCommand,
|
insilmaril@721
|
1395 |
NULL, uc,
|
insilmaril@721
|
1396 |
NULL, rc,
|
insilmaril@721
|
1397 |
comment,
|
insilmaril@721
|
1398 |
NULL);
|
insilmaril@721
|
1399 |
}
|
insilmaril@721
|
1400 |
|
insilmaril@721
|
1401 |
|
insilmaril@650
|
1402 |
QGraphicsScene* VymModel::getScene ()
|
insilmaril@650
|
1403 |
{
|
insilmaril@650
|
1404 |
return mapScene;
|
insilmaril@650
|
1405 |
}
|
insilmaril@650
|
1406 |
|
insilmaril@761
|
1407 |
TreeItem* VymModel::findBySelectString(QString s)
|
insilmaril@761
|
1408 |
{
|
insilmaril@761
|
1409 |
if (s.isEmpty() ) return NULL;
|
insilmaril@761
|
1410 |
|
insilmaril@761
|
1411 |
// Old maps don't have multiple mapcenters and don't save full path
|
insilmaril@761
|
1412 |
if (s.left(2) !="mc")
|
insilmaril@761
|
1413 |
s="mc:0,"+s;
|
insilmaril@761
|
1414 |
|
insilmaril@761
|
1415 |
QStringList parts=s.split (",");
|
insilmaril@761
|
1416 |
QString typ;
|
insilmaril@761
|
1417 |
int n;
|
insilmaril@761
|
1418 |
TreeItem *ti=rootItem;
|
insilmaril@761
|
1419 |
|
insilmaril@761
|
1420 |
while (!parts.isEmpty() )
|
insilmaril@650
|
1421 |
{
|
insilmaril@761
|
1422 |
typ=parts.first().left(2);
|
insilmaril@761
|
1423 |
n=parts.first().right(parts.first().length() - 3).toInt();
|
insilmaril@761
|
1424 |
parts.removeFirst();
|
insilmaril@761
|
1425 |
if (typ=="mc" || typ=="bo")
|
insilmaril@761
|
1426 |
ti=ti->getBranchNum (n);
|
insilmaril@761
|
1427 |
/* FIXME-2
|
insilmaril@761
|
1428 |
else
|
insilmaril@761
|
1429 |
if (typ="fi")
|
insilmaril@761
|
1430 |
ti=ti->getImageNum (n);
|
insilmaril@761
|
1431 |
*/
|
insilmaril@761
|
1432 |
}
|
insilmaril@761
|
1433 |
return ti;
|
insilmaril@650
|
1434 |
}
|
insilmaril@650
|
1435 |
|
insilmaril@754
|
1436 |
TreeItem* VymModel::findID (const QString &s)
|
insilmaril@754
|
1437 |
{
|
insilmaril@754
|
1438 |
TreeItem *ti;
|
insilmaril@754
|
1439 |
for (int i=0; i<rootItem->branchCount(); i++)
|
insilmaril@650
|
1440 |
{
|
insilmaril@754
|
1441 |
ti=rootItem->getBranchNum(i)->findID (s);
|
insilmaril@754
|
1442 |
if (ti) return ti;
|
insilmaril@650
|
1443 |
}
|
insilmaril@650
|
1444 |
return NULL;
|
insilmaril@650
|
1445 |
}
|
insilmaril@650
|
1446 |
|
insilmaril@721
|
1447 |
//////////////////////////////////////////////
|
insilmaril@721
|
1448 |
// Interface
|
insilmaril@721
|
1449 |
//////////////////////////////////////////////
|
insilmaril@721
|
1450 |
void VymModel::setVersion (const QString &s)
|
insilmaril@721
|
1451 |
{
|
insilmaril@721
|
1452 |
version=s;
|
insilmaril@721
|
1453 |
}
|
insilmaril@721
|
1454 |
|
insilmaril@721
|
1455 |
void VymModel::setAuthor (const QString &s)
|
insilmaril@721
|
1456 |
{
|
insilmaril@721
|
1457 |
saveState (
|
insilmaril@721
|
1458 |
QString ("setMapAuthor (\"%1\")").arg(author),
|
insilmaril@721
|
1459 |
QString ("setMapAuthor (\"%1\")").arg(s),
|
insilmaril@721
|
1460 |
QString ("Set author of map to \"%1\"").arg(s)
|
insilmaril@721
|
1461 |
);
|
insilmaril@721
|
1462 |
author=s;
|
insilmaril@721
|
1463 |
}
|
insilmaril@721
|
1464 |
|
insilmaril@721
|
1465 |
QString VymModel::getAuthor()
|
insilmaril@721
|
1466 |
{
|
insilmaril@721
|
1467 |
return author;
|
insilmaril@721
|
1468 |
}
|
insilmaril@721
|
1469 |
|
insilmaril@721
|
1470 |
void VymModel::setComment (const QString &s)
|
insilmaril@721
|
1471 |
{
|
insilmaril@721
|
1472 |
saveState (
|
insilmaril@721
|
1473 |
QString ("setMapComment (\"%1\")").arg(comment),
|
insilmaril@721
|
1474 |
QString ("setMapComment (\"%1\")").arg(s),
|
insilmaril@721
|
1475 |
QString ("Set comment of map")
|
insilmaril@721
|
1476 |
);
|
insilmaril@721
|
1477 |
comment=s;
|
insilmaril@721
|
1478 |
}
|
insilmaril@721
|
1479 |
|
insilmaril@721
|
1480 |
QString VymModel::getComment ()
|
insilmaril@721
|
1481 |
{
|
insilmaril@721
|
1482 |
return comment;
|
insilmaril@721
|
1483 |
}
|
insilmaril@721
|
1484 |
|
insilmaril@721
|
1485 |
QString VymModel::getDate ()
|
insilmaril@721
|
1486 |
{
|
insilmaril@721
|
1487 |
return QDate::currentDate().toString ("yyyy-MM-dd");
|
insilmaril@721
|
1488 |
}
|
insilmaril@721
|
1489 |
|
insilmaril@749
|
1490 |
int VymModel::branchCount() // FIXME-2 Optimize this: use internal counter instead of going through whole map each time...
|
insilmaril@742
|
1491 |
{
|
insilmaril@742
|
1492 |
int c=0;
|
insilmaril@750
|
1493 |
BranchItem *cur=NULL;
|
insilmaril@750
|
1494 |
BranchItem *prev=NULL;
|
insilmaril@742
|
1495 |
int d;
|
insilmaril@742
|
1496 |
next(cur,prev,d);
|
insilmaril@742
|
1497 |
while (cur)
|
insilmaril@742
|
1498 |
{
|
insilmaril@742
|
1499 |
c++;
|
insilmaril@742
|
1500 |
next(cur,prev,d);
|
insilmaril@742
|
1501 |
}
|
insilmaril@742
|
1502 |
return c;
|
insilmaril@742
|
1503 |
}
|
insilmaril@742
|
1504 |
|
insilmaril@721
|
1505 |
void VymModel::setHeading(const QString &s)
|
insilmaril@721
|
1506 |
{
|
insilmaril@753
|
1507 |
BranchItem *selbi=getSelectedBranchItem();
|
insilmaril@753
|
1508 |
if (selbi)
|
insilmaril@721
|
1509 |
{
|
insilmaril@721
|
1510 |
saveState(
|
insilmaril@753
|
1511 |
selbi,
|
insilmaril@753
|
1512 |
"setHeading (\""+selbi->getHeading()+"\")",
|
insilmaril@753
|
1513 |
selbi,
|
insilmaril@721
|
1514 |
"setHeading (\""+s+"\")",
|
insilmaril@753
|
1515 |
QString("Set heading of %1 to \"%2\"").arg(getObjectName(selbi)).arg(s) );
|
insilmaril@753
|
1516 |
selbi->setHeading(s );
|
insilmaril@753
|
1517 |
QModelIndex ix2=index (selbi);
|
insilmaril@753
|
1518 |
emit (dataChanged ( ix2,ix2));
|
insilmaril@746
|
1519 |
/* FIXME-3 testing only
|
insilmaril@736
|
1520 |
*/
|
insilmaril@726
|
1521 |
|
insilmaril@721
|
1522 |
reposition();
|
insilmaril@753
|
1523 |
// selection.update(); //FIXME-4
|
insilmaril@721
|
1524 |
ensureSelectionVisible();
|
insilmaril@721
|
1525 |
}
|
insilmaril@721
|
1526 |
}
|
insilmaril@721
|
1527 |
|
insilmaril@753
|
1528 |
BranchItem* VymModel::findText (QString s, bool cs)
|
insilmaril@721
|
1529 |
{
|
insilmaril@741
|
1530 |
int d=0;
|
insilmaril@721
|
1531 |
QTextDocument::FindFlags flags=0;
|
insilmaril@721
|
1532 |
if (cs) flags=QTextDocument::FindCaseSensitively;
|
insilmaril@721
|
1533 |
|
insilmaril@741
|
1534 |
if (!findCurrent)
|
insilmaril@721
|
1535 |
{ // Nothing found or new find process
|
insilmaril@721
|
1536 |
if (EOFind)
|
insilmaril@721
|
1537 |
// nothing found, start again
|
insilmaril@721
|
1538 |
EOFind=false;
|
insilmaril@741
|
1539 |
findCurrent=NULL;
|
insilmaril@741
|
1540 |
findPrevious=NULL;
|
insilmaril@741
|
1541 |
next (findCurrent,findPrevious,d);
|
insilmaril@721
|
1542 |
}
|
insilmaril@721
|
1543 |
bool searching=true;
|
insilmaril@721
|
1544 |
bool foundNote=false;
|
insilmaril@721
|
1545 |
while (searching && !EOFind)
|
insilmaril@721
|
1546 |
{
|
insilmaril@741
|
1547 |
if (findCurrent)
|
insilmaril@721
|
1548 |
{
|
insilmaril@721
|
1549 |
// Searching in Note
|
insilmaril@741
|
1550 |
if (findCurrent->getNote().contains(s,cs))
|
insilmaril@721
|
1551 |
{
|
insilmaril@741
|
1552 |
select (findCurrent);
|
insilmaril@741
|
1553 |
/*
|
insilmaril@735
|
1554 |
if (getSelectedBranch()!=itFind)
|
insilmaril@721
|
1555 |
{
|
insilmaril@735
|
1556 |
select(itFind);
|
insilmaril@721
|
1557 |
ensureSelectionVisible();
|
insilmaril@721
|
1558 |
}
|
insilmaril@741
|
1559 |
*/
|
insilmaril@721
|
1560 |
if (textEditor->findText(s,flags))
|
insilmaril@721
|
1561 |
{
|
insilmaril@721
|
1562 |
searching=false;
|
insilmaril@721
|
1563 |
foundNote=true;
|
insilmaril@721
|
1564 |
}
|
insilmaril@721
|
1565 |
}
|
insilmaril@721
|
1566 |
// Searching in Heading
|
insilmaril@741
|
1567 |
if (searching && findCurrent->getHeading().contains (s,cs) )
|
insilmaril@721
|
1568 |
{
|
insilmaril@741
|
1569 |
select(findCurrent);
|
insilmaril@721
|
1570 |
searching=false;
|
insilmaril@721
|
1571 |
}
|
insilmaril@721
|
1572 |
}
|
insilmaril@721
|
1573 |
if (!foundNote)
|
insilmaril@721
|
1574 |
{
|
insilmaril@741
|
1575 |
if (!next(findCurrent,findPrevious,d) )
|
insilmaril@741
|
1576 |
EOFind=true;
|
insilmaril@721
|
1577 |
}
|
insilmaril@721
|
1578 |
//cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
|
insilmaril@721
|
1579 |
}
|
insilmaril@721
|
1580 |
if (!searching)
|
insilmaril@753
|
1581 |
return getSelectedBranchItem();
|
insilmaril@721
|
1582 |
else
|
insilmaril@721
|
1583 |
return NULL;
|
insilmaril@721
|
1584 |
}
|
insilmaril@721
|
1585 |
|
insilmaril@721
|
1586 |
void VymModel::findReset()
|
insilmaril@721
|
1587 |
{ // Necessary if text to find changes during a find process
|
insilmaril@741
|
1588 |
findCurrent=NULL;
|
insilmaril@741
|
1589 |
findPrevious=NULL;
|
insilmaril@721
|
1590 |
EOFind=false;
|
insilmaril@721
|
1591 |
}
|
insilmaril@721
|
1592 |
|
insilmaril@721
|
1593 |
void VymModel::setScene (QGraphicsScene *s)
|
insilmaril@721
|
1594 |
{
|
insilmaril@746
|
1595 |
mapScene=s; // FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
|
insilmaril@728
|
1596 |
//init(); // Here we have a mapScene set,
|
insilmaril@721
|
1597 |
// which is (still) needed to create MapCenters
|
insilmaril@721
|
1598 |
}
|
insilmaril@721
|
1599 |
|
insilmaril@753
|
1600 |
void VymModel::setURL(const QString &url) //FIXME-2
|
insilmaril@753
|
1601 |
{
|
insilmaril@753
|
1602 |
/*
|
insilmaril@735
|
1603 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
1604 |
if (bo)
|
insilmaril@721
|
1605 |
{
|
insilmaril@721
|
1606 |
QString oldurl=bo->getURL();
|
insilmaril@721
|
1607 |
bo->setURL (url);
|
insilmaril@721
|
1608 |
saveState (
|
insilmaril@721
|
1609 |
bo,
|
insilmaril@721
|
1610 |
QString ("setURL (\"%1\")").arg(oldurl),
|
insilmaril@721
|
1611 |
bo,
|
insilmaril@721
|
1612 |
QString ("setURL (\"%1\")").arg(url),
|
insilmaril@721
|
1613 |
QString ("set URL of %1 to %2").arg(getObjectName(bo)).arg(url)
|
insilmaril@721
|
1614 |
);
|
insilmaril@721
|
1615 |
updateActions();
|
insilmaril@721
|
1616 |
reposition();
|
insilmaril@721
|
1617 |
selection.update();
|
insilmaril@721
|
1618 |
ensureSelectionVisible();
|
insilmaril@721
|
1619 |
}
|
insilmaril@753
|
1620 |
*/
|
insilmaril@721
|
1621 |
}
|
insilmaril@721
|
1622 |
|
insilmaril@753
|
1623 |
QString VymModel::getURL() //FIXME-2
|
insilmaril@753
|
1624 |
{
|
insilmaril@753
|
1625 |
/*
|
insilmaril@735
|
1626 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
1627 |
if (bo)
|
insilmaril@721
|
1628 |
return bo->getURL();
|
insilmaril@721
|
1629 |
else
|
insilmaril@721
|
1630 |
return "";
|
insilmaril@753
|
1631 |
*/
|
insilmaril@721
|
1632 |
}
|
insilmaril@721
|
1633 |
|
insilmaril@746
|
1634 |
QStringList VymModel::getURLs() // FIXME-1 first, next moved to vymmodel
|
insilmaril@746
|
1635 |
{
|
insilmaril@746
|
1636 |
return QStringList();
|
insilmaril@746
|
1637 |
/*
|
insilmaril@721
|
1638 |
QStringList urls;
|
insilmaril@735
|
1639 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
1640 |
if (bo)
|
insilmaril@721
|
1641 |
{
|
insilmaril@721
|
1642 |
bo=bo->first();
|
insilmaril@721
|
1643 |
while (bo)
|
insilmaril@721
|
1644 |
{
|
insilmaril@721
|
1645 |
if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
|
insilmaril@721
|
1646 |
bo=bo->next();
|
insilmaril@721
|
1647 |
}
|
insilmaril@721
|
1648 |
}
|
insilmaril@721
|
1649 |
return urls;
|
insilmaril@746
|
1650 |
*/
|
insilmaril@721
|
1651 |
}
|
insilmaril@721
|
1652 |
|
insilmaril@754
|
1653 |
void VymModel::linkFloatImageTo(const QString &dstString) // FIXME-2
|
insilmaril@721
|
1654 |
{
|
insilmaril@721
|
1655 |
FloatImageObj *fio=selection.getFloatImage();
|
insilmaril@721
|
1656 |
if (fio)
|
insilmaril@721
|
1657 |
{
|
insilmaril@754
|
1658 |
TreeItem *dst=findBySelectString (dstString);
|
insilmaril@754
|
1659 |
if (dst && dst->isBranchLikeType() )
|
insilmaril@721
|
1660 |
{
|
insilmaril@754
|
1661 |
TreeItem *dstPar=dst->parent();
|
insilmaril@721
|
1662 |
QString parString=getSelectString(dstPar);
|
insilmaril@721
|
1663 |
QString fioPreSelectString=getSelectString(fio);
|
insilmaril@721
|
1664 |
QString fioPreParentSelectString=getSelectString (fio->getParObj());
|
insilmaril@754
|
1665 |
// FIXME-2 ((BranchObj*)dst)->addFloatImage (fio);
|
insilmaril@754
|
1666 |
unselect();
|
insilmaril@754
|
1667 |
// ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
|
insilmaril@721
|
1668 |
fio=((BranchObj*)dst)->getLastFloatImage();
|
insilmaril@721
|
1669 |
fio->setRelPos();
|
insilmaril@721
|
1670 |
fio->reposition();
|
insilmaril@754
|
1671 |
// select (fio);
|
insilmaril@721
|
1672 |
saveState(
|
insilmaril@721
|
1673 |
getSelectString(fio),
|
insilmaril@721
|
1674 |
QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
|
insilmaril@721
|
1675 |
fioPreSelectString,
|
insilmaril@721
|
1676 |
QString ("linkTo (\"%1\")").arg(dstString),
|
insilmaril@721
|
1677 |
QString ("Link floatimage to %1").arg(getObjectName(dst)));
|
insilmaril@721
|
1678 |
}
|
insilmaril@721
|
1679 |
}
|
insilmaril@721
|
1680 |
}
|
insilmaril@721
|
1681 |
|
insilmaril@721
|
1682 |
|
insilmaril@753
|
1683 |
void VymModel::setFrameType(const FrameObj::FrameType &t) //FIXME-2
|
insilmaril@753
|
1684 |
{
|
insilmaril@753
|
1685 |
/*
|
insilmaril@735
|
1686 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
1687 |
if (bo)
|
insilmaril@721
|
1688 |
{
|
insilmaril@721
|
1689 |
QString s=bo->getFrameTypeName();
|
insilmaril@721
|
1690 |
bo->setFrameType (t);
|
insilmaril@721
|
1691 |
saveState (bo, QString("setFrameType (\"%1\")").arg(s),
|
insilmaril@721
|
1692 |
bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
|
insilmaril@721
|
1693 |
reposition();
|
insilmaril@721
|
1694 |
bo->updateLink();
|
insilmaril@721
|
1695 |
}
|
insilmaril@753
|
1696 |
*/
|
insilmaril@721
|
1697 |
}
|
insilmaril@721
|
1698 |
|
insilmaril@753
|
1699 |
void VymModel::setFrameType(const QString &s) //FIXME-2
|
insilmaril@753
|
1700 |
{
|
insilmaril@753
|
1701 |
/*
|
insilmaril@735
|
1702 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
1703 |
if (bo)
|
insilmaril@721
|
1704 |
{
|
insilmaril@721
|
1705 |
saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
|
insilmaril@721
|
1706 |
bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
|
insilmaril@721
|
1707 |
bo->setFrameType (s);
|
insilmaril@721
|
1708 |
reposition();
|
insilmaril@721
|
1709 |
bo->updateLink();
|
insilmaril@721
|
1710 |
}
|
insilmaril@753
|
1711 |
*/
|
insilmaril@721
|
1712 |
}
|
insilmaril@721
|
1713 |
|
insilmaril@753
|
1714 |
void VymModel::setFramePenColor(const QColor &c) //FIXME-2
|
insilmaril@753
|
1715 |
{
|
insilmaril@753
|
1716 |
/*
|
insilmaril@735
|
1717 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
1718 |
if (bo)
|
insilmaril@721
|
1719 |
{
|
insilmaril@721
|
1720 |
saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
|
insilmaril@721
|
1721 |
bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
|
insilmaril@721
|
1722 |
bo->setFramePenColor (c);
|
insilmaril@721
|
1723 |
}
|
insilmaril@753
|
1724 |
*/
|
insilmaril@721
|
1725 |
}
|
insilmaril@721
|
1726 |
|
insilmaril@753
|
1727 |
void VymModel::setFrameBrushColor(const QColor &c) //FIXME-2
|
insilmaril@753
|
1728 |
{
|
insilmaril@753
|
1729 |
/*
|
insilmaril@735
|
1730 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
1731 |
if (bo)
|
insilmaril@721
|
1732 |
{
|
insilmaril@721
|
1733 |
saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
|
insilmaril@721
|
1734 |
bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
|
insilmaril@721
|
1735 |
bo->setFrameBrushColor (c);
|
insilmaril@721
|
1736 |
}
|
insilmaril@753
|
1737 |
*/}
|
insilmaril@753
|
1738 |
|
insilmaril@753
|
1739 |
void VymModel::setFramePadding (const int &i) //FIXME-2
|
insilmaril@753
|
1740 |
{
|
insilmaril@753
|
1741 |
/*
|
insilmaril@735
|
1742 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
1743 |
if (bo)
|
insilmaril@721
|
1744 |
{
|
insilmaril@721
|
1745 |
saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
|
insilmaril@721
|
1746 |
bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
|
insilmaril@721
|
1747 |
bo->setFramePadding (i);
|
insilmaril@721
|
1748 |
reposition();
|
insilmaril@721
|
1749 |
bo->updateLink();
|
insilmaril@721
|
1750 |
}
|
insilmaril@753
|
1751 |
*/
|
insilmaril@721
|
1752 |
}
|
insilmaril@721
|
1753 |
|
insilmaril@753
|
1754 |
void VymModel::setFrameBorderWidth(const int &i) //FIXME-2
|
insilmaril@753
|
1755 |
{
|
insilmaril@753
|
1756 |
/*
|
insilmaril@735
|
1757 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
1758 |
if (bo)
|
insilmaril@721
|
1759 |
{
|
insilmaril@721
|
1760 |
saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
|
insilmaril@721
|
1761 |
bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
|
insilmaril@721
|
1762 |
bo->setFrameBorderWidth (i);
|
insilmaril@721
|
1763 |
reposition();
|
insilmaril@721
|
1764 |
bo->updateLink();
|
insilmaril@721
|
1765 |
}
|
insilmaril@753
|
1766 |
*/
|
insilmaril@721
|
1767 |
}
|
insilmaril@721
|
1768 |
|
insilmaril@753
|
1769 |
void VymModel::setIncludeImagesVer(bool b) //FIXME-2
|
insilmaril@753
|
1770 |
{
|
insilmaril@753
|
1771 |
/*
|
insilmaril@735
|
1772 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
1773 |
if (bo)
|
insilmaril@721
|
1774 |
{
|
insilmaril@721
|
1775 |
QString u= b ? "false" : "true";
|
insilmaril@721
|
1776 |
QString r=!b ? "false" : "true";
|
insilmaril@721
|
1777 |
|
insilmaril@721
|
1778 |
saveState(
|
insilmaril@721
|
1779 |
bo,
|
insilmaril@721
|
1780 |
QString("setIncludeImagesVertically (%1)").arg(u),
|
insilmaril@721
|
1781 |
bo,
|
insilmaril@721
|
1782 |
QString("setIncludeImagesVertically (%1)").arg(r),
|
insilmaril@721
|
1783 |
QString("Include images vertically in %1").arg(getObjectName(bo))
|
insilmaril@721
|
1784 |
);
|
insilmaril@721
|
1785 |
bo->setIncludeImagesVer(b);
|
insilmaril@721
|
1786 |
reposition();
|
insilmaril@721
|
1787 |
}
|
insilmaril@753
|
1788 |
*/}
|
insilmaril@753
|
1789 |
|
insilmaril@753
|
1790 |
void VymModel::setIncludeImagesHor(bool b) //FIXME-2
|
insilmaril@753
|
1791 |
{
|
insilmaril@753
|
1792 |
/*
|
insilmaril@735
|
1793 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
1794 |
if (bo)
|
insilmaril@721
|
1795 |
{
|
insilmaril@721
|
1796 |
QString u= b ? "false" : "true";
|
insilmaril@721
|
1797 |
QString r=!b ? "false" : "true";
|
insilmaril@721
|
1798 |
|
insilmaril@721
|
1799 |
saveState(
|
insilmaril@721
|
1800 |
bo,
|
insilmaril@721
|
1801 |
QString("setIncludeImagesHorizontally (%1)").arg(u),
|
insilmaril@721
|
1802 |
bo,
|
insilmaril@721
|
1803 |
QString("setIncludeImagesHorizontally (%1)").arg(r),
|
insilmaril@721
|
1804 |
QString("Include images horizontally in %1").arg(getObjectName(bo))
|
insilmaril@721
|
1805 |
);
|
insilmaril@721
|
1806 |
bo->setIncludeImagesHor(b);
|
insilmaril@721
|
1807 |
reposition();
|
insilmaril@721
|
1808 |
}
|
insilmaril@753
|
1809 |
*/
|
insilmaril@721
|
1810 |
}
|
insilmaril@721
|
1811 |
|
insilmaril@753
|
1812 |
void VymModel::setHideLinkUnselected (bool b)//FIXME-2
|
insilmaril@753
|
1813 |
{
|
insilmaril@753
|
1814 |
/*
|
insilmaril@735
|
1815 |
LinkableMapObj *sel=getSelectedLMO();
|
insilmaril@721
|
1816 |
if (sel &&
|
insilmaril@735
|
1817 |
(selectionType() == TreeItem::Branch ||
|
insilmaril@735
|
1818 |
selectionType() == TreeItem::MapCenter ||
|
insilmaril@735
|
1819 |
selectionType() == TreeItem::Image ))
|
insilmaril@721
|
1820 |
{
|
insilmaril@721
|
1821 |
QString u= b ? "false" : "true";
|
insilmaril@721
|
1822 |
QString r=!b ? "false" : "true";
|
insilmaril@721
|
1823 |
|
insilmaril@721
|
1824 |
saveState(
|
insilmaril@721
|
1825 |
sel,
|
insilmaril@721
|
1826 |
QString("setHideLinkUnselected (%1)").arg(u),
|
insilmaril@721
|
1827 |
sel,
|
insilmaril@721
|
1828 |
QString("setHideLinkUnselected (%1)").arg(r),
|
insilmaril@721
|
1829 |
QString("Hide link of %1 if unselected").arg(getObjectName(sel))
|
insilmaril@721
|
1830 |
);
|
insilmaril@721
|
1831 |
sel->setHideLinkUnselected(b);
|
insilmaril@721
|
1832 |
}
|
insilmaril@753
|
1833 |
*/
|
insilmaril@721
|
1834 |
}
|
insilmaril@721
|
1835 |
|
insilmaril@721
|
1836 |
void VymModel::setHideExport(bool b)
|
insilmaril@721
|
1837 |
{
|
insilmaril@753
|
1838 |
BranchItem *bi=getSelectedBranchItem();
|
insilmaril@753
|
1839 |
if (bi)
|
insilmaril@721
|
1840 |
{
|
insilmaril@753
|
1841 |
bi->setHideInExport (b);
|
insilmaril@721
|
1842 |
QString u= b ? "false" : "true";
|
insilmaril@721
|
1843 |
QString r=!b ? "false" : "true";
|
insilmaril@721
|
1844 |
|
insilmaril@721
|
1845 |
saveState(
|
insilmaril@753
|
1846 |
bi,
|
insilmaril@721
|
1847 |
QString ("setHideExport (%1)").arg(u),
|
insilmaril@753
|
1848 |
bi,
|
insilmaril@721
|
1849 |
QString ("setHideExport (%1)").arg(r),
|
insilmaril@753
|
1850 |
QString ("Set HideExport flag of %1 to %2").arg(getObjectName(bi)).arg (r)
|
insilmaril@721
|
1851 |
);
|
insilmaril@721
|
1852 |
updateActions();
|
insilmaril@721
|
1853 |
reposition();
|
insilmaril@753
|
1854 |
// selection.update();
|
insilmaril@746
|
1855 |
// FIXME-3 VM needed? scene()->update();
|
insilmaril@721
|
1856 |
}
|
insilmaril@721
|
1857 |
}
|
insilmaril@721
|
1858 |
|
insilmaril@721
|
1859 |
void VymModel::toggleHideExport()
|
insilmaril@721
|
1860 |
{
|
insilmaril@753
|
1861 |
BranchItem *selbi=getSelectedBranchItem();
|
insilmaril@753
|
1862 |
if (selbi)
|
insilmaril@753
|
1863 |
setHideExport ( !selbi->hideInExport() );
|
insilmaril@721
|
1864 |
}
|
insilmaril@721
|
1865 |
|
insilmaril@721
|
1866 |
|
insilmaril@753
|
1867 |
void VymModel::copy() //FIXME-2
|
insilmaril@753
|
1868 |
{
|
insilmaril@753
|
1869 |
/*
|
insilmaril@735
|
1870 |
LinkableMapObj *sel=getSelectedLMO();
|
insilmaril@735
|
1871 |
if (sel &&
|
insilmaril@735
|
1872 |
(selectionType() == TreeItem::Branch ||
|
insilmaril@735
|
1873 |
selectionType() == TreeItem::MapCenter ||
|
insilmaril@735
|
1874 |
selectionType() == TreeItem::Image ))
|
insilmaril@721
|
1875 |
{
|
insilmaril@721
|
1876 |
if (redosAvail == 0)
|
insilmaril@721
|
1877 |
{
|
insilmaril@721
|
1878 |
// Copy to history
|
insilmaril@721
|
1879 |
QString s=getSelectString(sel);
|
insilmaril@721
|
1880 |
saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
|
insilmaril@721
|
1881 |
curClipboard=curStep;
|
insilmaril@721
|
1882 |
}
|
insilmaril@721
|
1883 |
|
insilmaril@721
|
1884 |
// Copy also to global clipboard, because we are at last step in history
|
insilmaril@721
|
1885 |
QString bakMapName(QString("history-%1").arg(curStep));
|
insilmaril@721
|
1886 |
QString bakMapDir(tmpMapDir +"/"+bakMapName);
|
insilmaril@721
|
1887 |
copyDir (bakMapDir,clipboardDir );
|
insilmaril@721
|
1888 |
|
insilmaril@721
|
1889 |
clipboardEmpty=false;
|
insilmaril@721
|
1890 |
updateActions();
|
insilmaril@721
|
1891 |
}
|
insilmaril@753
|
1892 |
*/
|
insilmaril@721
|
1893 |
}
|
insilmaril@721
|
1894 |
|
insilmaril@721
|
1895 |
|
insilmaril@753
|
1896 |
void VymModel::pasteNoSave(const int &n) //FIXME-2
|
insilmaril@753
|
1897 |
{
|
insilmaril@753
|
1898 |
/*
|
insilmaril@721
|
1899 |
bool old=blockSaveState;
|
insilmaril@721
|
1900 |
blockSaveState=true;
|
insilmaril@721
|
1901 |
bool zippedOrg=zipped;
|
insilmaril@721
|
1902 |
if (redosAvail > 0 || n!=0)
|
insilmaril@721
|
1903 |
{
|
insilmaril@721
|
1904 |
// Use the "historical" buffer
|
insilmaril@721
|
1905 |
QString bakMapName(QString("history-%1").arg(n));
|
insilmaril@721
|
1906 |
QString bakMapDir(tmpMapDir +"/"+bakMapName);
|
insilmaril@721
|
1907 |
load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
|
insilmaril@721
|
1908 |
} else
|
insilmaril@721
|
1909 |
// Use the global buffer
|
insilmaril@721
|
1910 |
load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
|
insilmaril@721
|
1911 |
zipped=zippedOrg;
|
insilmaril@721
|
1912 |
blockSaveState=old;
|
insilmaril@753
|
1913 |
*/
|
insilmaril@721
|
1914 |
}
|
insilmaril@721
|
1915 |
|
insilmaril@753
|
1916 |
void VymModel::paste() //FIXME-2
|
insilmaril@721
|
1917 |
{
|
insilmaril@753
|
1918 |
/*
|
insilmaril@735
|
1919 |
BranchObj *sel=getSelectedBranch();
|
insilmaril@721
|
1920 |
if (sel)
|
insilmaril@721
|
1921 |
{
|
insilmaril@721
|
1922 |
saveStateChangingPart(
|
insilmaril@721
|
1923 |
sel,
|
insilmaril@721
|
1924 |
sel,
|
insilmaril@721
|
1925 |
QString ("paste (%1)").arg(curClipboard),
|
insilmaril@721
|
1926 |
QString("Paste to %1").arg( getObjectName(sel))
|
insilmaril@721
|
1927 |
);
|
insilmaril@721
|
1928 |
pasteNoSave(0);
|
insilmaril@721
|
1929 |
reposition();
|
insilmaril@721
|
1930 |
}
|
insilmaril@753
|
1931 |
*/
|
insilmaril@721
|
1932 |
}
|
insilmaril@721
|
1933 |
|
insilmaril@753
|
1934 |
void VymModel::cut() //FIXME-2
|
insilmaril@753
|
1935 |
{
|
insilmaril@753
|
1936 |
/*
|
insilmaril@735
|
1937 |
LinkableMapObj *sel=getSelectedLMO();
|
insilmaril@735
|
1938 |
if ( sel && (selectionType() == TreeItem::Branch ||
|
insilmaril@735
|
1939 |
selectionType()==TreeItem::MapCenter ||
|
insilmaril@735
|
1940 |
selectionType()==TreeItem::Image))
|
insilmaril@721
|
1941 |
{
|
insilmaril@753
|
1942 |
*/
|
insilmaril@721
|
1943 |
/* No savestate! savestate is called in cutNoSave
|
insilmaril@721
|
1944 |
saveStateChangingPart(
|
insilmaril@721
|
1945 |
sel->getParObj(),
|
insilmaril@721
|
1946 |
sel,
|
insilmaril@721
|
1947 |
"cut ()",
|
insilmaril@721
|
1948 |
QString("Cut %1").arg(getObjectName(sel ))
|
insilmaril@721
|
1949 |
);
|
insilmaril@721
|
1950 |
*/
|
insilmaril@753
|
1951 |
/*
|
insilmaril@721
|
1952 |
copy();
|
insilmaril@721
|
1953 |
deleteSelection();
|
insilmaril@721
|
1954 |
reposition();
|
insilmaril@721
|
1955 |
}
|
insilmaril@753
|
1956 |
*/}
|
insilmaril@753
|
1957 |
|
insilmaril@753
|
1958 |
void VymModel::moveBranchUp() //FIXME-2
|
insilmaril@753
|
1959 |
{
|
insilmaril@753
|
1960 |
/*
|
insilmaril@735
|
1961 |
BranchObj* bo=getSelectedBranch();
|
insilmaril@721
|
1962 |
BranchObj* par;
|
insilmaril@721
|
1963 |
if (bo)
|
insilmaril@721
|
1964 |
{
|
insilmaril@721
|
1965 |
if (!bo->canMoveBranchUp()) return;
|
insilmaril@721
|
1966 |
par=(BranchObj*)(bo->getParObj());
|
insilmaril@721
|
1967 |
BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
|
insilmaril@721
|
1968 |
saveState (getSelectString(bo),"moveBranchDown ()",getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getObjectName(bo)));
|
insilmaril@721
|
1969 |
reposition();
|
insilmaril@746
|
1970 |
//FIXME-3 VM needed? scene()->update();
|
insilmaril@721
|
1971 |
selection.update();
|
insilmaril@721
|
1972 |
ensureSelectionVisible();
|
insilmaril@721
|
1973 |
}
|
insilmaril@753
|
1974 |
*/
|
insilmaril@721
|
1975 |
}
|
insilmaril@721
|
1976 |
|
insilmaril@753
|
1977 |
void VymModel::moveBranchDown() //FIXME-2
|
insilmaril@753
|
1978 |
{
|
insilmaril@753
|
1979 |
/*
|
insilmaril@735
|
1980 |
BranchObj* bo=getSelectedBranch();
|
insilmaril@721
|
1981 |
BranchObj* par;
|
insilmaril@721
|
1982 |
if (bo)
|
insilmaril@721
|
1983 |
{
|
insilmaril@721
|
1984 |
if (!bo->canMoveBranchDown()) return;
|
insilmaril@721
|
1985 |
par=(BranchObj*)(bo->getParObj());
|
insilmaril@721
|
1986 |
BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
|
insilmaril@721
|
1987 |
saveState(getSelectString(bo),"moveBranchUp ()",getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getObjectName(bo)));
|
insilmaril@721
|
1988 |
reposition();
|
insilmaril@746
|
1989 |
//FIXME-3 VM needed? scene()->update();
|
insilmaril@721
|
1990 |
selection.update();
|
insilmaril@721
|
1991 |
ensureSelectionVisible();
|
insilmaril@721
|
1992 |
}
|
insilmaril@753
|
1993 |
*/
|
insilmaril@721
|
1994 |
}
|
insilmaril@721
|
1995 |
|
insilmaril@753
|
1996 |
void VymModel::sortChildren() // FIXME-2 not implemented yet
|
insilmaril@749
|
1997 |
{
|
insilmaril@749
|
1998 |
/*
|
insilmaril@735
|
1999 |
BranchObj* bo=getSelectedBranch();
|
insilmaril@721
|
2000 |
if (bo)
|
insilmaril@721
|
2001 |
{
|
insilmaril@749
|
2002 |
if(treeItem->branchCount()>1)
|
insilmaril@721
|
2003 |
{
|
insilmaril@721
|
2004 |
saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
|
insilmaril@721
|
2005 |
bo->sortChildren();
|
insilmaril@721
|
2006 |
reposition();
|
insilmaril@721
|
2007 |
ensureSelectionVisible();
|
insilmaril@721
|
2008 |
}
|
insilmaril@721
|
2009 |
}
|
insilmaril@749
|
2010 |
*/
|
insilmaril@721
|
2011 |
}
|
insilmaril@721
|
2012 |
|
insilmaril@753
|
2013 |
MapCenterItem* VymModel::createMapCenter()
|
insilmaril@753
|
2014 |
{
|
insilmaril@753
|
2015 |
MapCenterItem *mci=addMapCenter (QPointF (0,0) );
|
insilmaril@753
|
2016 |
select (mci);
|
insilmaril@753
|
2017 |
return mci;
|
insilmaril@726
|
2018 |
}
|
insilmaril@726
|
2019 |
|
insilmaril@755
|
2020 |
BranchItem* VymModel::createBranch()
|
insilmaril@755
|
2021 |
{
|
insilmaril@755
|
2022 |
return addNewBranchInt (-2);
|
insilmaril@739
|
2023 |
}
|
insilmaril@739
|
2024 |
|
insilmaril@753
|
2025 |
TreeItem* VymModel::createImage() //FIXME-2
|
insilmaril@753
|
2026 |
{
|
insilmaril@753
|
2027 |
/*
|
insilmaril@735
|
2028 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@726
|
2029 |
if (bo)
|
insilmaril@726
|
2030 |
{
|
insilmaril@746
|
2031 |
FloatImageObj *newfio=bo->addFloatImage(); // FIXME-1 VM Old model, merge with below
|
insilmaril@726
|
2032 |
|
insilmaril@726
|
2033 |
// Create TreeItem
|
insilmaril@726
|
2034 |
QList<QVariant> cData;
|
insilmaril@739
|
2035 |
cData << "VM:createImage" << "undef"<<"undef";
|
insilmaril@726
|
2036 |
TreeItem *parti=bo->getTreeItem();
|
insilmaril@726
|
2037 |
TreeItem *ti=new TreeItem (cData,parti);
|
insilmaril@739
|
2038 |
ti->setLMO (newfio);
|
insilmaril@739
|
2039 |
ti->setType (TreeItem::Image);
|
insilmaril@726
|
2040 |
parti->appendChild (ti);
|
insilmaril@726
|
2041 |
|
insilmaril@739
|
2042 |
if (newfio)
|
insilmaril@726
|
2043 |
{
|
insilmaril@739
|
2044 |
newfio->setTreeItem (ti);
|
insilmaril@746
|
2045 |
select (newfio); // FIXME-2 VM really needed here?
|
insilmaril@739
|
2046 |
return ti;
|
insilmaril@726
|
2047 |
}
|
insilmaril@726
|
2048 |
}
|
insilmaril@739
|
2049 |
return NULL;
|
insilmaril@753
|
2050 |
*/
|
insilmaril@726
|
2051 |
}
|
insilmaril@726
|
2052 |
|
insilmaril@753
|
2053 |
MapCenterItem* VymModel::addMapCenter ()
|
insilmaril@753
|
2054 |
{
|
insilmaril@761
|
2055 |
MapCenterItem *mci=addMapCenter (contextPos);
|
insilmaril@746
|
2056 |
//FIXME-3 selection.select (mco);
|
insilmaril@721
|
2057 |
updateActions();
|
insilmaril@721
|
2058 |
ensureSelectionVisible();
|
insilmaril@721
|
2059 |
saveState (
|
insilmaril@753
|
2060 |
mci,
|
insilmaril@721
|
2061 |
"delete()",
|
insilmaril@721
|
2062 |
NULL,
|
insilmaril@723
|
2063 |
QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
|
insilmaril@723
|
2064 |
QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
|
insilmaril@721
|
2065 |
);
|
insilmaril@753
|
2066 |
return mci;
|
insilmaril@721
|
2067 |
}
|
insilmaril@721
|
2068 |
|
insilmaril@753
|
2069 |
MapCenterItem* VymModel::addMapCenter(QPointF absPos)
|
insilmaril@721
|
2070 |
{
|
insilmaril@749
|
2071 |
|
insilmaril@749
|
2072 |
// Create TreeItem
|
insilmaril@749
|
2073 |
QModelIndex parix=index(rootItem);
|
insilmaril@749
|
2074 |
|
insilmaril@749
|
2075 |
int n=rootItem->branchCount();
|
insilmaril@749
|
2076 |
|
insilmaril@749
|
2077 |
emit (layoutAboutToBeChanged() );
|
insilmaril@749
|
2078 |
beginInsertRows (parix,n,n+1);
|
insilmaril@749
|
2079 |
|
insilmaril@749
|
2080 |
QList<QVariant> cData;
|
insilmaril@749
|
2081 |
cData << "VM:addMapCenter" << "undef"<<"undef";
|
insilmaril@760
|
2082 |
MapCenterItem *mci=new MapCenterItem (cData);
|
insilmaril@753
|
2083 |
mci->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
|
insilmaril@753
|
2084 |
rootItem->appendChild (mci);
|
insilmaril@749
|
2085 |
|
insilmaril@749
|
2086 |
endInsertRows();
|
insilmaril@749
|
2087 |
emit (newChildObject (parix));
|
insilmaril@749
|
2088 |
emit (layoutChanged() );
|
insilmaril@749
|
2089 |
|
insilmaril@749
|
2090 |
// Create MapObj
|
insilmaril@760
|
2091 |
BranchObj *newbo=mci->createMapObj(mapScene);
|
insilmaril@760
|
2092 |
|
insilmaril@760
|
2093 |
/*
|
insilmaril@760
|
2094 |
|
insilmaril@760
|
2095 |
if (!mci->getHeading().isEmpty() )
|
insilmaril@760
|
2096 |
{
|
insilmaril@760
|
2097 |
newbo->updateHeading();
|
insilmaril@760
|
2098 |
newbo->setColor (headingColor);
|
insilmaril@760
|
2099 |
}
|
insilmaril@760
|
2100 |
*/
|
insilmaril@760
|
2101 |
|
insilmaril@760
|
2102 |
//newbo->updateLink(); //FIXME-3
|
insilmaril@760
|
2103 |
|
insilmaril@760
|
2104 |
/*
|
insilmaril@754
|
2105 |
//mapCenter->setMapEditor(mapEditor); //FIXME-3 VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects
|
insilmaril@753
|
2106 |
mapCenter->setTreeItem (mci); // TreeItem needs to exist before setVisibility
|
insilmaril@753
|
2107 |
mci->setLMO (mapCenter);
|
insilmaril@753
|
2108 |
mapCenter->updateHeading();
|
insilmaril@721
|
2109 |
mapCenter->move (absPos);
|
insilmaril@721
|
2110 |
mapCenter->setVisibility (true);
|
insilmaril@753
|
2111 |
//mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
|
insilmaril@745
|
2112 |
*/
|
insilmaril@753
|
2113 |
return mci;
|
insilmaril@721
|
2114 |
}
|
insilmaril@721
|
2115 |
|
insilmaril@755
|
2116 |
BranchItem* VymModel::addNewBranchInt(int num)
|
insilmaril@721
|
2117 |
{
|
insilmaril@721
|
2118 |
// Depending on pos:
|
insilmaril@721
|
2119 |
// -3 insert in children of parent above selection
|
insilmaril@721
|
2120 |
// -2 add branch to selection
|
insilmaril@721
|
2121 |
// -1 insert in children of parent below selection
|
insilmaril@721
|
2122 |
// 0..n insert in children of parent at pos
|
insilmaril@721
|
2123 |
BranchObj *newbo=NULL;
|
insilmaril@753
|
2124 |
BranchObj *bo=getSelectedBranchObj(); //FIXME-2
|
insilmaril@749
|
2125 |
BranchItem *bi=getSelectedBranchItem();
|
insilmaril@721
|
2126 |
if (bo)
|
insilmaril@721
|
2127 |
{
|
insilmaril@721
|
2128 |
if (num==-2)
|
insilmaril@721
|
2129 |
{
|
insilmaril@749
|
2130 |
// Create TreeItem
|
insilmaril@749
|
2131 |
QList<QVariant> cData;
|
insilmaril@749
|
2132 |
cData << "new" << "undef"<<"undef";
|
insilmaril@749
|
2133 |
|
insilmaril@749
|
2134 |
BranchItem *parbi=bi;
|
insilmaril@749
|
2135 |
QModelIndex parix=index(parbi);
|
insilmaril@756
|
2136 |
int n=parbi->childCount();
|
insilmaril@749
|
2137 |
|
insilmaril@749
|
2138 |
emit (layoutAboutToBeChanged() );
|
insilmaril@756
|
2139 |
beginInsertRows (parix,n,n+1); //FIXME-1 check if n is correct: should be index below _last_ branch...
|
insilmaril@756
|
2140 |
bi=new BranchItem (cData);
|
insilmaril@753
|
2141 |
bi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
|
insilmaril@749
|
2142 |
|
insilmaril@756
|
2143 |
parbi->appendChild (bi);
|
insilmaril@749
|
2144 |
endInsertRows ();
|
insilmaril@749
|
2145 |
emit (newChildObject (parix));
|
insilmaril@749
|
2146 |
emit (layoutChanged() );
|
insilmaril@749
|
2147 |
|
insilmaril@721
|
2148 |
// save scroll state. If scrolled, automatically select
|
insilmaril@721
|
2149 |
// new branch in order to tmp unscroll parent...
|
insilmaril@755
|
2150 |
newbo=bi->createMapObj(mapScene);
|
insilmaril@755
|
2151 |
select (bi);
|
insilmaril@721
|
2152 |
}else if (num==-1)
|
insilmaril@721
|
2153 |
{
|
insilmaril@755
|
2154 |
/*
|
insilmaril@749
|
2155 |
num=bi->num()+1;
|
insilmaril@721
|
2156 |
bo=(BranchObj*)bo->getParObj();
|
insilmaril@746
|
2157 |
if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing
|
insilmaril@755
|
2158 |
*/
|
insilmaril@721
|
2159 |
}else if (num==-3)
|
insilmaril@721
|
2160 |
{
|
insilmaril@755
|
2161 |
/*
|
insilmaril@749
|
2162 |
num=bi->num();
|
insilmaril@721
|
2163 |
bo=(BranchObj*)bo->getParObj();
|
insilmaril@746
|
2164 |
if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing
|
insilmaril@755
|
2165 |
*/
|
insilmaril@721
|
2166 |
}
|
insilmaril@721
|
2167 |
}
|
insilmaril@755
|
2168 |
return bi;
|
insilmaril@721
|
2169 |
}
|
insilmaril@721
|
2170 |
|
insilmaril@755
|
2171 |
BranchItem* VymModel::addNewBranch(int pos)
|
insilmaril@721
|
2172 |
{
|
insilmaril@721
|
2173 |
// Different meaning than num in addNewBranchInt!
|
insilmaril@721
|
2174 |
// -1 add above
|
insilmaril@721
|
2175 |
// 0 add as child
|
insilmaril@721
|
2176 |
// +1 add below
|
insilmaril@755
|
2177 |
BranchItem *newbi=NULL;
|
insilmaril@755
|
2178 |
BranchItem *selbi=getSelectedBranchItem();
|
insilmaril@755
|
2179 |
|
insilmaril@755
|
2180 |
if (selbi)
|
insilmaril@721
|
2181 |
{
|
insilmaril@749
|
2182 |
// FIXME-2 VM do we still need this in model? setCursor (Qt::ArrowCursor);
|
insilmaril@721
|
2183 |
|
insilmaril@755
|
2184 |
newbi=addNewBranchInt (pos-2);
|
insilmaril@755
|
2185 |
|
insilmaril@755
|
2186 |
if (newbi)
|
insilmaril@721
|
2187 |
{
|
insilmaril@721
|
2188 |
saveState(
|
insilmaril@755
|
2189 |
newbi,
|
insilmaril@721
|
2190 |
"delete ()",
|
insilmaril@755
|
2191 |
selbi,
|
insilmaril@721
|
2192 |
QString ("addBranch (%1)").arg(pos),
|
insilmaril@755
|
2193 |
QString ("Add new branch to %1").arg(getObjectName(selbi)));
|
insilmaril@721
|
2194 |
|
insilmaril@721
|
2195 |
reposition();
|
insilmaril@746
|
2196 |
// selection.update(); FIXME-3
|
insilmaril@761
|
2197 |
latestAddedItem=newbi;
|
insilmaril@721
|
2198 |
// In Network mode, the client needs to know where the new branch is,
|
insilmaril@721
|
2199 |
// so we have to pass on this information via saveState.
|
insilmaril@721
|
2200 |
// TODO: Get rid of this positioning workaround
|
insilmaril@755
|
2201 |
/* FIXME-4 network problem: QString ps=qpointfToString (newbo->getAbsPos());
|
insilmaril@721
|
2202 |
sendData ("selectLatestAdded ()");
|
insilmaril@721
|
2203 |
sendData (QString("move %1").arg(ps));
|
insilmaril@721
|
2204 |
sendSelection();
|
insilmaril@755
|
2205 |
*/
|
insilmaril@721
|
2206 |
}
|
insilmaril@721
|
2207 |
}
|
insilmaril@755
|
2208 |
return newbi;
|
insilmaril@721
|
2209 |
}
|
insilmaril@721
|
2210 |
|
insilmaril@721
|
2211 |
|
insilmaril@755
|
2212 |
BranchItem* VymModel::addNewBranchBefore() //FIXME-2
|
insilmaril@753
|
2213 |
{
|
insilmaril@753
|
2214 |
/*
|
insilmaril@721
|
2215 |
BranchObj *newbo=NULL;
|
insilmaril@735
|
2216 |
BranchObj *bo = getSelectedBranch();
|
insilmaril@735
|
2217 |
if (bo && selectionType()==TreeItem::Branch)
|
insilmaril@721
|
2218 |
// We accept no MapCenterObj here, so we _have_ a parent
|
insilmaril@721
|
2219 |
{
|
insilmaril@721
|
2220 |
QPointF p=bo->getRelPos();
|
insilmaril@721
|
2221 |
|
insilmaril@721
|
2222 |
|
insilmaril@721
|
2223 |
BranchObj *parbo=(BranchObj*)(bo->getParObj());
|
insilmaril@721
|
2224 |
|
insilmaril@721
|
2225 |
// add below selection
|
insilmaril@749
|
2226 |
newbo=parbo->insertBranch(bo->getTreeItem()->num()+1); //FIXME-1 VM still missing
|
insilmaril@745
|
2227 |
|
insilmaril@721
|
2228 |
if (newbo)
|
insilmaril@721
|
2229 |
{
|
insilmaril@721
|
2230 |
newbo->move2RelPos (p);
|
insilmaril@721
|
2231 |
|
insilmaril@721
|
2232 |
// Move selection to new branch
|
insilmaril@721
|
2233 |
bo->linkTo (newbo,-1);
|
insilmaril@721
|
2234 |
|
insilmaril@721
|
2235 |
saveState (newbo, "deleteKeepChildren ()", newbo, "addBranchBefore ()",
|
insilmaril@721
|
2236 |
QString ("Add branch before %1").arg(getObjectName(bo)));
|
insilmaril@721
|
2237 |
|
insilmaril@721
|
2238 |
reposition();
|
insilmaril@746
|
2239 |
// selection.update(); FIXME-3
|
insilmaril@721
|
2240 |
}
|
insilmaril@721
|
2241 |
}
|
insilmaril@721
|
2242 |
latestSelectionString=selection.getSelectString();
|
insilmaril@721
|
2243 |
return newbo;
|
insilmaril@753
|
2244 |
*/
|
insilmaril@753
|
2245 |
return NULL;
|
insilmaril@721
|
2246 |
}
|
insilmaril@721
|
2247 |
|
insilmaril@755
|
2248 |
BranchItem* VymModel::relinkBranch (BranchItem *branch, BranchItem *dst, int pos)
|
insilmaril@755
|
2249 |
{
|
insilmaril@755
|
2250 |
if (branch && dst)
|
insilmaril@755
|
2251 |
{
|
insilmaril@756
|
2252 |
emit (layoutAboutToBeChanged() );
|
insilmaril@755
|
2253 |
BranchItem *branchpi=(BranchItem*)branch->parent();
|
insilmaril@756
|
2254 |
// Remove at current position
|
insilmaril@756
|
2255 |
int n=branch->childNum();
|
insilmaril@756
|
2256 |
beginRemoveRows (index(branchpi),n,n);
|
insilmaril@756
|
2257 |
branchpi->removeChild (n);
|
insilmaril@756
|
2258 |
endRemoveRows();
|
insilmaril@756
|
2259 |
|
insilmaril@756
|
2260 |
if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
|
insilmaril@756
|
2261 |
|
insilmaril@756
|
2262 |
// Append as last branch to dst
|
insilmaril@756
|
2263 |
if (dst->branchCount()==0)
|
insilmaril@756
|
2264 |
n=0;
|
insilmaril@756
|
2265 |
else
|
insilmaril@756
|
2266 |
n=dst->getFirstBranch()->childNumber();
|
insilmaril@756
|
2267 |
beginInsertRows (index(dst),n+pos,n+pos);
|
insilmaril@756
|
2268 |
dst->insertBranch (pos,branch);
|
insilmaril@756
|
2269 |
endInsertRows();
|
insilmaril@756
|
2270 |
|
insilmaril@756
|
2271 |
branch->getLMO()->setParObj(dst->getLMO()); //FIXME-5 update parObj in View
|
insilmaril@756
|
2272 |
emit (layoutChanged() );
|
insilmaril@756
|
2273 |
select (branch);
|
insilmaril@755
|
2274 |
}
|
insilmaril@755
|
2275 |
}
|
insilmaril@755
|
2276 |
|
insilmaril@721
|
2277 |
void VymModel::deleteSelection()
|
insilmaril@721
|
2278 |
{
|
insilmaril@753
|
2279 |
BranchItem *selbi=getSelectedBranchItem();
|
insilmaril@753
|
2280 |
|
insilmaril@753
|
2281 |
if (!selbi) return;
|
insilmaril@753
|
2282 |
|
insilmaril@760
|
2283 |
TreeItem *pi=selbi->parent();
|
insilmaril@760
|
2284 |
QModelIndex parentIndex=index(pi);
|
insilmaril@728
|
2285 |
|
insilmaril@753
|
2286 |
if (selbi->isBranchLikeType() )
|
insilmaril@721
|
2287 |
{
|
insilmaril@735
|
2288 |
unselect();
|
insilmaril@760
|
2289 |
saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
|
insilmaril@745
|
2290 |
|
insilmaril@745
|
2291 |
emit (layoutAboutToBeChanged() );
|
insilmaril@745
|
2292 |
|
insilmaril@760
|
2293 |
int n=selbi->childNum();
|
insilmaril@745
|
2294 |
beginRemoveRows (parentIndex,n,n);
|
insilmaril@748
|
2295 |
removeRows (n,1,parentIndex);
|
insilmaril@749
|
2296 |
endRemoveRows();
|
insilmaril@760
|
2297 |
select (pi);
|
insilmaril@721
|
2298 |
ensureSelectionVisible();
|
insilmaril@721
|
2299 |
reposition();
|
insilmaril@745
|
2300 |
|
insilmaril@745
|
2301 |
emit (layoutChanged() );
|
insilmaril@721
|
2302 |
return;
|
insilmaril@721
|
2303 |
}
|
insilmaril@749
|
2304 |
//FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing
|
insilmaril@745
|
2305 |
|
insilmaril@748
|
2306 |
/*
|
insilmaril@721
|
2307 |
if (fio)
|
insilmaril@721
|
2308 |
{
|
insilmaril@721
|
2309 |
BranchObj* par=(BranchObj*)fio->getParObj();
|
insilmaril@721
|
2310 |
saveStateChangingPart(
|
insilmaril@721
|
2311 |
par,
|
insilmaril@721
|
2312 |
fio,
|
insilmaril@721
|
2313 |
"delete ()",
|
insilmaril@721
|
2314 |
QString("Delete %1").arg(getObjectName(fio))
|
insilmaril@721
|
2315 |
);
|
insilmaril@735
|
2316 |
unselect();
|
insilmaril@721
|
2317 |
par->removeFloatImage(fio);
|
insilmaril@735
|
2318 |
select (par);
|
insilmaril@721
|
2319 |
reposition();
|
insilmaril@721
|
2320 |
ensureSelectionVisible();
|
insilmaril@721
|
2321 |
return;
|
insilmaril@721
|
2322 |
}
|
insilmaril@748
|
2323 |
*/
|
insilmaril@721
|
2324 |
}
|
insilmaril@721
|
2325 |
|
insilmaril@753
|
2326 |
void VymModel::deleteKeepChildren() //FIXME-2 VM still missing
|
insilmaril@753
|
2327 |
|
insilmaril@753
|
2328 |
{
|
insilmaril@753
|
2329 |
/*
|
insilmaril@735
|
2330 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
2331 |
BranchObj *par;
|
insilmaril@721
|
2332 |
if (bo)
|
insilmaril@721
|
2333 |
{
|
insilmaril@721
|
2334 |
par=(BranchObj*)(bo->getParObj());
|
insilmaril@726
|
2335 |
|
insilmaril@726
|
2336 |
// Don't use this on mapcenter
|
insilmaril@726
|
2337 |
if (!par) return;
|
insilmaril@726
|
2338 |
|
insilmaril@726
|
2339 |
// Check if we have childs at all to keep
|
insilmaril@749
|
2340 |
if (bo->getTreeItem()->branchCount()==0)
|
insilmaril@726
|
2341 |
{
|
insilmaril@726
|
2342 |
deleteSelection();
|
insilmaril@726
|
2343 |
return;
|
insilmaril@726
|
2344 |
}
|
insilmaril@726
|
2345 |
|
insilmaril@721
|
2346 |
QPointF p=bo->getRelPos();
|
insilmaril@721
|
2347 |
saveStateChangingPart(
|
insilmaril@721
|
2348 |
bo->getParObj(),
|
insilmaril@721
|
2349 |
bo,
|
insilmaril@721
|
2350 |
"deleteKeepChildren ()",
|
insilmaril@721
|
2351 |
QString("Remove %1 and keep its children").arg(getObjectName(bo))
|
insilmaril@721
|
2352 |
);
|
insilmaril@721
|
2353 |
|
insilmaril@721
|
2354 |
QString sel=getSelectString(bo);
|
insilmaril@721
|
2355 |
unselect();
|
insilmaril@721
|
2356 |
par->removeBranchHere(bo);
|
insilmaril@721
|
2357 |
reposition();
|
insilmaril@721
|
2358 |
select (sel);
|
insilmaril@735
|
2359 |
getSelectedBranch()->move2RelPos (p);
|
insilmaril@721
|
2360 |
reposition();
|
insilmaril@721
|
2361 |
}
|
insilmaril@753
|
2362 |
*/}
|
insilmaril@753
|
2363 |
|
insilmaril@753
|
2364 |
void VymModel::deleteChildren() //FIXME-2 VM still missing
|
insilmaril@753
|
2365 |
|
insilmaril@753
|
2366 |
{
|
insilmaril@753
|
2367 |
/*
|
insilmaril@735
|
2368 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
2369 |
if (bo)
|
insilmaril@721
|
2370 |
{
|
insilmaril@721
|
2371 |
saveStateChangingPart(
|
insilmaril@721
|
2372 |
bo,
|
insilmaril@721
|
2373 |
bo,
|
insilmaril@721
|
2374 |
"deleteChildren ()",
|
insilmaril@721
|
2375 |
QString( "Remove children of branch %1").arg(getObjectName(bo))
|
insilmaril@721
|
2376 |
);
|
insilmaril@721
|
2377 |
bo->removeChildren();
|
insilmaril@721
|
2378 |
reposition();
|
insilmaril@721
|
2379 |
}
|
insilmaril@753
|
2380 |
*/}
|
insilmaril@721
|
2381 |
|
insilmaril@721
|
2382 |
|
insilmaril@749
|
2383 |
bool VymModel::scrollBranch(BranchItem *bi)
|
insilmaril@749
|
2384 |
{
|
insilmaril@749
|
2385 |
if (bi)
|
insilmaril@721
|
2386 |
{
|
insilmaril@749
|
2387 |
if (bi->isScrolled()) return false;
|
insilmaril@749
|
2388 |
if (bi->branchCount()==0) return false;
|
insilmaril@749
|
2389 |
if (bi->depth()==0) return false;
|
insilmaril@721
|
2390 |
QString u,r;
|
insilmaril@721
|
2391 |
r="scroll";
|
insilmaril@721
|
2392 |
u="unscroll";
|
insilmaril@753
|
2393 |
/* FIXME-3 no savestate yet
|
insilmaril@721
|
2394 |
saveState(
|
insilmaril@721
|
2395 |
bo,
|
insilmaril@721
|
2396 |
QString ("%1 ()").arg(u),
|
insilmaril@721
|
2397 |
bo,
|
insilmaril@721
|
2398 |
QString ("%1 ()").arg(r),
|
insilmaril@721
|
2399 |
QString ("%1 %2").arg(r).arg(getObjectName(bo))
|
insilmaril@721
|
2400 |
);
|
insilmaril@749
|
2401 |
*/
|
insilmaril@749
|
2402 |
bi->toggleScroll();
|
insilmaril@749
|
2403 |
//selection.update();
|
insilmaril@746
|
2404 |
// FIXME-3 VM needed? scene()->update();
|
insilmaril@721
|
2405 |
return true;
|
insilmaril@721
|
2406 |
}
|
insilmaril@721
|
2407 |
return false;
|
insilmaril@721
|
2408 |
}
|
insilmaril@721
|
2409 |
|
insilmaril@749
|
2410 |
bool VymModel::unscrollBranch(BranchItem *bi)
|
insilmaril@749
|
2411 |
{
|
insilmaril@749
|
2412 |
if (bi)
|
insilmaril@721
|
2413 |
{
|
insilmaril@749
|
2414 |
if (bi->isScrolled()) return false;
|
insilmaril@749
|
2415 |
if (bi->branchCount()==0) return false;
|
insilmaril@749
|
2416 |
if (bi->depth()==0) return false;
|
insilmaril@749
|
2417 |
|
insilmaril@721
|
2418 |
QString u,r;
|
insilmaril@721
|
2419 |
u="scroll";
|
insilmaril@721
|
2420 |
r="unscroll";
|
insilmaril@753
|
2421 |
/* FIXME-3 no savestate yet
|
insilmaril@721
|
2422 |
saveState(
|
insilmaril@721
|
2423 |
bo,
|
insilmaril@721
|
2424 |
QString ("%1 ()").arg(u),
|
insilmaril@721
|
2425 |
bo,
|
insilmaril@721
|
2426 |
QString ("%1 ()").arg(r),
|
insilmaril@721
|
2427 |
QString ("%1 %2").arg(r).arg(getObjectName(bo))
|
insilmaril@721
|
2428 |
);
|
insilmaril@749
|
2429 |
*/
|
insilmaril@749
|
2430 |
bi->toggleScroll();
|
insilmaril@749
|
2431 |
// selection.update();
|
insilmaril@746
|
2432 |
// FIXME-3 VM needed? scene()->update();
|
insilmaril@721
|
2433 |
return true;
|
insilmaril@721
|
2434 |
}
|
insilmaril@721
|
2435 |
return false;
|
insilmaril@721
|
2436 |
}
|
insilmaril@721
|
2437 |
|
insilmaril@721
|
2438 |
void VymModel::toggleScroll()
|
insilmaril@721
|
2439 |
{
|
insilmaril@749
|
2440 |
BranchItem *bi=(BranchItem*)getSelectedBranchItem();
|
insilmaril@749
|
2441 |
if (bi && bi->getType()==TreeItem::Branch )
|
insilmaril@721
|
2442 |
{
|
insilmaril@749
|
2443 |
if (bi->isScrolled())
|
insilmaril@749
|
2444 |
unscrollBranch (bi);
|
insilmaril@721
|
2445 |
else
|
insilmaril@749
|
2446 |
scrollBranch (bi);
|
insilmaril@721
|
2447 |
}
|
insilmaril@721
|
2448 |
}
|
insilmaril@721
|
2449 |
|
insilmaril@746
|
2450 |
void VymModel::unscrollChildren() // FIXME-1 first, next moved to vymmodel
|
insilmaril@746
|
2451 |
|
insilmaril@746
|
2452 |
{
|
insilmaril@746
|
2453 |
/*
|
insilmaril@735
|
2454 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
2455 |
if (bo)
|
insilmaril@721
|
2456 |
{
|
insilmaril@721
|
2457 |
bo->first();
|
insilmaril@721
|
2458 |
while (bo)
|
insilmaril@721
|
2459 |
{
|
insilmaril@721
|
2460 |
if (bo->isScrolled()) unscrollBranch (bo);
|
insilmaril@721
|
2461 |
bo=bo->next();
|
insilmaril@721
|
2462 |
}
|
insilmaril@721
|
2463 |
}
|
insilmaril@746
|
2464 |
*/
|
insilmaril@721
|
2465 |
}
|
insilmaril@746
|
2466 |
|
insilmaril@753
|
2467 |
void VymModel::addFloatImage (const QPixmap &img) //FIXME-2
|
insilmaril@753
|
2468 |
{
|
insilmaril@753
|
2469 |
/*
|
insilmaril@735
|
2470 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
2471 |
if (bo)
|
insilmaril@721
|
2472 |
{
|
insilmaril@721
|
2473 |
FloatImageObj *fio=bo->addFloatImage();
|
insilmaril@721
|
2474 |
fio->load(img);
|
insilmaril@721
|
2475 |
fio->setOriginalFilename("No original filename (image added by dropevent)");
|
insilmaril@721
|
2476 |
QString s=getSelectString(bo);
|
insilmaril@721
|
2477 |
saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
|
insilmaril@721
|
2478 |
saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
|
insilmaril@721
|
2479 |
reposition();
|
insilmaril@746
|
2480 |
// FIXME-3 VM needed? scene()->update();
|
insilmaril@721
|
2481 |
}
|
insilmaril@753
|
2482 |
*/
|
insilmaril@721
|
2483 |
}
|
insilmaril@721
|
2484 |
|
insilmaril@721
|
2485 |
|
insilmaril@753
|
2486 |
void VymModel::colorBranch (QColor c) //FIXME-2
|
insilmaril@753
|
2487 |
{
|
insilmaril@753
|
2488 |
/*
|
insilmaril@735
|
2489 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
2490 |
if (bo)
|
insilmaril@721
|
2491 |
{
|
insilmaril@721
|
2492 |
saveState(
|
insilmaril@721
|
2493 |
bo,
|
insilmaril@721
|
2494 |
QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
|
insilmaril@721
|
2495 |
bo,
|
insilmaril@721
|
2496 |
QString ("colorBranch (\"%1\")").arg(c.name()),
|
insilmaril@721
|
2497 |
QString("Set color of %1 to %2").arg(getObjectName(bo)).arg(c.name())
|
insilmaril@721
|
2498 |
);
|
insilmaril@721
|
2499 |
bo->setColor(c); // color branch
|
insilmaril@721
|
2500 |
}
|
insilmaril@753
|
2501 |
*/
|
insilmaril@721
|
2502 |
}
|
insilmaril@721
|
2503 |
|
insilmaril@753
|
2504 |
void VymModel::colorSubtree (QColor c) //FIXME-2
|
insilmaril@753
|
2505 |
{
|
insilmaril@753
|
2506 |
/*
|
insilmaril@735
|
2507 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
2508 |
if (bo)
|
insilmaril@721
|
2509 |
{
|
insilmaril@721
|
2510 |
saveStateChangingPart(
|
insilmaril@721
|
2511 |
bo,
|
insilmaril@721
|
2512 |
bo,
|
insilmaril@721
|
2513 |
QString ("colorSubtree (\"%1\")").arg(c.name()),
|
insilmaril@721
|
2514 |
QString ("Set color of %1 and children to %2").arg(getObjectName(bo)).arg(c.name())
|
insilmaril@721
|
2515 |
);
|
insilmaril@721
|
2516 |
bo->setColorSubtree (c); // color links, color children
|
insilmaril@721
|
2517 |
}
|
insilmaril@753
|
2518 |
*/
|
insilmaril@721
|
2519 |
}
|
insilmaril@721
|
2520 |
|
insilmaril@753
|
2521 |
QColor VymModel::getCurrentHeadingColor() //FIXME-2
|
insilmaril@753
|
2522 |
{
|
insilmaril@753
|
2523 |
/*
|
insilmaril@735
|
2524 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
2525 |
if (bo) return bo->getColor();
|
insilmaril@721
|
2526 |
|
insilmaril@721
|
2527 |
QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
|
insilmaril@753
|
2528 |
*/
|
insilmaril@721
|
2529 |
return Qt::black;
|
insilmaril@721
|
2530 |
}
|
insilmaril@721
|
2531 |
|
insilmaril@721
|
2532 |
|
insilmaril@721
|
2533 |
|
insilmaril@753
|
2534 |
void VymModel::editURL() //FIXME-2
|
insilmaril@753
|
2535 |
{
|
insilmaril@753
|
2536 |
/*
|
insilmaril@735
|
2537 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
2538 |
if (bo)
|
insilmaril@721
|
2539 |
{
|
insilmaril@721
|
2540 |
bool ok;
|
insilmaril@721
|
2541 |
QString text = QInputDialog::getText(
|
insilmaril@721
|
2542 |
"VYM", tr("Enter URL:"), QLineEdit::Normal,
|
insilmaril@721
|
2543 |
bo->getURL(), &ok, NULL);
|
insilmaril@721
|
2544 |
if ( ok)
|
insilmaril@721
|
2545 |
// user entered something and pressed OK
|
insilmaril@721
|
2546 |
setURL(text);
|
insilmaril@721
|
2547 |
}
|
insilmaril@753
|
2548 |
*/
|
insilmaril@721
|
2549 |
}
|
insilmaril@721
|
2550 |
|
insilmaril@753
|
2551 |
void VymModel::editLocalURL() //FIXME-2
|
insilmaril@753
|
2552 |
{
|
insilmaril@753
|
2553 |
/*
|
insilmaril@735
|
2554 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
2555 |
if (bo)
|
insilmaril@721
|
2556 |
{
|
insilmaril@721
|
2557 |
QStringList filters;
|
insilmaril@721
|
2558 |
filters <<"All files (*)";
|
insilmaril@721
|
2559 |
filters << tr("Text","Filedialog") + " (*.txt)";
|
insilmaril@721
|
2560 |
filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
|
insilmaril@721
|
2561 |
filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
|
insilmaril@721
|
2562 |
filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
|
insilmaril@721
|
2563 |
QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
|
insilmaril@721
|
2564 |
fd->setFilters (filters);
|
insilmaril@721
|
2565 |
fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
|
insilmaril@721
|
2566 |
fd->setDirectory (lastFileDir);
|
insilmaril@721
|
2567 |
if (! bo->getVymLink().isEmpty() )
|
insilmaril@721
|
2568 |
fd->selectFile( bo->getURL() );
|
insilmaril@721
|
2569 |
fd->show();
|
insilmaril@721
|
2570 |
|
insilmaril@721
|
2571 |
if ( fd->exec() == QDialog::Accepted )
|
insilmaril@721
|
2572 |
{
|
insilmaril@721
|
2573 |
lastFileDir=QDir (fd->directory().path());
|
insilmaril@721
|
2574 |
setURL (fd->selectedFile() );
|
insilmaril@721
|
2575 |
}
|
insilmaril@721
|
2576 |
}
|
insilmaril@753
|
2577 |
*/
|
insilmaril@721
|
2578 |
}
|
insilmaril@721
|
2579 |
|
insilmaril@721
|
2580 |
|
insilmaril@753
|
2581 |
void VymModel::editHeading2URL() //FIXME-2
|
insilmaril@753
|
2582 |
{
|
insilmaril@753
|
2583 |
/*
|
insilmaril@735
|
2584 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
2585 |
if (bo)
|
insilmaril@721
|
2586 |
setURL (bo->getHeading());
|
insilmaril@753
|
2587 |
*/
|
insilmaril@721
|
2588 |
}
|
insilmaril@721
|
2589 |
|
insilmaril@753
|
2590 |
void VymModel::editBugzilla2URL() //FIXME-2
|
insilmaril@753
|
2591 |
{
|
insilmaril@753
|
2592 |
/*
|
insilmaril@735
|
2593 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
2594 |
if (bo)
|
insilmaril@721
|
2595 |
{
|
insilmaril@721
|
2596 |
QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
|
insilmaril@721
|
2597 |
setURL (url);
|
insilmaril@721
|
2598 |
}
|
insilmaril@753
|
2599 |
*/
|
insilmaril@721
|
2600 |
}
|
insilmaril@721
|
2601 |
|
insilmaril@753
|
2602 |
void VymModel::editFATE2URL() //FIXME-2
|
insilmaril@753
|
2603 |
{
|
insilmaril@753
|
2604 |
/*
|
insilmaril@735
|
2605 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
2606 |
if (bo)
|
insilmaril@721
|
2607 |
{
|
insilmaril@721
|
2608 |
QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
|
insilmaril@721
|
2609 |
saveState(
|
insilmaril@721
|
2610 |
bo,
|
insilmaril@721
|
2611 |
"setURL (\""+bo->getURL()+"\")",
|
insilmaril@721
|
2612 |
bo,
|
insilmaril@721
|
2613 |
"setURL (\""+url+"\")",
|
insilmaril@721
|
2614 |
QString("Use heading of %1 as link to FATE").arg(getObjectName(bo))
|
insilmaril@721
|
2615 |
);
|
insilmaril@721
|
2616 |
bo->setURL (url);
|
insilmaril@721
|
2617 |
updateActions();
|
insilmaril@721
|
2618 |
}
|
insilmaril@753
|
2619 |
*/
|
insilmaril@721
|
2620 |
}
|
insilmaril@721
|
2621 |
|
insilmaril@721
|
2622 |
void VymModel::editVymLink()
|
insilmaril@721
|
2623 |
{
|
insilmaril@753
|
2624 |
BranchItem *bi=getSelectedBranchItem();
|
insilmaril@753
|
2625 |
if (bi)
|
insilmaril@721
|
2626 |
{
|
insilmaril@721
|
2627 |
QStringList filters;
|
insilmaril@721
|
2628 |
filters <<"VYM map (*.vym)";
|
insilmaril@721
|
2629 |
QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
|
insilmaril@721
|
2630 |
fd->setFilters (filters);
|
insilmaril@721
|
2631 |
fd->setCaption(vymName+" - " +tr("Link to another map"));
|
insilmaril@721
|
2632 |
fd->setDirectory (lastFileDir);
|
insilmaril@753
|
2633 |
if (! bi->getVymLink().isEmpty() )
|
insilmaril@753
|
2634 |
fd->selectFile( bi->getVymLink() );
|
insilmaril@721
|
2635 |
fd->show();
|
insilmaril@721
|
2636 |
|
insilmaril@721
|
2637 |
QString fn;
|
insilmaril@721
|
2638 |
if ( fd->exec() == QDialog::Accepted )
|
insilmaril@721
|
2639 |
{
|
insilmaril@721
|
2640 |
lastFileDir=QDir (fd->directory().path());
|
insilmaril@721
|
2641 |
saveState(
|
insilmaril@753
|
2642 |
bi,
|
insilmaril@753
|
2643 |
"setVymLink (\""+bi->getVymLink()+"\")",
|
insilmaril@753
|
2644 |
bi,
|
insilmaril@721
|
2645 |
"setVymLink (\""+fd->selectedFile()+"\")",
|
insilmaril@753
|
2646 |
QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
|
insilmaril@721
|
2647 |
);
|
insilmaril@746
|
2648 |
setVymLink (fd->selectedFile() ); // FIXME-2 ok?
|
insilmaril@721
|
2649 |
}
|
insilmaril@721
|
2650 |
}
|
insilmaril@721
|
2651 |
}
|
insilmaril@721
|
2652 |
|
insilmaril@753
|
2653 |
void VymModel::setVymLink (const QString &s) // FIXME-3 no savestate?
|
insilmaril@721
|
2654 |
{
|
insilmaril@721
|
2655 |
// Internal function, no saveState needed
|
insilmaril@753
|
2656 |
BranchItem *bi=getSelectedBranchItem();
|
insilmaril@753
|
2657 |
if (bi)
|
insilmaril@721
|
2658 |
{
|
insilmaril@753
|
2659 |
bi->getBranchObj()->setVymLink(s); //FIXME-3 check getBO
|
insilmaril@721
|
2660 |
reposition();
|
insilmaril@721
|
2661 |
updateActions();
|
insilmaril@753
|
2662 |
//selection.update();
|
insilmaril@721
|
2663 |
ensureSelectionVisible();
|
insilmaril@721
|
2664 |
}
|
insilmaril@721
|
2665 |
}
|
insilmaril@721
|
2666 |
|
insilmaril@721
|
2667 |
void VymModel::deleteVymLink()
|
insilmaril@721
|
2668 |
{
|
insilmaril@753
|
2669 |
BranchItem *bi=getSelectedBranchItem();
|
insilmaril@753
|
2670 |
if (bi)
|
insilmaril@721
|
2671 |
{
|
insilmaril@721
|
2672 |
saveState(
|
insilmaril@753
|
2673 |
bi,
|
insilmaril@753
|
2674 |
"setVymLink (\""+bi->getBranchObj()->getVymLink()+"\")", //FIXME-3 check getBO
|
insilmaril@753
|
2675 |
|
insilmaril@753
|
2676 |
bi,
|
insilmaril@721
|
2677 |
"setVymLink (\"\")",
|
insilmaril@753
|
2678 |
QString("Unset vymlink of %1").arg(getObjectName(bi))
|
insilmaril@721
|
2679 |
);
|
insilmaril@753
|
2680 |
bi->getBranchObj()->setVymLink ("" ); //FIXME-3 check getBO
|
insilmaril@721
|
2681 |
updateActions();
|
insilmaril@721
|
2682 |
reposition();
|
insilmaril@746
|
2683 |
// FIXME-3 VM needed? scene()->update();
|
insilmaril@721
|
2684 |
}
|
insilmaril@721
|
2685 |
}
|
insilmaril@721
|
2686 |
|
insilmaril@721
|
2687 |
QString VymModel::getVymLink()
|
insilmaril@721
|
2688 |
{
|
insilmaril@753
|
2689 |
BranchItem *bi=getSelectedBranchItem();
|
insilmaril@753
|
2690 |
if (bi)
|
insilmaril@753
|
2691 |
return bi->getBranchObj()->getVymLink(); //FIXME-3 check getBO here...
|
insilmaril@721
|
2692 |
else
|
insilmaril@721
|
2693 |
return "";
|
insilmaril@721
|
2694 |
|
insilmaril@721
|
2695 |
}
|
insilmaril@721
|
2696 |
|
insilmaril@746
|
2697 |
QStringList VymModel::getVymLinks() // FIXME-1 first, next moved to vymmodel
|
insilmaril@746
|
2698 |
{
|
insilmaril@746
|
2699 |
return QStringList();
|
insilmaril@746
|
2700 |
/*
|
insilmaril@721
|
2701 |
QStringList links;
|
insilmaril@735
|
2702 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
2703 |
if (bo)
|
insilmaril@721
|
2704 |
{
|
insilmaril@721
|
2705 |
bo=bo->first();
|
insilmaril@721
|
2706 |
while (bo)
|
insilmaril@721
|
2707 |
{
|
insilmaril@721
|
2708 |
if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
|
insilmaril@721
|
2709 |
bo=bo->next();
|
insilmaril@721
|
2710 |
}
|
insilmaril@721
|
2711 |
}
|
insilmaril@721
|
2712 |
return links;
|
insilmaril@746
|
2713 |
*/
|
insilmaril@721
|
2714 |
}
|
insilmaril@721
|
2715 |
|
insilmaril@721
|
2716 |
|
insilmaril@753
|
2717 |
void VymModel::followXLink(int i) // FIXME-2
|
insilmaril@753
|
2718 |
{
|
insilmaril@753
|
2719 |
i=0;
|
insilmaril@753
|
2720 |
/*
|
insilmaril@735
|
2721 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
2722 |
if (bo)
|
insilmaril@721
|
2723 |
{
|
insilmaril@721
|
2724 |
bo=bo->XLinkTargetAt(i);
|
insilmaril@721
|
2725 |
if (bo)
|
insilmaril@721
|
2726 |
{
|
insilmaril@721
|
2727 |
selection.select(bo);
|
insilmaril@721
|
2728 |
ensureSelectionVisible();
|
insilmaril@721
|
2729 |
}
|
insilmaril@721
|
2730 |
}
|
insilmaril@753
|
2731 |
*/
|
insilmaril@721
|
2732 |
}
|
insilmaril@721
|
2733 |
|
insilmaril@753
|
2734 |
void VymModel::editXLink(int i) // FIXME-2 VM missing saveState
|
insilmaril@753
|
2735 |
{
|
insilmaril@753
|
2736 |
i=0;
|
insilmaril@753
|
2737 |
/*
|
insilmaril@735
|
2738 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
2739 |
if (bo)
|
insilmaril@721
|
2740 |
{
|
insilmaril@721
|
2741 |
XLinkObj *xlo=bo->XLinkAt(i);
|
insilmaril@721
|
2742 |
if (xlo)
|
insilmaril@721
|
2743 |
{
|
insilmaril@721
|
2744 |
EditXLinkDialog dia;
|
insilmaril@721
|
2745 |
dia.setXLink (xlo);
|
insilmaril@721
|
2746 |
dia.setSelection(bo);
|
insilmaril@721
|
2747 |
if (dia.exec() == QDialog::Accepted)
|
insilmaril@721
|
2748 |
{
|
insilmaril@721
|
2749 |
if (dia.useSettingsGlobal() )
|
insilmaril@721
|
2750 |
{
|
insilmaril@721
|
2751 |
setMapDefXLinkColor (xlo->getColor() );
|
insilmaril@721
|
2752 |
setMapDefXLinkWidth (xlo->getWidth() );
|
insilmaril@721
|
2753 |
}
|
insilmaril@721
|
2754 |
if (dia.deleteXLink())
|
insilmaril@721
|
2755 |
bo->deleteXLinkAt(i);
|
insilmaril@721
|
2756 |
}
|
insilmaril@721
|
2757 |
}
|
insilmaril@721
|
2758 |
}
|
insilmaril@753
|
2759 |
*/
|
insilmaril@721
|
2760 |
}
|
insilmaril@721
|
2761 |
|
insilmaril@721
|
2762 |
|
insilmaril@721
|
2763 |
|
insilmaril@721
|
2764 |
|
insilmaril@721
|
2765 |
|
insilmaril@721
|
2766 |
//////////////////////////////////////////////
|
insilmaril@721
|
2767 |
// Scripting
|
insilmaril@721
|
2768 |
//////////////////////////////////////////////
|
insilmaril@721
|
2769 |
|
insilmaril@721
|
2770 |
void VymModel::parseAtom(const QString &atom)
|
insilmaril@721
|
2771 |
{
|
insilmaril@753
|
2772 |
//BranchObj *selb=getSelectedBranch(); // FIXME-4
|
insilmaril@750
|
2773 |
TreeItem* selti=getSelectedItem();
|
insilmaril@750
|
2774 |
BranchItem *selbi=getSelectedBranchItem();
|
insilmaril@721
|
2775 |
QString s,t;
|
insilmaril@721
|
2776 |
double x,y;
|
insilmaril@721
|
2777 |
int n;
|
insilmaril@721
|
2778 |
bool b,ok;
|
insilmaril@721
|
2779 |
|
insilmaril@721
|
2780 |
// Split string s into command and parameters
|
insilmaril@721
|
2781 |
parser.parseAtom (atom);
|
insilmaril@721
|
2782 |
QString com=parser.getCommand();
|
insilmaril@721
|
2783 |
|
insilmaril@721
|
2784 |
// External commands
|
insilmaril@721
|
2785 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
2786 |
if (com=="addBranch")
|
insilmaril@721
|
2787 |
{
|
insilmaril@750
|
2788 |
if (!selti)
|
insilmaril@721
|
2789 |
{
|
insilmaril@721
|
2790 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
2791 |
} else if (! selbi )
|
insilmaril@721
|
2792 |
{
|
insilmaril@721
|
2793 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
2794 |
} else
|
insilmaril@721
|
2795 |
{
|
insilmaril@721
|
2796 |
QList <int> pl;
|
insilmaril@721
|
2797 |
pl << 0 <<1;
|
insilmaril@721
|
2798 |
if (parser.checkParCount(pl))
|
insilmaril@721
|
2799 |
{
|
insilmaril@721
|
2800 |
if (parser.parCount()==0)
|
insilmaril@721
|
2801 |
addNewBranch (0);
|
insilmaril@721
|
2802 |
else
|
insilmaril@721
|
2803 |
{
|
insilmaril@721
|
2804 |
n=parser.parInt (ok,0);
|
insilmaril@721
|
2805 |
if (ok ) addNewBranch (n);
|
insilmaril@721
|
2806 |
}
|
insilmaril@721
|
2807 |
}
|
insilmaril@721
|
2808 |
}
|
insilmaril@721
|
2809 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
2810 |
} else if (com=="addBranchBefore")
|
insilmaril@721
|
2811 |
{
|
insilmaril@750
|
2812 |
if (!selti)
|
insilmaril@721
|
2813 |
{
|
insilmaril@721
|
2814 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
2815 |
} else if (! selbi )
|
insilmaril@721
|
2816 |
{
|
insilmaril@721
|
2817 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
2818 |
} else
|
insilmaril@721
|
2819 |
{
|
insilmaril@721
|
2820 |
if (parser.parCount()==0)
|
insilmaril@721
|
2821 |
{
|
insilmaril@721
|
2822 |
addNewBranchBefore ();
|
insilmaril@721
|
2823 |
}
|
insilmaril@721
|
2824 |
}
|
insilmaril@721
|
2825 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
2826 |
} else if (com==QString("addMapCenter"))
|
insilmaril@721
|
2827 |
{
|
insilmaril@721
|
2828 |
if (parser.checkParCount(2))
|
insilmaril@721
|
2829 |
{
|
insilmaril@721
|
2830 |
x=parser.parDouble (ok,0);
|
insilmaril@721
|
2831 |
if (ok)
|
insilmaril@721
|
2832 |
{
|
insilmaril@721
|
2833 |
y=parser.parDouble (ok,1);
|
insilmaril@721
|
2834 |
if (ok) addMapCenter (QPointF(x,y));
|
insilmaril@721
|
2835 |
}
|
insilmaril@721
|
2836 |
}
|
insilmaril@721
|
2837 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
2838 |
} else if (com==QString("addMapReplace"))
|
insilmaril@721
|
2839 |
{
|
insilmaril@750
|
2840 |
if (!selti)
|
insilmaril@721
|
2841 |
{
|
insilmaril@721
|
2842 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
2843 |
} else if (! selbi )
|
insilmaril@721
|
2844 |
{
|
insilmaril@721
|
2845 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
2846 |
} else if (parser.checkParCount(1))
|
insilmaril@721
|
2847 |
{
|
insilmaril@721
|
2848 |
//s=parser.parString (ok,0); // selection
|
insilmaril@721
|
2849 |
t=parser.parString (ok,0); // path to map
|
insilmaril@721
|
2850 |
if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
|
insilmaril@753
|
2851 |
addMapReplaceInt(getSelectString(selbi),t);
|
insilmaril@721
|
2852 |
}
|
insilmaril@721
|
2853 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
2854 |
} else if (com==QString("addMapInsert"))
|
insilmaril@721
|
2855 |
{
|
insilmaril@750
|
2856 |
if (!selti)
|
insilmaril@721
|
2857 |
{
|
insilmaril@721
|
2858 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
2859 |
} else if (! selbi )
|
insilmaril@721
|
2860 |
{
|
insilmaril@721
|
2861 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
2862 |
} else
|
insilmaril@721
|
2863 |
{
|
insilmaril@721
|
2864 |
if (parser.checkParCount(2))
|
insilmaril@721
|
2865 |
{
|
insilmaril@721
|
2866 |
t=parser.parString (ok,0); // path to map
|
insilmaril@721
|
2867 |
n=parser.parInt(ok,1); // position
|
insilmaril@721
|
2868 |
if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
|
insilmaril@721
|
2869 |
addMapInsertInt(t,n);
|
insilmaril@721
|
2870 |
}
|
insilmaril@721
|
2871 |
}
|
insilmaril@721
|
2872 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@753
|
2873 |
} else /*if (com=="clearFlags") // FIXME-2
|
insilmaril@721
|
2874 |
{
|
insilmaril@750
|
2875 |
if (!selti )
|
insilmaril@721
|
2876 |
{
|
insilmaril@721
|
2877 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
2878 |
} else if (! selbi )
|
insilmaril@721
|
2879 |
{
|
insilmaril@721
|
2880 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
2881 |
} else if (parser.checkParCount(0))
|
insilmaril@721
|
2882 |
{
|
insilmaril@721
|
2883 |
selb->clearStandardFlags();
|
insilmaril@721
|
2884 |
selb->updateFlagsToolbar();
|
insilmaril@721
|
2885 |
}
|
insilmaril@721
|
2886 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@753
|
2887 |
} else */ if (com=="colorBranch")
|
insilmaril@721
|
2888 |
{
|
insilmaril@750
|
2889 |
if (!selti)
|
insilmaril@721
|
2890 |
{
|
insilmaril@721
|
2891 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
2892 |
} else if (! selbi )
|
insilmaril@721
|
2893 |
{
|
insilmaril@721
|
2894 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
2895 |
} else if (parser.checkParCount(1))
|
insilmaril@721
|
2896 |
{
|
insilmaril@721
|
2897 |
QColor c=parser.parColor (ok,0);
|
insilmaril@721
|
2898 |
if (ok) colorBranch (c);
|
insilmaril@721
|
2899 |
}
|
insilmaril@721
|
2900 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
2901 |
} else if (com=="colorSubtree")
|
insilmaril@721
|
2902 |
{
|
insilmaril@750
|
2903 |
if (!selti)
|
insilmaril@721
|
2904 |
{
|
insilmaril@721
|
2905 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
2906 |
} else if (! selbi )
|
insilmaril@721
|
2907 |
{
|
insilmaril@721
|
2908 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
2909 |
} else if (parser.checkParCount(1))
|
insilmaril@721
|
2910 |
{
|
insilmaril@721
|
2911 |
QColor c=parser.parColor (ok,0);
|
insilmaril@721
|
2912 |
if (ok) colorSubtree (c);
|
insilmaril@721
|
2913 |
}
|
insilmaril@721
|
2914 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
2915 |
} else if (com=="copy")
|
insilmaril@721
|
2916 |
{
|
insilmaril@750
|
2917 |
if (!selti)
|
insilmaril@721
|
2918 |
{
|
insilmaril@721
|
2919 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
2920 |
} else if (! selbi )
|
insilmaril@721
|
2921 |
{
|
insilmaril@721
|
2922 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
2923 |
} else if (parser.checkParCount(0))
|
insilmaril@721
|
2924 |
{
|
insilmaril@746
|
2925 |
//FIXME-1 missing action for copy
|
insilmaril@721
|
2926 |
}
|
insilmaril@721
|
2927 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
2928 |
} else if (com=="cut")
|
insilmaril@721
|
2929 |
{
|
insilmaril@750
|
2930 |
if (!selti)
|
insilmaril@721
|
2931 |
{
|
insilmaril@721
|
2932 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@735
|
2933 |
} else if ( selectionType()!=TreeItem::Branch &&
|
insilmaril@735
|
2934 |
selectionType()!=TreeItem::MapCenter &&
|
insilmaril@735
|
2935 |
selectionType()!=TreeItem::Image )
|
insilmaril@721
|
2936 |
{
|
insilmaril@721
|
2937 |
parser.setError (Aborted,"Type of selection is not a branch or floatimage");
|
insilmaril@721
|
2938 |
} else if (parser.checkParCount(0))
|
insilmaril@721
|
2939 |
{
|
insilmaril@721
|
2940 |
cut();
|
insilmaril@721
|
2941 |
}
|
insilmaril@721
|
2942 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
2943 |
} else if (com=="delete")
|
insilmaril@721
|
2944 |
{
|
insilmaril@750
|
2945 |
if (!selti)
|
insilmaril@721
|
2946 |
{
|
insilmaril@721
|
2947 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@721
|
2948 |
}
|
insilmaril@735
|
2949 |
/*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
|
insilmaril@721
|
2950 |
{
|
insilmaril@721
|
2951 |
parser.setError (Aborted,"Type of selection is wrong.");
|
insilmaril@721
|
2952 |
}
|
insilmaril@721
|
2953 |
*/
|
insilmaril@721
|
2954 |
else if (parser.checkParCount(0))
|
insilmaril@721
|
2955 |
{
|
insilmaril@721
|
2956 |
deleteSelection();
|
insilmaril@721
|
2957 |
}
|
insilmaril@721
|
2958 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
2959 |
} else if (com=="deleteKeepChildren")
|
insilmaril@721
|
2960 |
{
|
insilmaril@750
|
2961 |
if (!selti)
|
insilmaril@721
|
2962 |
{
|
insilmaril@721
|
2963 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
2964 |
} else if (! selbi )
|
insilmaril@721
|
2965 |
{
|
insilmaril@721
|
2966 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
2967 |
} else if (parser.checkParCount(0))
|
insilmaril@721
|
2968 |
{
|
insilmaril@721
|
2969 |
deleteKeepChildren();
|
insilmaril@721
|
2970 |
}
|
insilmaril@721
|
2971 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
2972 |
} else if (com=="deleteChildren")
|
insilmaril@721
|
2973 |
{
|
insilmaril@750
|
2974 |
if (!selti)
|
insilmaril@721
|
2975 |
{
|
insilmaril@721
|
2976 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
2977 |
} else if (! selbi)
|
insilmaril@721
|
2978 |
{
|
insilmaril@721
|
2979 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
2980 |
} else if (parser.checkParCount(0))
|
insilmaril@721
|
2981 |
{
|
insilmaril@721
|
2982 |
deleteChildren();
|
insilmaril@721
|
2983 |
}
|
insilmaril@721
|
2984 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
2985 |
} else if (com=="exportASCII")
|
insilmaril@721
|
2986 |
{
|
insilmaril@721
|
2987 |
QString fname="";
|
insilmaril@721
|
2988 |
ok=true;
|
insilmaril@721
|
2989 |
if (parser.parCount()>=1)
|
insilmaril@721
|
2990 |
// Hey, we even have a filename
|
insilmaril@721
|
2991 |
fname=parser.parString(ok,0);
|
insilmaril@721
|
2992 |
if (!ok)
|
insilmaril@721
|
2993 |
{
|
insilmaril@721
|
2994 |
parser.setError (Aborted,"Could not read filename");
|
insilmaril@721
|
2995 |
} else
|
insilmaril@721
|
2996 |
{
|
insilmaril@721
|
2997 |
exportASCII (fname,false);
|
insilmaril@721
|
2998 |
}
|
insilmaril@721
|
2999 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3000 |
} else if (com=="exportImage")
|
insilmaril@721
|
3001 |
{
|
insilmaril@721
|
3002 |
QString fname="";
|
insilmaril@721
|
3003 |
ok=true;
|
insilmaril@721
|
3004 |
if (parser.parCount()>=2)
|
insilmaril@721
|
3005 |
// Hey, we even have a filename
|
insilmaril@721
|
3006 |
fname=parser.parString(ok,0);
|
insilmaril@721
|
3007 |
if (!ok)
|
insilmaril@721
|
3008 |
{
|
insilmaril@721
|
3009 |
parser.setError (Aborted,"Could not read filename");
|
insilmaril@721
|
3010 |
} else
|
insilmaril@721
|
3011 |
{
|
insilmaril@721
|
3012 |
QString format="PNG";
|
insilmaril@721
|
3013 |
if (parser.parCount()>=2)
|
insilmaril@721
|
3014 |
{
|
insilmaril@721
|
3015 |
format=parser.parString(ok,1);
|
insilmaril@721
|
3016 |
}
|
insilmaril@721
|
3017 |
exportImage (fname,false,format);
|
insilmaril@721
|
3018 |
}
|
insilmaril@721
|
3019 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3020 |
} else if (com=="exportXHTML")
|
insilmaril@721
|
3021 |
{
|
insilmaril@721
|
3022 |
QString fname="";
|
insilmaril@721
|
3023 |
ok=true;
|
insilmaril@721
|
3024 |
if (parser.parCount()>=2)
|
insilmaril@721
|
3025 |
// Hey, we even have a filename
|
insilmaril@721
|
3026 |
fname=parser.parString(ok,1);
|
insilmaril@721
|
3027 |
if (!ok)
|
insilmaril@721
|
3028 |
{
|
insilmaril@721
|
3029 |
parser.setError (Aborted,"Could not read filename");
|
insilmaril@721
|
3030 |
} else
|
insilmaril@721
|
3031 |
{
|
insilmaril@721
|
3032 |
exportXHTML (fname,false);
|
insilmaril@721
|
3033 |
}
|
insilmaril@721
|
3034 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3035 |
} else if (com=="exportXML")
|
insilmaril@721
|
3036 |
{
|
insilmaril@721
|
3037 |
QString fname="";
|
insilmaril@721
|
3038 |
ok=true;
|
insilmaril@721
|
3039 |
if (parser.parCount()>=2)
|
insilmaril@721
|
3040 |
// Hey, we even have a filename
|
insilmaril@721
|
3041 |
fname=parser.parString(ok,1);
|
insilmaril@721
|
3042 |
if (!ok)
|
insilmaril@721
|
3043 |
{
|
insilmaril@721
|
3044 |
parser.setError (Aborted,"Could not read filename");
|
insilmaril@721
|
3045 |
} else
|
insilmaril@721
|
3046 |
{
|
insilmaril@721
|
3047 |
exportXML (fname,false);
|
insilmaril@721
|
3048 |
}
|
insilmaril@721
|
3049 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3050 |
} else if (com=="importDir")
|
insilmaril@721
|
3051 |
{
|
insilmaril@750
|
3052 |
if (!selti)
|
insilmaril@721
|
3053 |
{
|
insilmaril@721
|
3054 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3055 |
} else if (! selbi )
|
insilmaril@721
|
3056 |
{
|
insilmaril@721
|
3057 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3058 |
} else if (parser.checkParCount(1))
|
insilmaril@721
|
3059 |
{
|
insilmaril@721
|
3060 |
s=parser.parString(ok,0);
|
insilmaril@721
|
3061 |
if (ok) importDirInt(s);
|
insilmaril@721
|
3062 |
}
|
insilmaril@721
|
3063 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@753
|
3064 |
} else /* FIXME-2 if (com=="linkTo")
|
insilmaril@721
|
3065 |
{
|
insilmaril@750
|
3066 |
if (!selti)
|
insilmaril@721
|
3067 |
{
|
insilmaril@721
|
3068 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3069 |
} else if ( selbi)
|
insilmaril@721
|
3070 |
{
|
insilmaril@721
|
3071 |
if (parser.checkParCount(4))
|
insilmaril@721
|
3072 |
{
|
insilmaril@721
|
3073 |
// 0 selectstring of parent
|
insilmaril@721
|
3074 |
// 1 num in parent (for branches)
|
insilmaril@721
|
3075 |
// 2,3 x,y of mainbranch or mapcenter
|
insilmaril@721
|
3076 |
s=parser.parString(ok,0);
|
insilmaril@721
|
3077 |
LinkableMapObj *dst=findObjBySelect (s);
|
insilmaril@721
|
3078 |
if (dst)
|
insilmaril@721
|
3079 |
{
|
insilmaril@721
|
3080 |
if (typeid(*dst) == typeid(BranchObj) )
|
insilmaril@721
|
3081 |
{
|
insilmaril@721
|
3082 |
// Get number in parent
|
insilmaril@721
|
3083 |
n=parser.parInt (ok,1);
|
insilmaril@721
|
3084 |
if (ok)
|
insilmaril@721
|
3085 |
{
|
insilmaril@721
|
3086 |
selb->linkTo ((BranchObj*)(dst),n);
|
insilmaril@721
|
3087 |
selection.update();
|
insilmaril@721
|
3088 |
}
|
insilmaril@721
|
3089 |
} else if (typeid(*dst) == typeid(MapCenterObj) )
|
insilmaril@721
|
3090 |
{
|
insilmaril@721
|
3091 |
selb->linkTo ((BranchObj*)(dst),-1);
|
insilmaril@721
|
3092 |
// Get coordinates of mainbranch
|
insilmaril@721
|
3093 |
x=parser.parDouble(ok,2);
|
insilmaril@721
|
3094 |
if (ok)
|
insilmaril@721
|
3095 |
{
|
insilmaril@721
|
3096 |
y=parser.parDouble(ok,3);
|
insilmaril@721
|
3097 |
if (ok)
|
insilmaril@721
|
3098 |
{
|
insilmaril@753
|
3099 |
selbi->move (x,y);
|
insilmaril@721
|
3100 |
selection.update();
|
insilmaril@721
|
3101 |
}
|
insilmaril@721
|
3102 |
}
|
insilmaril@721
|
3103 |
}
|
insilmaril@721
|
3104 |
}
|
insilmaril@721
|
3105 |
}
|
insilmaril@735
|
3106 |
} else if ( selectionType() == TreeItem::Image)
|
insilmaril@721
|
3107 |
{
|
insilmaril@721
|
3108 |
if (parser.checkParCount(1))
|
insilmaril@721
|
3109 |
{
|
insilmaril@721
|
3110 |
// 0 selectstring of parent
|
insilmaril@721
|
3111 |
s=parser.parString(ok,0);
|
insilmaril@721
|
3112 |
LinkableMapObj *dst=findObjBySelect (s);
|
insilmaril@721
|
3113 |
if (dst)
|
insilmaril@721
|
3114 |
{
|
insilmaril@721
|
3115 |
if (typeid(*dst) == typeid(BranchObj) ||
|
insilmaril@721
|
3116 |
typeid(*dst) == typeid(MapCenterObj))
|
insilmaril@721
|
3117 |
linkFloatImageTo (getSelectString(dst));
|
insilmaril@721
|
3118 |
} else
|
insilmaril@721
|
3119 |
parser.setError (Aborted,"Destination is not a branch");
|
insilmaril@721
|
3120 |
}
|
insilmaril@721
|
3121 |
} else
|
insilmaril@721
|
3122 |
parser.setError (Aborted,"Type of selection is not a floatimage or branch");
|
insilmaril@721
|
3123 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@753
|
3124 |
} else */ if (com=="loadImage")
|
insilmaril@721
|
3125 |
{
|
insilmaril@750
|
3126 |
if (!selti)
|
insilmaril@721
|
3127 |
{
|
insilmaril@721
|
3128 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3129 |
} else if (! selbi )
|
insilmaril@721
|
3130 |
{
|
insilmaril@721
|
3131 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3132 |
} else if (parser.checkParCount(1))
|
insilmaril@721
|
3133 |
{
|
insilmaril@721
|
3134 |
s=parser.parString(ok,0);
|
insilmaril@721
|
3135 |
if (ok) loadFloatImageInt (s);
|
insilmaril@721
|
3136 |
}
|
insilmaril@721
|
3137 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3138 |
} else if (com=="moveBranchUp")
|
insilmaril@721
|
3139 |
{
|
insilmaril@750
|
3140 |
if (!selti )
|
insilmaril@721
|
3141 |
{
|
insilmaril@721
|
3142 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3143 |
} else if (! selbi )
|
insilmaril@721
|
3144 |
{
|
insilmaril@721
|
3145 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3146 |
} else if (parser.checkParCount(0))
|
insilmaril@721
|
3147 |
{
|
insilmaril@721
|
3148 |
moveBranchUp();
|
insilmaril@721
|
3149 |
}
|
insilmaril@721
|
3150 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3151 |
} else if (com=="moveBranchDown")
|
insilmaril@721
|
3152 |
{
|
insilmaril@750
|
3153 |
if (!selti )
|
insilmaril@721
|
3154 |
{
|
insilmaril@721
|
3155 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3156 |
} else if (! selbi )
|
insilmaril@721
|
3157 |
{
|
insilmaril@721
|
3158 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3159 |
} else if (parser.checkParCount(0))
|
insilmaril@721
|
3160 |
{
|
insilmaril@721
|
3161 |
moveBranchDown();
|
insilmaril@721
|
3162 |
}
|
insilmaril@721
|
3163 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3164 |
} else if (com=="move")
|
insilmaril@721
|
3165 |
{
|
insilmaril@750
|
3166 |
if (!selti )
|
insilmaril@721
|
3167 |
{
|
insilmaril@721
|
3168 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@735
|
3169 |
} else if ( selectionType()!=TreeItem::Branch &&
|
insilmaril@735
|
3170 |
selectionType()!=TreeItem::MapCenter &&
|
insilmaril@735
|
3171 |
selectionType()!=TreeItem::Image )
|
insilmaril@721
|
3172 |
{
|
insilmaril@721
|
3173 |
parser.setError (Aborted,"Type of selection is not a branch or floatimage");
|
insilmaril@721
|
3174 |
} else if (parser.checkParCount(2))
|
insilmaril@721
|
3175 |
{
|
insilmaril@721
|
3176 |
x=parser.parDouble (ok,0);
|
insilmaril@721
|
3177 |
if (ok)
|
insilmaril@721
|
3178 |
{
|
insilmaril@721
|
3179 |
y=parser.parDouble (ok,1);
|
insilmaril@721
|
3180 |
if (ok) move (x,y);
|
insilmaril@721
|
3181 |
}
|
insilmaril@721
|
3182 |
}
|
insilmaril@721
|
3183 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3184 |
} else if (com=="moveRel")
|
insilmaril@721
|
3185 |
{
|
insilmaril@750
|
3186 |
if (!selti )
|
insilmaril@721
|
3187 |
{
|
insilmaril@721
|
3188 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@735
|
3189 |
} else if ( selectionType()!=TreeItem::Branch &&
|
insilmaril@735
|
3190 |
selectionType()!=TreeItem::MapCenter &&
|
insilmaril@735
|
3191 |
selectionType()!=TreeItem::Image )
|
insilmaril@721
|
3192 |
{
|
insilmaril@721
|
3193 |
parser.setError (Aborted,"Type of selection is not a branch or floatimage");
|
insilmaril@721
|
3194 |
} else if (parser.checkParCount(2))
|
insilmaril@721
|
3195 |
{
|
insilmaril@721
|
3196 |
x=parser.parDouble (ok,0);
|
insilmaril@721
|
3197 |
if (ok)
|
insilmaril@721
|
3198 |
{
|
insilmaril@721
|
3199 |
y=parser.parDouble (ok,1);
|
insilmaril@721
|
3200 |
if (ok) moveRel (x,y);
|
insilmaril@721
|
3201 |
}
|
insilmaril@721
|
3202 |
}
|
insilmaril@721
|
3203 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3204 |
} else if (com=="nop")
|
insilmaril@721
|
3205 |
{
|
insilmaril@721
|
3206 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3207 |
} else if (com=="paste")
|
insilmaril@721
|
3208 |
{
|
insilmaril@750
|
3209 |
if (!selti )
|
insilmaril@721
|
3210 |
{
|
insilmaril@721
|
3211 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3212 |
} else if (! selbi )
|
insilmaril@721
|
3213 |
{
|
insilmaril@721
|
3214 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3215 |
} else if (parser.checkParCount(1))
|
insilmaril@721
|
3216 |
{
|
insilmaril@721
|
3217 |
n=parser.parInt (ok,0);
|
insilmaril@721
|
3218 |
if (ok) pasteNoSave(n);
|
insilmaril@721
|
3219 |
}
|
insilmaril@721
|
3220 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3221 |
} else if (com=="qa")
|
insilmaril@721
|
3222 |
{
|
insilmaril@750
|
3223 |
if (!selti )
|
insilmaril@721
|
3224 |
{
|
insilmaril@721
|
3225 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3226 |
} else if (! selbi )
|
insilmaril@721
|
3227 |
{
|
insilmaril@721
|
3228 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3229 |
} else if (parser.checkParCount(4))
|
insilmaril@721
|
3230 |
{
|
insilmaril@721
|
3231 |
QString c,u;
|
insilmaril@721
|
3232 |
c=parser.parString (ok,0);
|
insilmaril@721
|
3233 |
if (!ok)
|
insilmaril@721
|
3234 |
{
|
insilmaril@721
|
3235 |
parser.setError (Aborted,"No comment given");
|
insilmaril@721
|
3236 |
} else
|
insilmaril@721
|
3237 |
{
|
insilmaril@721
|
3238 |
s=parser.parString (ok,1);
|
insilmaril@721
|
3239 |
if (!ok)
|
insilmaril@721
|
3240 |
{
|
insilmaril@721
|
3241 |
parser.setError (Aborted,"First parameter is not a string");
|
insilmaril@721
|
3242 |
} else
|
insilmaril@721
|
3243 |
{
|
insilmaril@721
|
3244 |
t=parser.parString (ok,2);
|
insilmaril@721
|
3245 |
if (!ok)
|
insilmaril@721
|
3246 |
{
|
insilmaril@721
|
3247 |
parser.setError (Aborted,"Condition is not a string");
|
insilmaril@721
|
3248 |
} else
|
insilmaril@721
|
3249 |
{
|
insilmaril@721
|
3250 |
u=parser.parString (ok,3);
|
insilmaril@721
|
3251 |
if (!ok)
|
insilmaril@721
|
3252 |
{
|
insilmaril@721
|
3253 |
parser.setError (Aborted,"Third parameter is not a string");
|
insilmaril@721
|
3254 |
} else
|
insilmaril@721
|
3255 |
{
|
insilmaril@721
|
3256 |
if (s!="heading")
|
insilmaril@721
|
3257 |
{
|
insilmaril@721
|
3258 |
parser.setError (Aborted,"Unknown type: "+s);
|
insilmaril@721
|
3259 |
} else
|
insilmaril@721
|
3260 |
{
|
insilmaril@721
|
3261 |
if (! (t=="eq") )
|
insilmaril@721
|
3262 |
{
|
insilmaril@721
|
3263 |
parser.setError (Aborted,"Unknown operator: "+t);
|
insilmaril@721
|
3264 |
} else
|
insilmaril@721
|
3265 |
{
|
insilmaril@753
|
3266 |
if (! selbi )
|
insilmaril@721
|
3267 |
{
|
insilmaril@721
|
3268 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3269 |
} else
|
insilmaril@721
|
3270 |
{
|
insilmaril@753
|
3271 |
if (selbi->getHeading() == u)
|
insilmaril@721
|
3272 |
{
|
insilmaril@721
|
3273 |
cout << "PASSED: " << qPrintable (c) << endl;
|
insilmaril@721
|
3274 |
} else
|
insilmaril@721
|
3275 |
{
|
insilmaril@721
|
3276 |
cout << "FAILED: " << qPrintable (c) << endl;
|
insilmaril@721
|
3277 |
}
|
insilmaril@721
|
3278 |
}
|
insilmaril@721
|
3279 |
}
|
insilmaril@721
|
3280 |
}
|
insilmaril@721
|
3281 |
}
|
insilmaril@721
|
3282 |
}
|
insilmaril@721
|
3283 |
}
|
insilmaril@721
|
3284 |
}
|
insilmaril@721
|
3285 |
}
|
insilmaril@721
|
3286 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3287 |
} else if (com=="saveImage")
|
insilmaril@721
|
3288 |
{
|
insilmaril@721
|
3289 |
FloatImageObj *fio=selection.getFloatImage();
|
insilmaril@721
|
3290 |
if (!fio)
|
insilmaril@721
|
3291 |
{
|
insilmaril@721
|
3292 |
parser.setError (Aborted,"Type of selection is not an image");
|
insilmaril@721
|
3293 |
} else if (parser.checkParCount(2))
|
insilmaril@721
|
3294 |
{
|
insilmaril@721
|
3295 |
s=parser.parString(ok,0);
|
insilmaril@721
|
3296 |
if (ok)
|
insilmaril@721
|
3297 |
{
|
insilmaril@721
|
3298 |
t=parser.parString(ok,1);
|
insilmaril@721
|
3299 |
if (ok) saveFloatImageInt (fio,t,s);
|
insilmaril@721
|
3300 |
}
|
insilmaril@721
|
3301 |
}
|
insilmaril@721
|
3302 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3303 |
} else if (com=="scroll")
|
insilmaril@721
|
3304 |
{
|
insilmaril@750
|
3305 |
if (!selti)
|
insilmaril@721
|
3306 |
{
|
insilmaril@721
|
3307 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@750
|
3308 |
} else if (! selbi )
|
insilmaril@721
|
3309 |
{
|
insilmaril@721
|
3310 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3311 |
} else if (parser.checkParCount(0))
|
insilmaril@721
|
3312 |
{
|
insilmaril@750
|
3313 |
if (!scrollBranch (selbi))
|
insilmaril@721
|
3314 |
parser.setError (Aborted,"Could not scroll branch");
|
insilmaril@721
|
3315 |
}
|
insilmaril@721
|
3316 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3317 |
} else if (com=="select")
|
insilmaril@721
|
3318 |
{
|
insilmaril@721
|
3319 |
if (parser.checkParCount(1))
|
insilmaril@721
|
3320 |
{
|
insilmaril@721
|
3321 |
s=parser.parString(ok,0);
|
insilmaril@721
|
3322 |
if (ok) select (s);
|
insilmaril@721
|
3323 |
}
|
insilmaril@721
|
3324 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3325 |
} else if (com=="selectLastBranch")
|
insilmaril@721
|
3326 |
{
|
insilmaril@750
|
3327 |
if (!selti )
|
insilmaril@721
|
3328 |
{
|
insilmaril@721
|
3329 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3330 |
} else if (! selbi )
|
insilmaril@721
|
3331 |
{
|
insilmaril@721
|
3332 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3333 |
} else if (parser.checkParCount(0))
|
insilmaril@721
|
3334 |
{
|
insilmaril@750
|
3335 |
BranchItem *bi=selbi->getLastBranch();
|
insilmaril@750
|
3336 |
if (!bi)
|
insilmaril@721
|
3337 |
parser.setError (Aborted,"Could not select last branch");
|
insilmaril@750
|
3338 |
select (bi); // FIXME-3 was selectInt
|
insilmaril@721
|
3339 |
|
insilmaril@721
|
3340 |
}
|
insilmaril@721
|
3341 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@753
|
3342 |
} else /* FIXME-2 if (com=="selectLastImage")
|
insilmaril@721
|
3343 |
{
|
insilmaril@750
|
3344 |
if (!selti )
|
insilmaril@721
|
3345 |
{
|
insilmaril@721
|
3346 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3347 |
} else if (! selbi )
|
insilmaril@721
|
3348 |
{
|
insilmaril@721
|
3349 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3350 |
} else if (parser.checkParCount(0))
|
insilmaril@721
|
3351 |
{
|
insilmaril@721
|
3352 |
FloatImageObj *fio=selb->getLastFloatImage();
|
insilmaril@721
|
3353 |
if (!fio)
|
insilmaril@721
|
3354 |
parser.setError (Aborted,"Could not select last image");
|
insilmaril@750
|
3355 |
select (fio); // FIXME-3 was selectInt
|
insilmaril@721
|
3356 |
|
insilmaril@721
|
3357 |
}
|
insilmaril@721
|
3358 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@753
|
3359 |
} else */ if (com=="selectLatestAdded")
|
insilmaril@721
|
3360 |
{
|
insilmaril@761
|
3361 |
if (!latestAddedItem)
|
insilmaril@721
|
3362 |
{
|
insilmaril@721
|
3363 |
parser.setError (Aborted,"No latest added object");
|
insilmaril@721
|
3364 |
} else
|
insilmaril@721
|
3365 |
{
|
insilmaril@761
|
3366 |
if (!select (latestAddedItem))
|
insilmaril@761
|
3367 |
parser.setError (Aborted,"Could not select latest added object ");
|
insilmaril@721
|
3368 |
}
|
insilmaril@721
|
3369 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3370 |
} else if (com=="setFrameType")
|
insilmaril@721
|
3371 |
{
|
insilmaril@735
|
3372 |
if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
|
insilmaril@721
|
3373 |
{
|
insilmaril@721
|
3374 |
parser.setError (Aborted,"Type of selection does not allow setting frame type");
|
insilmaril@721
|
3375 |
}
|
insilmaril@721
|
3376 |
else if (parser.checkParCount(1))
|
insilmaril@721
|
3377 |
{
|
insilmaril@721
|
3378 |
s=parser.parString(ok,0);
|
insilmaril@721
|
3379 |
if (ok) setFrameType (s);
|
insilmaril@721
|
3380 |
}
|
insilmaril@721
|
3381 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3382 |
} else if (com=="setFramePenColor")
|
insilmaril@721
|
3383 |
{
|
insilmaril@735
|
3384 |
if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
|
insilmaril@721
|
3385 |
{
|
insilmaril@721
|
3386 |
parser.setError (Aborted,"Type of selection does not allow setting of pen color");
|
insilmaril@721
|
3387 |
}
|
insilmaril@721
|
3388 |
else if (parser.checkParCount(1))
|
insilmaril@721
|
3389 |
{
|
insilmaril@721
|
3390 |
QColor c=parser.parColor(ok,0);
|
insilmaril@721
|
3391 |
if (ok) setFramePenColor (c);
|
insilmaril@721
|
3392 |
}
|
insilmaril@721
|
3393 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3394 |
} else if (com=="setFrameBrushColor")
|
insilmaril@721
|
3395 |
{
|
insilmaril@735
|
3396 |
if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
|
insilmaril@721
|
3397 |
{
|
insilmaril@721
|
3398 |
parser.setError (Aborted,"Type of selection does not allow setting brush color");
|
insilmaril@721
|
3399 |
}
|
insilmaril@721
|
3400 |
else if (parser.checkParCount(1))
|
insilmaril@721
|
3401 |
{
|
insilmaril@721
|
3402 |
QColor c=parser.parColor(ok,0);
|
insilmaril@721
|
3403 |
if (ok) setFrameBrushColor (c);
|
insilmaril@721
|
3404 |
}
|
insilmaril@721
|
3405 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3406 |
} else if (com=="setFramePadding")
|
insilmaril@721
|
3407 |
{
|
insilmaril@735
|
3408 |
if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
|
insilmaril@721
|
3409 |
{
|
insilmaril@721
|
3410 |
parser.setError (Aborted,"Type of selection does not allow setting frame padding");
|
insilmaril@721
|
3411 |
}
|
insilmaril@721
|
3412 |
else if (parser.checkParCount(1))
|
insilmaril@721
|
3413 |
{
|
insilmaril@721
|
3414 |
n=parser.parInt(ok,0);
|
insilmaril@721
|
3415 |
if (ok) setFramePadding(n);
|
insilmaril@721
|
3416 |
}
|
insilmaril@721
|
3417 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3418 |
} else if (com=="setFrameBorderWidth")
|
insilmaril@721
|
3419 |
{
|
insilmaril@735
|
3420 |
if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
|
insilmaril@721
|
3421 |
{
|
insilmaril@721
|
3422 |
parser.setError (Aborted,"Type of selection does not allow setting frame border width");
|
insilmaril@721
|
3423 |
}
|
insilmaril@721
|
3424 |
else if (parser.checkParCount(1))
|
insilmaril@721
|
3425 |
{
|
insilmaril@721
|
3426 |
n=parser.parInt(ok,0);
|
insilmaril@721
|
3427 |
if (ok) setFrameBorderWidth (n);
|
insilmaril@721
|
3428 |
}
|
insilmaril@721
|
3429 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3430 |
} else if (com=="setMapAuthor")
|
insilmaril@721
|
3431 |
{
|
insilmaril@721
|
3432 |
if (parser.checkParCount(1))
|
insilmaril@721
|
3433 |
{
|
insilmaril@721
|
3434 |
s=parser.parString(ok,0);
|
insilmaril@721
|
3435 |
if (ok) setAuthor (s);
|
insilmaril@721
|
3436 |
}
|
insilmaril@721
|
3437 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3438 |
} else if (com=="setMapComment")
|
insilmaril@721
|
3439 |
{
|
insilmaril@721
|
3440 |
if (parser.checkParCount(1))
|
insilmaril@721
|
3441 |
{
|
insilmaril@721
|
3442 |
s=parser.parString(ok,0);
|
insilmaril@721
|
3443 |
if (ok) setComment(s);
|
insilmaril@721
|
3444 |
}
|
insilmaril@721
|
3445 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3446 |
} else if (com=="setMapBackgroundColor")
|
insilmaril@721
|
3447 |
{
|
insilmaril@750
|
3448 |
if (!selti )
|
insilmaril@721
|
3449 |
{
|
insilmaril@721
|
3450 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3451 |
} else if (! selbi )
|
insilmaril@721
|
3452 |
{
|
insilmaril@721
|
3453 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3454 |
} else if (parser.checkParCount(1))
|
insilmaril@721
|
3455 |
{
|
insilmaril@721
|
3456 |
QColor c=parser.parColor (ok,0);
|
insilmaril@721
|
3457 |
if (ok) setMapBackgroundColor (c);
|
insilmaril@721
|
3458 |
}
|
insilmaril@721
|
3459 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3460 |
} else if (com=="setMapDefLinkColor")
|
insilmaril@721
|
3461 |
{
|
insilmaril@750
|
3462 |
if (!selti )
|
insilmaril@721
|
3463 |
{
|
insilmaril@721
|
3464 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3465 |
} else if (! selbi )
|
insilmaril@721
|
3466 |
{
|
insilmaril@721
|
3467 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3468 |
} else if (parser.checkParCount(1))
|
insilmaril@721
|
3469 |
{
|
insilmaril@721
|
3470 |
QColor c=parser.parColor (ok,0);
|
insilmaril@721
|
3471 |
if (ok) setMapDefLinkColor (c);
|
insilmaril@721
|
3472 |
}
|
insilmaril@721
|
3473 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3474 |
} else if (com=="setMapLinkStyle")
|
insilmaril@721
|
3475 |
{
|
insilmaril@721
|
3476 |
if (parser.checkParCount(1))
|
insilmaril@721
|
3477 |
{
|
insilmaril@721
|
3478 |
s=parser.parString (ok,0);
|
insilmaril@721
|
3479 |
if (ok) setMapLinkStyle(s);
|
insilmaril@721
|
3480 |
}
|
insilmaril@721
|
3481 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3482 |
} else if (com=="setHeading")
|
insilmaril@721
|
3483 |
{
|
insilmaril@750
|
3484 |
if (!selti )
|
insilmaril@721
|
3485 |
{
|
insilmaril@721
|
3486 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3487 |
} else if (! selbi )
|
insilmaril@721
|
3488 |
{
|
insilmaril@721
|
3489 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3490 |
} else if (parser.checkParCount(1))
|
insilmaril@721
|
3491 |
{
|
insilmaril@721
|
3492 |
s=parser.parString (ok,0);
|
insilmaril@721
|
3493 |
if (ok)
|
insilmaril@721
|
3494 |
setHeading (s);
|
insilmaril@721
|
3495 |
}
|
insilmaril@721
|
3496 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3497 |
} else if (com=="setHideExport")
|
insilmaril@721
|
3498 |
{
|
insilmaril@750
|
3499 |
if (!selti )
|
insilmaril@721
|
3500 |
{
|
insilmaril@721
|
3501 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@735
|
3502 |
} else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
|
insilmaril@721
|
3503 |
{
|
insilmaril@721
|
3504 |
parser.setError (Aborted,"Type of selection is not a branch or floatimage");
|
insilmaril@721
|
3505 |
} else if (parser.checkParCount(1))
|
insilmaril@721
|
3506 |
{
|
insilmaril@721
|
3507 |
b=parser.parBool(ok,0);
|
insilmaril@721
|
3508 |
if (ok) setHideExport (b);
|
insilmaril@721
|
3509 |
}
|
insilmaril@721
|
3510 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3511 |
} else if (com=="setIncludeImagesHorizontally")
|
insilmaril@721
|
3512 |
{
|
insilmaril@750
|
3513 |
if (!selti )
|
insilmaril@721
|
3514 |
{
|
insilmaril@721
|
3515 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3516 |
} else if (! selbi)
|
insilmaril@721
|
3517 |
{
|
insilmaril@721
|
3518 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3519 |
} else if (parser.checkParCount(1))
|
insilmaril@721
|
3520 |
{
|
insilmaril@721
|
3521 |
b=parser.parBool(ok,0);
|
insilmaril@721
|
3522 |
if (ok) setIncludeImagesHor(b);
|
insilmaril@721
|
3523 |
}
|
insilmaril@721
|
3524 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3525 |
} else if (com=="setIncludeImagesVertically")
|
insilmaril@721
|
3526 |
{
|
insilmaril@750
|
3527 |
if (!selti )
|
insilmaril@721
|
3528 |
{
|
insilmaril@721
|
3529 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3530 |
} else if (! selbi)
|
insilmaril@721
|
3531 |
{
|
insilmaril@721
|
3532 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3533 |
} else if (parser.checkParCount(1))
|
insilmaril@721
|
3534 |
{
|
insilmaril@721
|
3535 |
b=parser.parBool(ok,0);
|
insilmaril@721
|
3536 |
if (ok) setIncludeImagesVer(b);
|
insilmaril@721
|
3537 |
}
|
insilmaril@721
|
3538 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3539 |
} else if (com=="setHideLinkUnselected")
|
insilmaril@721
|
3540 |
{
|
insilmaril@750
|
3541 |
if (!selti )
|
insilmaril@721
|
3542 |
{
|
insilmaril@721
|
3543 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@735
|
3544 |
} else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
|
insilmaril@721
|
3545 |
{
|
insilmaril@721
|
3546 |
parser.setError (Aborted,"Type of selection does not allow hiding the link");
|
insilmaril@721
|
3547 |
} else if (parser.checkParCount(1))
|
insilmaril@721
|
3548 |
{
|
insilmaril@721
|
3549 |
b=parser.parBool(ok,0);
|
insilmaril@721
|
3550 |
if (ok) setHideLinkUnselected(b);
|
insilmaril@721
|
3551 |
}
|
insilmaril@721
|
3552 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3553 |
} else if (com=="setSelectionColor")
|
insilmaril@721
|
3554 |
{
|
insilmaril@721
|
3555 |
if (parser.checkParCount(1))
|
insilmaril@721
|
3556 |
{
|
insilmaril@721
|
3557 |
QColor c=parser.parColor (ok,0);
|
insilmaril@721
|
3558 |
if (ok) setSelectionColorInt (c);
|
insilmaril@721
|
3559 |
}
|
insilmaril@721
|
3560 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3561 |
} else if (com=="setURL")
|
insilmaril@721
|
3562 |
{
|
insilmaril@750
|
3563 |
if (!selti )
|
insilmaril@721
|
3564 |
{
|
insilmaril@721
|
3565 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3566 |
} else if (! selbi )
|
insilmaril@721
|
3567 |
{
|
insilmaril@721
|
3568 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3569 |
} else if (parser.checkParCount(1))
|
insilmaril@721
|
3570 |
{
|
insilmaril@721
|
3571 |
s=parser.parString (ok,0);
|
insilmaril@721
|
3572 |
if (ok) setURL(s);
|
insilmaril@721
|
3573 |
}
|
insilmaril@721
|
3574 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3575 |
} else if (com=="setVymLink")
|
insilmaril@721
|
3576 |
{
|
insilmaril@750
|
3577 |
if (!selti )
|
insilmaril@721
|
3578 |
{
|
insilmaril@721
|
3579 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3580 |
} else if (! selbi )
|
insilmaril@721
|
3581 |
{
|
insilmaril@721
|
3582 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3583 |
} else if (parser.checkParCount(1))
|
insilmaril@721
|
3584 |
{
|
insilmaril@721
|
3585 |
s=parser.parString (ok,0);
|
insilmaril@721
|
3586 |
if (ok) setVymLink(s);
|
insilmaril@721
|
3587 |
}
|
insilmaril@721
|
3588 |
}
|
insilmaril@721
|
3589 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@753
|
3590 |
else /* FIXME-2 if (com=="setFlag")
|
insilmaril@721
|
3591 |
{
|
insilmaril@750
|
3592 |
if (!selti )
|
insilmaril@721
|
3593 |
{
|
insilmaril@721
|
3594 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3595 |
} else if (! selbi )
|
insilmaril@721
|
3596 |
{
|
insilmaril@721
|
3597 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3598 |
} else if (parser.checkParCount(1))
|
insilmaril@721
|
3599 |
{
|
insilmaril@721
|
3600 |
s=parser.parString(ok,0);
|
insilmaril@721
|
3601 |
if (ok)
|
insilmaril@721
|
3602 |
{
|
insilmaril@721
|
3603 |
selb->activateStandardFlag(s);
|
insilmaril@721
|
3604 |
selb->updateFlagsToolbar();
|
insilmaril@721
|
3605 |
}
|
insilmaril@721
|
3606 |
}
|
insilmaril@721
|
3607 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@753
|
3608 |
} else */ /* FIXME-2 if (com=="setFrameType")
|
insilmaril@721
|
3609 |
{
|
insilmaril@750
|
3610 |
if (!selti )
|
insilmaril@721
|
3611 |
{
|
insilmaril@721
|
3612 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@721
|
3613 |
} else if (! selb )
|
insilmaril@721
|
3614 |
{
|
insilmaril@721
|
3615 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3616 |
} else if (parser.checkParCount(1))
|
insilmaril@721
|
3617 |
{
|
insilmaril@721
|
3618 |
s=parser.parString(ok,0);
|
insilmaril@721
|
3619 |
if (ok)
|
insilmaril@721
|
3620 |
setFrameType (s);
|
insilmaril@721
|
3621 |
}
|
insilmaril@721
|
3622 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@753
|
3623 |
} else*/ if (com=="sortChildren")
|
insilmaril@721
|
3624 |
{
|
insilmaril@750
|
3625 |
if (!selti )
|
insilmaril@721
|
3626 |
{
|
insilmaril@721
|
3627 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3628 |
} else if (! selbi )
|
insilmaril@721
|
3629 |
{
|
insilmaril@721
|
3630 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3631 |
} else if (parser.checkParCount(0))
|
insilmaril@721
|
3632 |
{
|
insilmaril@721
|
3633 |
sortChildren();
|
insilmaril@721
|
3634 |
}
|
insilmaril@721
|
3635 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@753
|
3636 |
} else /* FIXME-2 if (com=="toggleFlag")
|
insilmaril@721
|
3637 |
{
|
insilmaril@750
|
3638 |
if (!selti )
|
insilmaril@721
|
3639 |
{
|
insilmaril@721
|
3640 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3641 |
} else if (! selbi )
|
insilmaril@721
|
3642 |
{
|
insilmaril@721
|
3643 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3644 |
} else if (parser.checkParCount(1))
|
insilmaril@721
|
3645 |
{
|
insilmaril@721
|
3646 |
s=parser.parString(ok,0);
|
insilmaril@721
|
3647 |
if (ok)
|
insilmaril@721
|
3648 |
{
|
insilmaril@753
|
3649 |
selbi->toggleStandardFlag(s);
|
insilmaril@721
|
3650 |
selb->updateFlagsToolbar();
|
insilmaril@721
|
3651 |
}
|
insilmaril@721
|
3652 |
}
|
insilmaril@721
|
3653 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@753
|
3654 |
} else */ if (com=="unscroll")
|
insilmaril@721
|
3655 |
{
|
insilmaril@750
|
3656 |
if (!selti)
|
insilmaril@721
|
3657 |
{
|
insilmaril@721
|
3658 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3659 |
} else if (! selbi )
|
insilmaril@721
|
3660 |
{
|
insilmaril@721
|
3661 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3662 |
} else if (parser.checkParCount(0))
|
insilmaril@721
|
3663 |
{
|
insilmaril@750
|
3664 |
if (!unscrollBranch (selbi))
|
insilmaril@721
|
3665 |
parser.setError (Aborted,"Could not unscroll branch");
|
insilmaril@721
|
3666 |
}
|
insilmaril@721
|
3667 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@721
|
3668 |
} else if (com=="unscrollChildren")
|
insilmaril@721
|
3669 |
{
|
insilmaril@750
|
3670 |
if (!selti)
|
insilmaril@721
|
3671 |
{
|
insilmaril@721
|
3672 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3673 |
} else if (! selbi )
|
insilmaril@721
|
3674 |
{
|
insilmaril@721
|
3675 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3676 |
} else if (parser.checkParCount(0))
|
insilmaril@721
|
3677 |
{
|
insilmaril@721
|
3678 |
unscrollChildren ();
|
insilmaril@721
|
3679 |
}
|
insilmaril@721
|
3680 |
/////////////////////////////////////////////////////////////////////
|
insilmaril@753
|
3681 |
} else /* FIXME-2 if (com=="unsetFlag")
|
insilmaril@721
|
3682 |
{
|
insilmaril@721
|
3683 |
if (selection.isEmpty() )
|
insilmaril@721
|
3684 |
{
|
insilmaril@721
|
3685 |
parser.setError (Aborted,"Nothing selected");
|
insilmaril@753
|
3686 |
} else if (! selbi )
|
insilmaril@721
|
3687 |
{
|
insilmaril@721
|
3688 |
parser.setError (Aborted,"Type of selection is not a branch");
|
insilmaril@721
|
3689 |
} else if (parser.checkParCount(1))
|
insilmaril@721
|
3690 |
{
|
insilmaril@721
|
3691 |
s=parser.parString(ok,0);
|
insilmaril@721
|
3692 |
if (ok)
|
insilmaril@721
|
3693 |
{
|
insilmaril@721
|
3694 |
selb->deactivateStandardFlag(s);
|
insilmaril@721
|
3695 |
selb->updateFlagsToolbar();
|
insilmaril@721
|
3696 |
}
|
insilmaril@721
|
3697 |
}
|
insilmaril@753
|
3698 |
} else */
|
insilmaril@721
|
3699 |
parser.setError (Aborted,"Unknown command");
|
insilmaril@721
|
3700 |
|
insilmaril@721
|
3701 |
// Any errors?
|
insilmaril@721
|
3702 |
if (parser.errorLevel()==NoError)
|
insilmaril@721
|
3703 |
{
|
insilmaril@746
|
3704 |
// setChanged(); FIXME-2 should not be called e.g. for export?!
|
insilmaril@721
|
3705 |
reposition();
|
insilmaril@721
|
3706 |
}
|
insilmaril@721
|
3707 |
else
|
insilmaril@721
|
3708 |
{
|
insilmaril@721
|
3709 |
// TODO Error handling
|
insilmaril@721
|
3710 |
qWarning("VymModel::parseAtom: Error!");
|
insilmaril@721
|
3711 |
qWarning(parser.errorMessage());
|
insilmaril@721
|
3712 |
}
|
insilmaril@721
|
3713 |
}
|
insilmaril@721
|
3714 |
|
insilmaril@721
|
3715 |
void VymModel::runScript (QString script)
|
insilmaril@721
|
3716 |
{
|
insilmaril@721
|
3717 |
parser.setScript (script);
|
insilmaril@721
|
3718 |
parser.runScript();
|
insilmaril@721
|
3719 |
while (parser.next() )
|
insilmaril@721
|
3720 |
parseAtom(parser.getAtom());
|
insilmaril@721
|
3721 |
}
|
insilmaril@721
|
3722 |
|
insilmaril@721
|
3723 |
void VymModel::setExportMode (bool b)
|
insilmaril@721
|
3724 |
{
|
insilmaril@721
|
3725 |
// should be called before and after exports
|
insilmaril@721
|
3726 |
// depending on the settings
|
insilmaril@721
|
3727 |
if (b && settings.value("/export/useHideExport","true")=="true")
|
insilmaril@753
|
3728 |
setHideTmpMode (TreeItem::HideExport);
|
insilmaril@721
|
3729 |
else
|
insilmaril@753
|
3730 |
setHideTmpMode (TreeItem::HideNone);
|
insilmaril@721
|
3731 |
}
|
insilmaril@721
|
3732 |
|
insilmaril@721
|
3733 |
void VymModel::exportImage(QString fname, bool askName, QString format)
|
insilmaril@721
|
3734 |
{
|
insilmaril@721
|
3735 |
if (fname=="")
|
insilmaril@721
|
3736 |
{
|
insilmaril@721
|
3737 |
fname=getMapName()+".png";
|
insilmaril@721
|
3738 |
format="PNG";
|
insilmaril@721
|
3739 |
}
|
insilmaril@721
|
3740 |
|
insilmaril@721
|
3741 |
if (askName)
|
insilmaril@721
|
3742 |
{
|
insilmaril@721
|
3743 |
QStringList fl;
|
insilmaril@721
|
3744 |
QFileDialog *fd=new QFileDialog (NULL);
|
insilmaril@721
|
3745 |
fd->setCaption (tr("Export map as image"));
|
insilmaril@721
|
3746 |
fd->setDirectory (lastImageDir);
|
insilmaril@721
|
3747 |
fd->setFileMode(QFileDialog::AnyFile);
|
insilmaril@721
|
3748 |
fd->setFilters (imageIO.getFilters() );
|
insilmaril@721
|
3749 |
if (fd->exec())
|
insilmaril@721
|
3750 |
{
|
insilmaril@721
|
3751 |
fl=fd->selectedFiles();
|
insilmaril@721
|
3752 |
fname=fl.first();
|
insilmaril@721
|
3753 |
format=imageIO.getType(fd->selectedFilter());
|
insilmaril@721
|
3754 |
}
|
insilmaril@721
|
3755 |
}
|
insilmaril@721
|
3756 |
|
insilmaril@721
|
3757 |
setExportMode (true);
|
insilmaril@721
|
3758 |
QPixmap pix (getPixmap());
|
insilmaril@721
|
3759 |
pix.save(fname, format);
|
insilmaril@721
|
3760 |
setExportMode (false);
|
insilmaril@721
|
3761 |
}
|
insilmaril@721
|
3762 |
|
insilmaril@721
|
3763 |
|
insilmaril@721
|
3764 |
void VymModel::exportXML(QString dir, bool askForName)
|
insilmaril@721
|
3765 |
{
|
insilmaril@721
|
3766 |
if (askForName)
|
insilmaril@721
|
3767 |
{
|
insilmaril@721
|
3768 |
dir=browseDirectory(NULL,tr("Export XML to directory"));
|
insilmaril@721
|
3769 |
if (dir =="" && !reallyWriteDirectory(dir) )
|
insilmaril@721
|
3770 |
return;
|
insilmaril@721
|
3771 |
}
|
insilmaril@721
|
3772 |
|
insilmaril@721
|
3773 |
// Hide stuff during export, if settings want this
|
insilmaril@721
|
3774 |
setExportMode (true);
|
insilmaril@721
|
3775 |
|
insilmaril@721
|
3776 |
// Create subdirectories
|
insilmaril@721
|
3777 |
makeSubDirs (dir);
|
insilmaril@721
|
3778 |
|
insilmaril@721
|
3779 |
// write to directory
|
insilmaril@721
|
3780 |
QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL);
|
insilmaril@721
|
3781 |
QFile file;
|
insilmaril@721
|
3782 |
|
insilmaril@721
|
3783 |
file.setName ( dir + "/"+mapName+".xml");
|
insilmaril@721
|
3784 |
if ( !file.open( QIODevice::WriteOnly ) )
|
insilmaril@721
|
3785 |
{
|
insilmaril@721
|
3786 |
// This should neverever happen
|
insilmaril@721
|
3787 |
QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
|
insilmaril@721
|
3788 |
return;
|
insilmaril@721
|
3789 |
}
|
insilmaril@721
|
3790 |
|
insilmaril@721
|
3791 |
// Write it finally, and write in UTF8, no matter what
|
insilmaril@721
|
3792 |
QTextStream ts( &file );
|
insilmaril@721
|
3793 |
ts.setEncoding (QTextStream::UnicodeUTF8);
|
insilmaril@721
|
3794 |
ts << saveFile;
|
insilmaril@721
|
3795 |
file.close();
|
insilmaril@721
|
3796 |
|
insilmaril@721
|
3797 |
// Now write image, too
|
insilmaril@721
|
3798 |
exportImage (dir+"/images/"+mapName+".png",false,"PNG");
|
insilmaril@721
|
3799 |
|
insilmaril@721
|
3800 |
setExportMode (false);
|
insilmaril@721
|
3801 |
}
|
insilmaril@721
|
3802 |
|
insilmaril@721
|
3803 |
void VymModel::exportASCII(QString fname,bool askName)
|
insilmaril@721
|
3804 |
{
|
insilmaril@721
|
3805 |
ExportASCII ex;
|
insilmaril@721
|
3806 |
ex.setModel (this);
|
insilmaril@721
|
3807 |
if (fname=="")
|
insilmaril@721
|
3808 |
ex.setFile (mapName+".txt");
|
insilmaril@721
|
3809 |
else
|
insilmaril@721
|
3810 |
ex.setFile (fname);
|
insilmaril@721
|
3811 |
|
insilmaril@721
|
3812 |
if (askName)
|
insilmaril@721
|
3813 |
{
|
insilmaril@721
|
3814 |
//ex.addFilter ("TXT (*.txt)");
|
insilmaril@721
|
3815 |
ex.setDir(lastImageDir);
|
insilmaril@721
|
3816 |
//ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
|
insilmaril@721
|
3817 |
ex.execDialog() ;
|
insilmaril@721
|
3818 |
}
|
insilmaril@721
|
3819 |
if (!ex.canceled())
|
insilmaril@721
|
3820 |
{
|
insilmaril@721
|
3821 |
setExportMode(true);
|
insilmaril@721
|
3822 |
ex.doExport();
|
insilmaril@721
|
3823 |
setExportMode(false);
|
insilmaril@721
|
3824 |
}
|
insilmaril@721
|
3825 |
}
|
insilmaril@721
|
3826 |
|
insilmaril@721
|
3827 |
void VymModel::exportXHTML (const QString &dir, bool askForName)
|
insilmaril@721
|
3828 |
{
|
insilmaril@721
|
3829 |
ExportXHTMLDialog dia(NULL);
|
insilmaril@721
|
3830 |
dia.setFilePath (filePath );
|
insilmaril@721
|
3831 |
dia.setMapName (mapName );
|
insilmaril@721
|
3832 |
dia.readSettings();
|
insilmaril@721
|
3833 |
if (dir!="") dia.setDir (dir);
|
insilmaril@721
|
3834 |
|
insilmaril@721
|
3835 |
bool ok=true;
|
insilmaril@721
|
3836 |
|
insilmaril@721
|
3837 |
if (askForName)
|
insilmaril@721
|
3838 |
{
|
insilmaril@721
|
3839 |
if (dia.exec()!=QDialog::Accepted)
|
insilmaril@721
|
3840 |
ok=false;
|
insilmaril@721
|
3841 |
else
|
insilmaril@721
|
3842 |
{
|
insilmaril@721
|
3843 |
QDir d (dia.getDir());
|
insilmaril@721
|
3844 |
// Check, if warnings should be used before overwriting
|
insilmaril@721
|
3845 |
// the output directory
|
insilmaril@721
|
3846 |
if (d.exists() && d.count()>0)
|
insilmaril@721
|
3847 |
{
|
insilmaril@721
|
3848 |
WarningDialog warn;
|
insilmaril@721
|
3849 |
warn.showCancelButton (true);
|
insilmaril@721
|
3850 |
warn.setText(QString(
|
insilmaril@721
|
3851 |
"The directory %1 is not empty.\n"
|
insilmaril@721
|
3852 |
"Do you risk to overwrite some of its contents?").arg(d.path() ));
|
insilmaril@721
|
3853 |
warn.setCaption("Warning: Directory not empty");
|
insilmaril@721
|
3854 |
warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
|
insilmaril@721
|
3855 |
|
insilmaril@721
|
3856 |
if (warn.exec()!=QDialog::Accepted) ok=false;
|
insilmaril@721
|
3857 |
}
|
insilmaril@721
|
3858 |
}
|
insilmaril@721
|
3859 |
}
|
insilmaril@721
|
3860 |
|
insilmaril@721
|
3861 |
if (ok)
|
insilmaril@721
|
3862 |
{
|
insilmaril@721
|
3863 |
exportXML (dia.getDir(),false );
|
insilmaril@721
|
3864 |
dia.doExport(mapName );
|
insilmaril@721
|
3865 |
//if (dia.hasChanged()) setChanged();
|
insilmaril@721
|
3866 |
}
|
insilmaril@721
|
3867 |
}
|
insilmaril@721
|
3868 |
|
insilmaril@721
|
3869 |
void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
|
insilmaril@721
|
3870 |
{
|
insilmaril@721
|
3871 |
ExportOO ex;
|
insilmaril@721
|
3872 |
ex.setFile (fn);
|
insilmaril@721
|
3873 |
ex.setModel (this);
|
insilmaril@721
|
3874 |
if (ex.setConfigFile(cf))
|
insilmaril@721
|
3875 |
{
|
insilmaril@721
|
3876 |
setExportMode (true);
|
insilmaril@721
|
3877 |
ex.exportPresentation();
|
insilmaril@721
|
3878 |
setExportMode (false);
|
insilmaril@721
|
3879 |
}
|
insilmaril@721
|
3880 |
}
|
insilmaril@721
|
3881 |
|
insilmaril@721
|
3882 |
|
insilmaril@721
|
3883 |
|
insilmaril@650
|
3884 |
|
insilmaril@652
|
3885 |
//////////////////////////////////////////////
|
insilmaril@652
|
3886 |
// View related
|
insilmaril@652
|
3887 |
//////////////////////////////////////////////
|
insilmaril@652
|
3888 |
|
insilmaril@723
|
3889 |
void VymModel::registerEditor(QWidget *me)
|
insilmaril@721
|
3890 |
{
|
insilmaril@723
|
3891 |
mapEditor=(MapEditor*)me;
|
insilmaril@721
|
3892 |
}
|
insilmaril@721
|
3893 |
|
insilmaril@721
|
3894 |
void VymModel::unregisterEditor(QWidget *)
|
insilmaril@721
|
3895 |
{
|
insilmaril@723
|
3896 |
mapEditor=NULL;
|
insilmaril@723
|
3897 |
}
|
insilmaril@723
|
3898 |
|
insilmaril@723
|
3899 |
void VymModel::setContextPos(QPointF p)
|
insilmaril@723
|
3900 |
{
|
insilmaril@723
|
3901 |
contextPos=p;
|
insilmaril@723
|
3902 |
}
|
insilmaril@723
|
3903 |
|
insilmaril@723
|
3904 |
void VymModel::unsetContextPos()
|
insilmaril@723
|
3905 |
{
|
insilmaril@723
|
3906 |
contextPos=QPointF();
|
insilmaril@721
|
3907 |
}
|
insilmaril@721
|
3908 |
|
insilmaril@721
|
3909 |
void VymModel::updateNoteFlag()
|
insilmaril@721
|
3910 |
{
|
insilmaril@721
|
3911 |
setChanged();
|
insilmaril@746
|
3912 |
cout << "VM::updateNoteFlag()\n";
|
insilmaril@746
|
3913 |
/* FIXME-1 modify note flag
|
insilmaril@735
|
3914 |
BranchObj *bo=getSelectedBranch();
|
insilmaril@721
|
3915 |
if (bo)
|
insilmaril@721
|
3916 |
{
|
insilmaril@721
|
3917 |
bo->updateNoteFlag();
|
insilmaril@721
|
3918 |
mainWindow->updateActions();
|
insilmaril@721
|
3919 |
}
|
insilmaril@746
|
3920 |
*/
|
insilmaril@721
|
3921 |
}
|
insilmaril@721
|
3922 |
|
insilmaril@754
|
3923 |
void VymModel::updateRelPositions() //FIXME-2 VM should have no need to updateRelPos
|
insilmaril@754
|
3924 |
{
|
insilmaril@760
|
3925 |
//cout << "VM::updateRelPos...\n";
|
insilmaril@754
|
3926 |
for (int i=0; i<rootItem->branchCount(); i++)
|
insilmaril@754
|
3927 |
((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
|
insilmaril@652
|
3928 |
}
|
insilmaril@652
|
3929 |
|
insilmaril@761
|
3930 |
void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views???
|
insilmaril@761
|
3931 |
{
|
insilmaril@761
|
3932 |
//cout << "VM::reposition blocked="<<blockReposition<<endl;
|
insilmaril@761
|
3933 |
if (blockReposition) return;
|
insilmaril@761
|
3934 |
|
insilmaril@754
|
3935 |
for (int i=0;i<rootItem->branchCount(); i++)
|
insilmaril@754
|
3936 |
rootItem->getBranchObjNum(i)->reposition(); // for positioning heading
|
insilmaril@652
|
3937 |
}
|
insilmaril@652
|
3938 |
|
insilmaril@755
|
3939 |
QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4
|
insilmaril@755
|
3940 |
{
|
insilmaril@755
|
3941 |
/*
|
insilmaril@665
|
3942 |
// Creating (arbitrary) shapes
|
insilmaril@665
|
3943 |
|
insilmaril@665
|
3944 |
QPolygonF p;
|
insilmaril@665
|
3945 |
QRectF rb=bo->getBBox();
|
insilmaril@665
|
3946 |
if (bo->getDepth()==0)
|
insilmaril@665
|
3947 |
{
|
insilmaril@665
|
3948 |
// Just take BBox of this mapCenter
|
insilmaril@665
|
3949 |
p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
|
insilmaril@665
|
3950 |
return p;
|
insilmaril@665
|
3951 |
}
|
insilmaril@665
|
3952 |
|
insilmaril@665
|
3953 |
// Take union of BBox and TotalBBox
|
insilmaril@665
|
3954 |
|
insilmaril@665
|
3955 |
QRectF ra=bo->getTotalBBox();
|
insilmaril@665
|
3956 |
if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
|
insilmaril@665
|
3957 |
p <<ra.bottomLeft()
|
insilmaril@665
|
3958 |
<<ra.topLeft()
|
insilmaril@665
|
3959 |
<<QPointF (rb.topLeft().x(), ra.topLeft().y() )
|
insilmaril@665
|
3960 |
<<rb.topRight()
|
insilmaril@665
|
3961 |
<<rb.bottomRight()
|
insilmaril@665
|
3962 |
<<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
|
insilmaril@665
|
3963 |
else
|
insilmaril@665
|
3964 |
p <<ra.bottomRight()
|
insilmaril@665
|
3965 |
<<ra.topRight()
|
insilmaril@665
|
3966 |
<<QPointF (rb.topRight().x(), ra.topRight().y() )
|
insilmaril@665
|
3967 |
<<rb.topLeft()
|
insilmaril@665
|
3968 |
<<rb.bottomLeft()
|
insilmaril@665
|
3969 |
<<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
|
insilmaril@665
|
3970 |
return p;
|
insilmaril@755
|
3971 |
*/
|
insilmaril@665
|
3972 |
}
|
insilmaril@665
|
3973 |
|
insilmaril@753
|
3974 |
void VymModel::moveAway(LinkableMapObj *lmo) //FIXME-5
|
insilmaril@665
|
3975 |
{
|
insilmaril@665
|
3976 |
// Autolayout:
|
insilmaril@665
|
3977 |
//
|
insilmaril@665
|
3978 |
// Move all branches and MapCenters away from lmo
|
insilmaril@665
|
3979 |
// to avoid collisions
|
insilmaril@665
|
3980 |
|
insilmaril@754
|
3981 |
/*
|
insilmaril@665
|
3982 |
QPolygonF pA;
|
insilmaril@665
|
3983 |
QPolygonF pB;
|
insilmaril@665
|
3984 |
|
insilmaril@665
|
3985 |
BranchObj *boA=(BranchObj*)lmo;
|
insilmaril@665
|
3986 |
BranchObj *boB;
|
insilmaril@754
|
3987 |
for (int i=0; i<rootItem->branchCount(); i++)
|
insilmaril@665
|
3988 |
{
|
insilmaril@754
|
3989 |
boB=rootItem->getBranchNum(i);
|
insilmaril@665
|
3990 |
pA=shape (boA);
|
insilmaril@665
|
3991 |
pB=shape (boB);
|
insilmaril@665
|
3992 |
PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
|
insilmaril@665
|
3993 |
cout <<"------->"
|
insilmaril@665
|
3994 |
<<"="<<r.intersect
|
insilmaril@665
|
3995 |
<<" ("<<qPrintable(boA->getHeading() )<<")"
|
insilmaril@665
|
3996 |
<<" with ("<< qPrintable (boB->getHeading() )
|
insilmaril@665
|
3997 |
<<") willIntersect"
|
insilmaril@665
|
3998 |
<<r.willIntersect
|
insilmaril@665
|
3999 |
<<" minT="<<r.minTranslation<<endl<<endl;
|
insilmaril@754
|
4000 |
}
|
insilmaril@753
|
4001 |
*/
|
insilmaril@665
|
4002 |
}
|
insilmaril@652
|
4003 |
|
insilmaril@721
|
4004 |
QPixmap VymModel::getPixmap()
|
insilmaril@721
|
4005 |
{
|
insilmaril@721
|
4006 |
QRectF mapRect=getTotalBBox();
|
insilmaril@721
|
4007 |
QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
|
insilmaril@721
|
4008 |
QPainter pp (&pix);
|
insilmaril@721
|
4009 |
|
insilmaril@721
|
4010 |
pp.setRenderHints(mapEditor->renderHints());
|
insilmaril@721
|
4011 |
|
insilmaril@721
|
4012 |
// Don't print the visualisation of selection
|
insilmaril@721
|
4013 |
selection.unselect();
|
insilmaril@721
|
4014 |
|
insilmaril@721
|
4015 |
mapScene->render ( &pp,
|
insilmaril@721
|
4016 |
QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
|
insilmaril@721
|
4017 |
QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
|
insilmaril@721
|
4018 |
|
insilmaril@721
|
4019 |
// Restore selection
|
insilmaril@721
|
4020 |
selection.reselect();
|
insilmaril@721
|
4021 |
|
insilmaril@721
|
4022 |
return pix;
|
insilmaril@721
|
4023 |
}
|
insilmaril@721
|
4024 |
|
insilmaril@721
|
4025 |
|
insilmaril@721
|
4026 |
void VymModel::setMapLinkStyle (const QString & s)
|
insilmaril@721
|
4027 |
{
|
insilmaril@721
|
4028 |
QString snow;
|
insilmaril@727
|
4029 |
switch (linkstyle)
|
insilmaril@727
|
4030 |
{
|
insilmaril@727
|
4031 |
case LinkableMapObj::Line :
|
insilmaril@727
|
4032 |
snow="StyleLine";
|
insilmaril@727
|
4033 |
break;
|
insilmaril@727
|
4034 |
case LinkableMapObj::Parabel:
|
insilmaril@727
|
4035 |
snow="StyleParabel";
|
insilmaril@727
|
4036 |
break;
|
insilmaril@727
|
4037 |
case LinkableMapObj::PolyLine:
|
insilmaril@727
|
4038 |
snow="StylePolyLine";
|
insilmaril@727
|
4039 |
break;
|
insilmaril@727
|
4040 |
case LinkableMapObj::PolyParabel:
|
insilmaril@727
|
4041 |
snow="StylePolyParabel";
|
insilmaril@727
|
4042 |
break;
|
insilmaril@727
|
4043 |
default:
|
insilmaril@727
|
4044 |
snow="UndefinedStyle";
|
insilmaril@727
|
4045 |
break;
|
insilmaril@727
|
4046 |
}
|
insilmaril@721
|
4047 |
|
insilmaril@721
|
4048 |
saveState (
|
insilmaril@721
|
4049 |
QString("setMapLinkStyle (\"%1\")").arg(s),
|
insilmaril@721
|
4050 |
QString("setMapLinkStyle (\"%1\")").arg(snow),
|
insilmaril@721
|
4051 |
QString("Set map link style (\"%1\")").arg(s)
|
insilmaril@721
|
4052 |
);
|
insilmaril@721
|
4053 |
|
insilmaril@721
|
4054 |
if (s=="StyleLine")
|
insilmaril@721
|
4055 |
linkstyle=LinkableMapObj::Line;
|
insilmaril@721
|
4056 |
else if (s=="StyleParabel")
|
insilmaril@721
|
4057 |
linkstyle=LinkableMapObj::Parabel;
|
insilmaril@721
|
4058 |
else if (s=="StylePolyLine")
|
insilmaril@721
|
4059 |
linkstyle=LinkableMapObj::PolyLine;
|
insilmaril@727
|
4060 |
else if (s=="StylePolyParabel")
|
insilmaril@721
|
4061 |
linkstyle=LinkableMapObj::PolyParabel;
|
insilmaril@727
|
4062 |
else
|
insilmaril@727
|
4063 |
linkstyle=LinkableMapObj::UndefinedStyle;
|
insilmaril@721
|
4064 |
|
insilmaril@750
|
4065 |
BranchItem *cur=NULL;
|
insilmaril@750
|
4066 |
BranchItem *prev=NULL;
|
insilmaril@741
|
4067 |
int d=0;
|
insilmaril@721
|
4068 |
BranchObj *bo;
|
insilmaril@741
|
4069 |
next (cur,prev,d);
|
insilmaril@741
|
4070 |
while (cur)
|
insilmaril@721
|
4071 |
{
|
insilmaril@741
|
4072 |
bo=(BranchObj*)(cur->getLMO() );
|
insilmaril@721
|
4073 |
bo->setLinkStyle(bo->getDefLinkStyle());
|
insilmaril@741
|
4074 |
cur=next(cur,prev,d);
|
insilmaril@721
|
4075 |
}
|
insilmaril@721
|
4076 |
reposition();
|
insilmaril@721
|
4077 |
}
|
insilmaril@721
|
4078 |
|
insilmaril@721
|
4079 |
LinkableMapObj::Style VymModel::getMapLinkStyle ()
|
insilmaril@721
|
4080 |
{
|
insilmaril@721
|
4081 |
return linkstyle;
|
insilmaril@721
|
4082 |
}
|
insilmaril@721
|
4083 |
|
insilmaril@721
|
4084 |
void VymModel::setMapDefLinkColor(QColor col)
|
insilmaril@721
|
4085 |
{
|
insilmaril@721
|
4086 |
if ( !col.isValid() ) return;
|
insilmaril@721
|
4087 |
saveState (
|
insilmaril@721
|
4088 |
QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
|
insilmaril@721
|
4089 |
QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
|
insilmaril@721
|
4090 |
QString("Set map link color to %1").arg(col.name())
|
insilmaril@721
|
4091 |
);
|
insilmaril@721
|
4092 |
|
insilmaril@721
|
4093 |
defLinkColor=col;
|
insilmaril@750
|
4094 |
BranchItem *cur=NULL;
|
insilmaril@750
|
4095 |
BranchItem *prev=NULL;
|
insilmaril@741
|
4096 |
int d=0;
|
insilmaril@721
|
4097 |
BranchObj *bo;
|
insilmaril@741
|
4098 |
cur=next(cur,prev,d);
|
insilmaril@741
|
4099 |
while (cur)
|
insilmaril@721
|
4100 |
{
|
insilmaril@741
|
4101 |
bo=(BranchObj*)(cur->getLMO() );
|
insilmaril@721
|
4102 |
bo->setLinkColor();
|
insilmaril@741
|
4103 |
next(cur,prev,d);
|
insilmaril@721
|
4104 |
}
|
insilmaril@721
|
4105 |
updateActions();
|
insilmaril@721
|
4106 |
}
|
insilmaril@721
|
4107 |
|
insilmaril@721
|
4108 |
void VymModel::setMapLinkColorHintInt()
|
insilmaril@721
|
4109 |
{
|
insilmaril@721
|
4110 |
// called from setMapLinkColorHint(lch) or at end of parse
|
insilmaril@750
|
4111 |
BranchItem *cur=NULL;
|
insilmaril@750
|
4112 |
BranchItem *prev=NULL;
|
insilmaril@741
|
4113 |
int d=0;
|
insilmaril@721
|
4114 |
BranchObj *bo;
|
insilmaril@741
|
4115 |
cur=next(cur,prev,d);
|
insilmaril@741
|
4116 |
while (cur)
|
insilmaril@721
|
4117 |
{
|
insilmaril@741
|
4118 |
bo=(BranchObj*)(cur->getLMO() );
|
insilmaril@721
|
4119 |
bo->setLinkColor();
|
insilmaril@741
|
4120 |
cur=next(cur,prev,d);
|
insilmaril@721
|
4121 |
}
|
insilmaril@721
|
4122 |
}
|
insilmaril@721
|
4123 |
|
insilmaril@721
|
4124 |
void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
|
insilmaril@721
|
4125 |
{
|
insilmaril@721
|
4126 |
linkcolorhint=lch;
|
insilmaril@721
|
4127 |
setMapLinkColorHintInt();
|
insilmaril@721
|
4128 |
}
|
insilmaril@721
|
4129 |
|
insilmaril@721
|
4130 |
void VymModel::toggleMapLinkColorHint()
|
insilmaril@721
|
4131 |
{
|
insilmaril@721
|
4132 |
if (linkcolorhint==LinkableMapObj::HeadingColor)
|
insilmaril@721
|
4133 |
linkcolorhint=LinkableMapObj::DefaultColor;
|
insilmaril@721
|
4134 |
else
|
insilmaril@721
|
4135 |
linkcolorhint=LinkableMapObj::HeadingColor;
|
insilmaril@750
|
4136 |
BranchItem *cur=NULL;
|
insilmaril@750
|
4137 |
BranchItem *prev=NULL;
|
insilmaril@741
|
4138 |
int d=0;
|
insilmaril@721
|
4139 |
BranchObj *bo;
|
insilmaril@741
|
4140 |
cur=next(cur,prev,d);
|
insilmaril@741
|
4141 |
while (cur)
|
insilmaril@721
|
4142 |
{
|
insilmaril@741
|
4143 |
bo=(BranchObj*)(cur->getLMO() );
|
insilmaril@721
|
4144 |
bo->setLinkColor();
|
insilmaril@741
|
4145 |
next(cur,prev,d);
|
insilmaril@721
|
4146 |
}
|
insilmaril@721
|
4147 |
}
|
insilmaril@721
|
4148 |
|
insilmaril@746
|
4149 |
void VymModel::selectMapBackgroundImage () // FIXME-2 move to ME
|
insilmaril@721
|
4150 |
{
|
insilmaril@721
|
4151 |
Q3FileDialog *fd=new Q3FileDialog( NULL);
|
insilmaril@721
|
4152 |
fd->setMode (Q3FileDialog::ExistingFile);
|
insilmaril@721
|
4153 |
fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
|
insilmaril@721
|
4154 |
ImagePreview *p =new ImagePreview (fd);
|
insilmaril@721
|
4155 |
fd->setContentsPreviewEnabled( TRUE );
|
insilmaril@721
|
4156 |
fd->setContentsPreview( p, p );
|
insilmaril@721
|
4157 |
fd->setPreviewMode( Q3FileDialog::Contents );
|
insilmaril@721
|
4158 |
fd->setCaption(vymName+" - " +tr("Load background image"));
|
insilmaril@721
|
4159 |
fd->setDir (lastImageDir);
|
insilmaril@721
|
4160 |
fd->show();
|
insilmaril@721
|
4161 |
|
insilmaril@721
|
4162 |
if ( fd->exec() == QDialog::Accepted )
|
insilmaril@721
|
4163 |
{
|
insilmaril@721
|
4164 |
// TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
|
insilmaril@721
|
4165 |
lastImageDir=QDir (fd->dirPath());
|
insilmaril@721
|
4166 |
setMapBackgroundImage (fd->selectedFile());
|
insilmaril@721
|
4167 |
}
|
insilmaril@721
|
4168 |
}
|
insilmaril@721
|
4169 |
|
insilmaril@746
|
4170 |
void VymModel::setMapBackgroundImage (const QString &fn) //FIXME-2 missing savestate
|
insilmaril@721
|
4171 |
{
|
insilmaril@721
|
4172 |
QColor oldcol=mapScene->backgroundBrush().color();
|
insilmaril@721
|
4173 |
/*
|
insilmaril@721
|
4174 |
saveState(
|
insilmaril@721
|
4175 |
selection,
|
insilmaril@721
|
4176 |
QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
|
insilmaril@721
|
4177 |
selection,
|
insilmaril@721
|
4178 |
QString ("setMapBackgroundImage (%1)").arg(col.name()),
|
insilmaril@721
|
4179 |
QString("Set background color of map to %1").arg(col.name()));
|
insilmaril@721
|
4180 |
*/
|
insilmaril@721
|
4181 |
QBrush brush;
|
insilmaril@721
|
4182 |
brush.setTextureImage (QPixmap (fn));
|
insilmaril@721
|
4183 |
mapScene->setBackgroundBrush(brush);
|
insilmaril@721
|
4184 |
}
|
insilmaril@721
|
4185 |
|
insilmaril@753
|
4186 |
void VymModel::selectMapBackgroundColor() // FIXME-3 move to ME
|
insilmaril@721
|
4187 |
{
|
insilmaril@721
|
4188 |
QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
|
insilmaril@721
|
4189 |
if ( !col.isValid() ) return;
|
insilmaril@721
|
4190 |
setMapBackgroundColor( col );
|
insilmaril@721
|
4191 |
}
|
insilmaril@721
|
4192 |
|
insilmaril@721
|
4193 |
|
insilmaril@753
|
4194 |
void VymModel::setMapBackgroundColor(QColor col) // FIXME-3 move to ME
|
insilmaril@721
|
4195 |
{
|
insilmaril@721
|
4196 |
QColor oldcol=mapScene->backgroundBrush().color();
|
insilmaril@721
|
4197 |
saveState(
|
insilmaril@721
|
4198 |
QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
|
insilmaril@721
|
4199 |
QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
|
insilmaril@721
|
4200 |
QString("Set background color of map to %1").arg(col.name()));
|
insilmaril@721
|
4201 |
mapScene->setBackgroundBrush(col);
|
insilmaril@721
|
4202 |
}
|
insilmaril@721
|
4203 |
|
insilmaril@753
|
4204 |
QColor VymModel::getMapBackgroundColor() // FIXME-3 move to ME
|
insilmaril@721
|
4205 |
{
|
insilmaril@721
|
4206 |
return mapScene->backgroundBrush().color();
|
insilmaril@721
|
4207 |
}
|
insilmaril@721
|
4208 |
|
insilmaril@721
|
4209 |
|
insilmaril@753
|
4210 |
LinkableMapObj::ColorHint VymModel::getMapLinkColorHint() // FIXME-3 move to ME
|
insilmaril@721
|
4211 |
{
|
insilmaril@721
|
4212 |
return linkcolorhint;
|
insilmaril@721
|
4213 |
}
|
insilmaril@721
|
4214 |
|
insilmaril@753
|
4215 |
QColor VymModel::getMapDefLinkColor() // FIXME-3 move to ME
|
insilmaril@721
|
4216 |
{
|
insilmaril@721
|
4217 |
return defLinkColor;
|
insilmaril@721
|
4218 |
}
|
insilmaril@721
|
4219 |
|
insilmaril@753
|
4220 |
void VymModel::setMapDefXLinkColor(QColor col) // FIXME-3 move to ME
|
insilmaril@721
|
4221 |
{
|
insilmaril@721
|
4222 |
defXLinkColor=col;
|
insilmaril@721
|
4223 |
}
|
insilmaril@721
|
4224 |
|
insilmaril@753
|
4225 |
QColor VymModel::getMapDefXLinkColor() // FIXME-3 move to ME
|
insilmaril@721
|
4226 |
{
|
insilmaril@721
|
4227 |
return defXLinkColor;
|
insilmaril@721
|
4228 |
}
|
insilmaril@721
|
4229 |
|
insilmaril@753
|
4230 |
void VymModel::setMapDefXLinkWidth (int w) // FIXME-3 move to ME
|
insilmaril@721
|
4231 |
{
|
insilmaril@721
|
4232 |
defXLinkWidth=w;
|
insilmaril@721
|
4233 |
}
|
insilmaril@721
|
4234 |
|
insilmaril@753
|
4235 |
int VymModel::getMapDefXLinkWidth() // FIXME-3 move to ME
|
insilmaril@721
|
4236 |
{
|
insilmaril@721
|
4237 |
return defXLinkWidth;
|
insilmaril@721
|
4238 |
}
|
insilmaril@721
|
4239 |
|
insilmaril@753
|
4240 |
void VymModel::move(const double &x, const double &y) // FIXME-3
|
insilmaril@753
|
4241 |
{
|
insilmaril@753
|
4242 |
int i=x; i=y;
|
insilmaril@753
|
4243 |
/*
|
insilmaril@735
|
4244 |
BranchObj *bo = getSelectedBranch();
|
insilmaril@735
|
4245 |
if (bo &&
|
insilmaril@735
|
4246 |
(selectionType()==TreeItem::Branch ||
|
insilmaril@735
|
4247 |
selectionType()==TreeItem::MapCenter ||
|
insilmaril@735
|
4248 |
selectionType()==TreeItem::Image
|
insilmaril@735
|
4249 |
))
|
insilmaril@721
|
4250 |
{
|
insilmaril@735
|
4251 |
QPointF ap(bo->getAbsPos());
|
insilmaril@721
|
4252 |
QPointF to(x, y);
|
insilmaril@721
|
4253 |
if (ap != to)
|
insilmaril@721
|
4254 |
{
|
insilmaril@721
|
4255 |
QString ps=qpointfToString(ap);
|
insilmaril@735
|
4256 |
QString s=getSelectString();
|
insilmaril@721
|
4257 |
saveState(
|
insilmaril@721
|
4258 |
s, "move "+ps,
|
insilmaril@721
|
4259 |
s, "move "+qpointfToString(to),
|
insilmaril@735
|
4260 |
QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
|
insilmaril@735
|
4261 |
bo->move(x,y);
|
insilmaril@721
|
4262 |
reposition();
|
insilmaril@721
|
4263 |
selection.update();
|
insilmaril@721
|
4264 |
}
|
insilmaril@721
|
4265 |
}
|
insilmaril@753
|
4266 |
*/
|
insilmaril@721
|
4267 |
}
|
insilmaril@721
|
4268 |
|
insilmaril@753
|
4269 |
void VymModel::moveRel (const double &x, const double &y) // FIXME-3
|
insilmaril@753
|
4270 |
{
|
insilmaril@753
|
4271 |
int i=x; i=y;
|
insilmaril@753
|
4272 |
/*
|
insilmaril@735
|
4273 |
BranchObj *bo = getSelectedBranch();
|
insilmaril@735
|
4274 |
if (bo &&
|
insilmaril@735
|
4275 |
(selectionType()==TreeItem::Branch ||
|
insilmaril@735
|
4276 |
selectionType()==TreeItem::MapCenter ||
|
insilmaril@735
|
4277 |
selectionType()==TreeItem::Image
|
insilmaril@735
|
4278 |
))
|
insilmaril@735
|
4279 |
if (bo)
|
insilmaril@721
|
4280 |
{
|
insilmaril@735
|
4281 |
QPointF rp(bo->getRelPos());
|
insilmaril@721
|
4282 |
QPointF to(x, y);
|
insilmaril@721
|
4283 |
if (rp != to)
|
insilmaril@721
|
4284 |
{
|
insilmaril@735
|
4285 |
QString ps=qpointfToString (bo->getRelPos());
|
insilmaril@735
|
4286 |
QString s=getSelectString(bo);
|
insilmaril@721
|
4287 |
saveState(
|
insilmaril@721
|
4288 |
s, "moveRel "+ps,
|
insilmaril@721
|
4289 |
s, "moveRel "+qpointfToString(to),
|
insilmaril@735
|
4290 |
QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
|
insilmaril@735
|
4291 |
((OrnamentedObj*)bo)->move2RelPos (x,y);
|
insilmaril@721
|
4292 |
reposition();
|
insilmaril@735
|
4293 |
bo->updateLink();
|
insilmaril@721
|
4294 |
selection.update();
|
insilmaril@721
|
4295 |
}
|
insilmaril@721
|
4296 |
}
|
insilmaril@753
|
4297 |
*/
|
insilmaril@721
|
4298 |
}
|
insilmaril@721
|
4299 |
|
insilmaril@721
|
4300 |
|
insilmaril@696
|
4301 |
void VymModel::animate()
|
insilmaril@696
|
4302 |
{
|
insilmaril@696
|
4303 |
animationTimer->stop();
|
insilmaril@696
|
4304 |
BranchObj *bo;
|
insilmaril@696
|
4305 |
int i=0;
|
insilmaril@696
|
4306 |
while (i<animObjList.size() )
|
insilmaril@696
|
4307 |
{
|
insilmaril@696
|
4308 |
bo=(BranchObj*)animObjList.at(i);
|
insilmaril@696
|
4309 |
if (!bo->animate())
|
insilmaril@696
|
4310 |
{
|
insilmaril@721
|
4311 |
if (i>=0)
|
insilmaril@721
|
4312 |
{
|
insilmaril@721
|
4313 |
animObjList.removeAt(i);
|
insilmaril@721
|
4314 |
i--;
|
insilmaril@721
|
4315 |
}
|
insilmaril@696
|
4316 |
}
|
insilmaril@696
|
4317 |
bo->reposition();
|
insilmaril@696
|
4318 |
i++;
|
insilmaril@696
|
4319 |
}
|
insilmaril@735
|
4320 |
QItemSelection sel=selModel->selection();
|
insilmaril@735
|
4321 |
emit (selectionChanged(sel,sel));
|
insilmaril@735
|
4322 |
|
insilmaril@696
|
4323 |
mapScene->update();
|
insilmaril@723
|
4324 |
if (!animObjList.isEmpty()) animationTimer->start();
|
insilmaril@696
|
4325 |
}
|
insilmaril@696
|
4326 |
|
insilmaril@696
|
4327 |
|
insilmaril@723
|
4328 |
void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
|
insilmaril@696
|
4329 |
{
|
insilmaril@755
|
4330 |
if (bo && bo->getTreeItem()->depth()>0)
|
insilmaril@696
|
4331 |
{
|
insilmaril@696
|
4332 |
AnimPoint ap;
|
insilmaril@696
|
4333 |
ap.setStart (start);
|
insilmaril@696
|
4334 |
ap.setDest (dest);
|
insilmaril@696
|
4335 |
ap.setTicks (animationTicks);
|
insilmaril@696
|
4336 |
ap.setAnimated (true);
|
insilmaril@696
|
4337 |
bo->setAnimation (ap);
|
insilmaril@696
|
4338 |
animObjList.append( bo );
|
insilmaril@696
|
4339 |
animationTimer->setSingleShot (true);
|
insilmaril@696
|
4340 |
animationTimer->start(animationInterval);
|
insilmaril@696
|
4341 |
}
|
insilmaril@696
|
4342 |
}
|
insilmaril@696
|
4343 |
|
insilmaril@722
|
4344 |
void VymModel::stopAnimation (MapObj *mo)
|
insilmaril@722
|
4345 |
{
|
insilmaril@722
|
4346 |
int i=animObjList.indexOf(mo);
|
insilmaril@722
|
4347 |
if (i>=0)
|
insilmaril@722
|
4348 |
animObjList.removeAt (i);
|
insilmaril@722
|
4349 |
}
|
insilmaril@722
|
4350 |
|
insilmaril@721
|
4351 |
void VymModel::sendSelection()
|
insilmaril@721
|
4352 |
{
|
insilmaril@721
|
4353 |
if (netstate!=Server) return;
|
insilmaril@721
|
4354 |
sendData (QString("select (\"%1\")").arg(selection.getSelectString()) );
|
insilmaril@721
|
4355 |
}
|
insilmaril@721
|
4356 |
|
insilmaril@721
|
4357 |
void VymModel::newServer()
|
insilmaril@721
|
4358 |
{
|
insilmaril@721
|
4359 |
port=54321;
|
insilmaril@721
|
4360 |
sendCounter=0;
|
insilmaril@721
|
4361 |
tcpServer = new QTcpServer(this);
|
insilmaril@721
|
4362 |
if (!tcpServer->listen(QHostAddress::Any,port)) {
|
insilmaril@721
|
4363 |
QMessageBox::critical(NULL, "vym server",
|
insilmaril@721
|
4364 |
QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
|
insilmaril@746
|
4365 |
//FIXME-3 needed? we are no widget any longer... close();
|
insilmaril@721
|
4366 |
return;
|
insilmaril@721
|
4367 |
}
|
insilmaril@721
|
4368 |
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
|
insilmaril@721
|
4369 |
netstate=Server;
|
insilmaril@721
|
4370 |
cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
|
insilmaril@721
|
4371 |
}
|
insilmaril@721
|
4372 |
|
insilmaril@721
|
4373 |
void VymModel::connectToServer()
|
insilmaril@721
|
4374 |
{
|
insilmaril@721
|
4375 |
port=54321;
|
insilmaril@721
|
4376 |
server="salam.suse.de";
|
insilmaril@721
|
4377 |
server="localhost";
|
insilmaril@721
|
4378 |
clientSocket = new QTcpSocket (this);
|
insilmaril@721
|
4379 |
clientSocket->abort();
|
insilmaril@721
|
4380 |
clientSocket->connectToHost(server ,port);
|
insilmaril@721
|
4381 |
connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
|
insilmaril@721
|
4382 |
connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
|
insilmaril@721
|
4383 |
this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
|
insilmaril@721
|
4384 |
netstate=Client;
|
insilmaril@721
|
4385 |
cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
|
insilmaril@721
|
4386 |
|
insilmaril@721
|
4387 |
|
insilmaril@721
|
4388 |
}
|
insilmaril@721
|
4389 |
|
insilmaril@721
|
4390 |
void VymModel::newClient()
|
insilmaril@721
|
4391 |
{
|
insilmaril@721
|
4392 |
QTcpSocket *newClient = tcpServer->nextPendingConnection();
|
insilmaril@721
|
4393 |
connect(newClient, SIGNAL(disconnected()),
|
insilmaril@721
|
4394 |
newClient, SLOT(deleteLater()));
|
insilmaril@721
|
4395 |
|
insilmaril@721
|
4396 |
cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
|
insilmaril@721
|
4397 |
|
insilmaril@721
|
4398 |
clientList.append (newClient);
|
insilmaril@721
|
4399 |
}
|
insilmaril@721
|
4400 |
|
insilmaril@721
|
4401 |
|
insilmaril@721
|
4402 |
void VymModel::sendData(const QString &s)
|
insilmaril@721
|
4403 |
{
|
insilmaril@721
|
4404 |
if (clientList.size()==0) return;
|
insilmaril@721
|
4405 |
|
insilmaril@721
|
4406 |
// Create bytearray to send
|
insilmaril@721
|
4407 |
QByteArray block;
|
insilmaril@721
|
4408 |
QDataStream out(&block, QIODevice::WriteOnly);
|
insilmaril@721
|
4409 |
out.setVersion(QDataStream::Qt_4_0);
|
insilmaril@721
|
4410 |
|
insilmaril@721
|
4411 |
// Reserve some space for blocksize
|
insilmaril@721
|
4412 |
out << (quint16)0;
|
insilmaril@721
|
4413 |
|
insilmaril@721
|
4414 |
// Write sendCounter
|
insilmaril@721
|
4415 |
out << sendCounter++;
|
insilmaril@721
|
4416 |
|
insilmaril@721
|
4417 |
// Write data
|
insilmaril@721
|
4418 |
out << s;
|
insilmaril@721
|
4419 |
|
insilmaril@721
|
4420 |
// Go back and write blocksize so far
|
insilmaril@721
|
4421 |
out.device()->seek(0);
|
insilmaril@721
|
4422 |
quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
|
insilmaril@721
|
4423 |
out << bs;
|
insilmaril@721
|
4424 |
|
insilmaril@721
|
4425 |
if (debug)
|
insilmaril@721
|
4426 |
cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
|
insilmaril@721
|
4427 |
|
insilmaril@721
|
4428 |
for (int i=0; i<clientList.size(); ++i)
|
insilmaril@721
|
4429 |
{
|
insilmaril@721
|
4430 |
//cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
|
insilmaril@721
|
4431 |
clientList.at(i)->write (block);
|
insilmaril@721
|
4432 |
}
|
insilmaril@721
|
4433 |
}
|
insilmaril@721
|
4434 |
|
insilmaril@721
|
4435 |
void VymModel::readData ()
|
insilmaril@721
|
4436 |
{
|
insilmaril@721
|
4437 |
while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
|
insilmaril@721
|
4438 |
{
|
insilmaril@721
|
4439 |
if (debug)
|
insilmaril@721
|
4440 |
cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
|
insilmaril@721
|
4441 |
quint16 recCounter;
|
insilmaril@721
|
4442 |
quint16 blockSize;
|
insilmaril@721
|
4443 |
|
insilmaril@721
|
4444 |
QDataStream in(clientSocket);
|
insilmaril@721
|
4445 |
in.setVersion(QDataStream::Qt_4_0);
|
insilmaril@721
|
4446 |
|
insilmaril@721
|
4447 |
in >> blockSize;
|
insilmaril@721
|
4448 |
in >> recCounter;
|
insilmaril@721
|
4449 |
|
insilmaril@721
|
4450 |
QString t;
|
insilmaril@721
|
4451 |
in >>t;
|
insilmaril@721
|
4452 |
if (debug)
|
insilmaril@721
|
4453 |
cout << " t="<<qPrintable (t)<<endl;
|
insilmaril@721
|
4454 |
parseAtom (t);
|
insilmaril@721
|
4455 |
}
|
insilmaril@721
|
4456 |
return;
|
insilmaril@721
|
4457 |
}
|
insilmaril@721
|
4458 |
|
insilmaril@721
|
4459 |
void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
|
insilmaril@721
|
4460 |
{
|
insilmaril@721
|
4461 |
switch (socketError) {
|
insilmaril@721
|
4462 |
case QAbstractSocket::RemoteHostClosedError:
|
insilmaril@721
|
4463 |
break;
|
insilmaril@721
|
4464 |
case QAbstractSocket::HostNotFoundError:
|
insilmaril@721
|
4465 |
QMessageBox::information(NULL, vymName +" Network client",
|
insilmaril@721
|
4466 |
"The host was not found. Please check the "
|
insilmaril@721
|
4467 |
"host name and port settings.");
|
insilmaril@721
|
4468 |
break;
|
insilmaril@721
|
4469 |
case QAbstractSocket::ConnectionRefusedError:
|
insilmaril@721
|
4470 |
QMessageBox::information(NULL, vymName + " Network client",
|
insilmaril@721
|
4471 |
"The connection was refused by the peer. "
|
insilmaril@721
|
4472 |
"Make sure the fortune server is running, "
|
insilmaril@721
|
4473 |
"and check that the host name and port "
|
insilmaril@721
|
4474 |
"settings are correct.");
|
insilmaril@721
|
4475 |
break;
|
insilmaril@721
|
4476 |
default:
|
insilmaril@721
|
4477 |
QMessageBox::information(NULL, vymName + " Network client",
|
insilmaril@721
|
4478 |
QString("The following error occurred: %1.")
|
insilmaril@721
|
4479 |
.arg(clientSocket->errorString()));
|
insilmaril@721
|
4480 |
}
|
insilmaril@721
|
4481 |
}
|
insilmaril@721
|
4482 |
|
insilmaril@721
|
4483 |
|
insilmaril@721
|
4484 |
|
insilmaril@721
|
4485 |
|
insilmaril@721
|
4486 |
void VymModel::selectMapSelectionColor()
|
insilmaril@721
|
4487 |
{
|
insilmaril@721
|
4488 |
QColor col = QColorDialog::getColor( defLinkColor, NULL);
|
insilmaril@721
|
4489 |
setSelectionColor (col);
|
insilmaril@721
|
4490 |
}
|
insilmaril@721
|
4491 |
|
insilmaril@721
|
4492 |
void VymModel::setSelectionColorInt (QColor col)
|
insilmaril@721
|
4493 |
{
|
insilmaril@721
|
4494 |
if ( !col.isValid() ) return;
|
insilmaril@721
|
4495 |
saveState (
|
insilmaril@728
|
4496 |
QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
|
insilmaril@721
|
4497 |
QString("setSelectionColor (%1)").arg(col.name()),
|
insilmaril@721
|
4498 |
QString("Set color of selection box to %1").arg(col.name())
|
insilmaril@721
|
4499 |
);
|
insilmaril@721
|
4500 |
|
insilmaril@728
|
4501 |
mapEditor->setSelectionColor (col);
|
insilmaril@721
|
4502 |
}
|
insilmaril@721
|
4503 |
|
insilmaril@746
|
4504 |
/*
|
insilmaril@746
|
4505 |
void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
|
insilmaril@746
|
4506 |
{
|
insilmaril@746
|
4507 |
cout << "VymModel::changeSelection (";
|
insilmaril@746
|
4508 |
if (!newsel.indexes().isEmpty() )
|
insilmaril@746
|
4509 |
cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
|
insilmaril@746
|
4510 |
cout << ",";
|
insilmaril@746
|
4511 |
if (!oldsel.indexes().isEmpty() )
|
insilmaril@746
|
4512 |
cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
|
insilmaril@746
|
4513 |
cout << ")\n";
|
insilmaril@735
|
4514 |
}
|
insilmaril@746
|
4515 |
*/
|
insilmaril@735
|
4516 |
|
insilmaril@742
|
4517 |
void VymModel::updateSelection(const QItemSelection &newsel)
|
insilmaril@735
|
4518 |
{
|
insilmaril@742
|
4519 |
emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
|
insilmaril@735
|
4520 |
ensureSelectionVisible();
|
insilmaril@735
|
4521 |
sendSelection();
|
insilmaril@721
|
4522 |
}
|
insilmaril@721
|
4523 |
|
insilmaril@746
|
4524 |
void VymModel::updateSelection()
|
insilmaril@746
|
4525 |
{
|
insilmaril@746
|
4526 |
QItemSelection newsel=selModel->selection();
|
insilmaril@746
|
4527 |
updateSelection (newsel);
|
insilmaril@746
|
4528 |
}
|
insilmaril@746
|
4529 |
|
insilmaril@721
|
4530 |
void VymModel::setSelectionColor(QColor col)
|
insilmaril@721
|
4531 |
{
|
insilmaril@721
|
4532 |
if ( !col.isValid() ) return;
|
insilmaril@721
|
4533 |
saveState (
|
insilmaril@728
|
4534 |
QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
|
insilmaril@721
|
4535 |
QString("setSelectionColor (%1)").arg(col.name()),
|
insilmaril@721
|
4536 |
QString("Set color of selection box to %1").arg(col.name())
|
insilmaril@721
|
4537 |
);
|
insilmaril@721
|
4538 |
setSelectionColorInt (col);
|
insilmaril@721
|
4539 |
}
|
insilmaril@721
|
4540 |
|
insilmaril@721
|
4541 |
QColor VymModel::getSelectionColor()
|
insilmaril@721
|
4542 |
{
|
insilmaril@728
|
4543 |
return mapEditor->getSelectionColor();
|
insilmaril@721
|
4544 |
}
|
insilmaril@721
|
4545 |
|
insilmaril@753
|
4546 |
void VymModel::setHideTmpMode (TreeItem::HideTmpMode mode)
|
insilmaril@721
|
4547 |
{
|
insilmaril@721
|
4548 |
hidemode=mode;
|
insilmaril@753
|
4549 |
for (int i=0;i<rootItem->childCount();i++)
|
insilmaril@753
|
4550 |
rootItem->child(i)->setHideTmp (mode);
|
insilmaril@721
|
4551 |
reposition();
|
insilmaril@746
|
4552 |
// FIXME-3 needed? scene()->update();
|
insilmaril@721
|
4553 |
}
|
insilmaril@721
|
4554 |
|
insilmaril@721
|
4555 |
|
insilmaril@754
|
4556 |
QRectF VymModel::getTotalBBox() //FIXME-2
|
insilmaril@721
|
4557 |
{
|
insilmaril@721
|
4558 |
QRectF r;
|
insilmaril@754
|
4559 |
/*
|
insilmaril@754
|
4560 |
for (int i=0;i<rootItem->branchCount(); i++)
|
insilmaril@754
|
4561 |
r=addBBox (rootItem->getBranchNum(i)->getTotalBBox(), r);
|
insilmaril@754
|
4562 |
*/
|
insilmaril@721
|
4563 |
return r;
|
insilmaril@721
|
4564 |
}
|
insilmaril@652
|
4565 |
|
insilmaril@652
|
4566 |
//////////////////////////////////////////////
|
insilmaril@652
|
4567 |
// Selection related
|
insilmaril@652
|
4568 |
//////////////////////////////////////////////
|
insilmaril@652
|
4569 |
|
insilmaril@727
|
4570 |
void VymModel::setSelectionModel (QItemSelectionModel *sm)
|
insilmaril@727
|
4571 |
{
|
insilmaril@727
|
4572 |
selModel=sm;
|
insilmaril@728
|
4573 |
}
|
insilmaril@728
|
4574 |
|
insilmaril@728
|
4575 |
QItemSelectionModel* VymModel::getSelectionModel()
|
insilmaril@728
|
4576 |
{
|
insilmaril@728
|
4577 |
return selModel;
|
insilmaril@727
|
4578 |
}
|
insilmaril@727
|
4579 |
|
insilmaril@721
|
4580 |
void VymModel::setSelectionBlocked (bool b)
|
insilmaril@721
|
4581 |
{
|
insilmaril@721
|
4582 |
if (b)
|
insilmaril@721
|
4583 |
selection.block();
|
insilmaril@721
|
4584 |
else
|
insilmaril@721
|
4585 |
selection.unblock();
|
insilmaril@721
|
4586 |
}
|
insilmaril@721
|
4587 |
|
insilmaril@721
|
4588 |
bool VymModel::isSelectionBlocked()
|
insilmaril@721
|
4589 |
{
|
insilmaril@721
|
4590 |
return selection.isBlocked();
|
insilmaril@721
|
4591 |
}
|
insilmaril@721
|
4592 |
|
insilmaril@727
|
4593 |
bool VymModel::select ()
|
insilmaril@727
|
4594 |
{
|
insilmaril@727
|
4595 |
QModelIndex index=selModel->selectedIndexes().first(); // TODO no multiselections yet
|
insilmaril@727
|
4596 |
|
insilmaril@745
|
4597 |
TreeItem *item = getItem (index);
|
insilmaril@727
|
4598 |
return select (item->getLMO() );
|
insilmaril@727
|
4599 |
}
|
insilmaril@727
|
4600 |
|
insilmaril@721
|
4601 |
bool VymModel::select (const QString &s)
|
insilmaril@721
|
4602 |
{
|
insilmaril@754
|
4603 |
TreeItem *ti=findBySelectString(s);
|
insilmaril@754
|
4604 |
if (ti)
|
insilmaril@721
|
4605 |
{
|
insilmaril@735
|
4606 |
unselect();
|
insilmaril@754
|
4607 |
select (ti);
|
insilmaril@721
|
4608 |
return true;
|
insilmaril@735
|
4609 |
}
|
insilmaril@721
|
4610 |
return false;
|
insilmaril@721
|
4611 |
}
|
insilmaril@721
|
4612 |
|
insilmaril@721
|
4613 |
bool VymModel::select (LinkableMapObj *lmo)
|
insilmaril@721
|
4614 |
{
|
insilmaril@735
|
4615 |
QItemSelection oldsel=selModel->selection();
|
insilmaril@735
|
4616 |
|
insilmaril@735
|
4617 |
if (lmo)
|
insilmaril@738
|
4618 |
return select (lmo->getTreeItem() );
|
insilmaril@738
|
4619 |
else
|
insilmaril@738
|
4620 |
return false;
|
insilmaril@738
|
4621 |
}
|
insilmaril@738
|
4622 |
|
insilmaril@738
|
4623 |
bool VymModel::select (TreeItem *ti)
|
insilmaril@738
|
4624 |
{
|
insilmaril@738
|
4625 |
if (ti)
|
insilmaril@721
|
4626 |
{
|
insilmaril@735
|
4627 |
QModelIndex ix=index(ti);
|
insilmaril@735
|
4628 |
selModel->select (ix,QItemSelectionModel::ClearAndSelect );
|
insilmaril@738
|
4629 |
ti->setLastSelectedBranch();
|
insilmaril@721
|
4630 |
return true;
|
insilmaril@721
|
4631 |
}
|
insilmaril@721
|
4632 |
return false;
|
insilmaril@721
|
4633 |
}
|
insilmaril@721
|
4634 |
|
insilmaril@721
|
4635 |
void VymModel::unselect()
|
insilmaril@721
|
4636 |
{
|
insilmaril@735
|
4637 |
selModel->clearSelection();
|
insilmaril@721
|
4638 |
}
|
insilmaril@721
|
4639 |
|
insilmaril@721
|
4640 |
void VymModel::reselect()
|
insilmaril@721
|
4641 |
{
|
insilmaril@721
|
4642 |
selection.reselect();
|
insilmaril@721
|
4643 |
}
|
insilmaril@721
|
4644 |
|
insilmaril@746
|
4645 |
void VymModel::ensureSelectionVisible() //FIXME-3 needed? in vymmodel.h commented...
|
insilmaril@721
|
4646 |
{
|
insilmaril@735
|
4647 |
LinkableMapObj *lmo=getSelectedLMO();
|
insilmaril@721
|
4648 |
if (lmo &&mapEditor) mapEditor->ensureVisible (lmo->getBBox() );
|
insilmaril@746
|
4649 |
}
|
insilmaril@746
|
4650 |
|
insilmaril@753
|
4651 |
void VymModel::emitNoteHasChanged (TreeItem *ti)
|
insilmaril@746
|
4652 |
{
|
insilmaril@746
|
4653 |
QModelIndex ix=index(ti);
|
insilmaril@753
|
4654 |
emit (noteHasChanged (ix) );
|
insilmaril@753
|
4655 |
}
|
insilmaril@753
|
4656 |
|
insilmaril@753
|
4657 |
void VymModel::emitDataHasChanged (TreeItem *ti)
|
insilmaril@753
|
4658 |
{
|
insilmaril@753
|
4659 |
QModelIndex ix=index(ti);
|
insilmaril@753
|
4660 |
emit (dataHasChanged (ix) );
|
insilmaril@721
|
4661 |
}
|
insilmaril@721
|
4662 |
|
insilmaril@750
|
4663 |
|
insilmaril@750
|
4664 |
//void VymModel::selectInt (LinkableMapObj *lmo) // FIXME-3 still needed?
|
insilmaril@750
|
4665 |
/*
|
insilmaril@721
|
4666 |
{
|
insilmaril@721
|
4667 |
if (selection.select(lmo))
|
insilmaril@721
|
4668 |
{
|
insilmaril@729
|
4669 |
//selection.update();
|
insilmaril@746
|
4670 |
sendSelection (); // FIXME-4 VM use signal
|
insilmaril@721
|
4671 |
}
|
insilmaril@721
|
4672 |
}
|
insilmaril@721
|
4673 |
|
insilmaril@750
|
4674 |
void VymModel::selectInt (TreeItem *ti)
|
insilmaril@750
|
4675 |
{
|
insilmaril@750
|
4676 |
if (selection.select(lmo))
|
insilmaril@750
|
4677 |
{
|
insilmaril@750
|
4678 |
//selection.update();
|
insilmaril@750
|
4679 |
sendSelection (); // FIXME-4 VM use signal
|
insilmaril@750
|
4680 |
}
|
insilmaril@750
|
4681 |
}
|
insilmaril@750
|
4682 |
*/
|
insilmaril@721
|
4683 |
|
insilmaril@721
|
4684 |
void VymModel::selectNextBranchInt()
|
insilmaril@721
|
4685 |
{
|
insilmaril@755
|
4686 |
BranchItem *bi=getSelectedBranchItem();
|
insilmaril@755
|
4687 |
if (bi)
|
insilmaril@721
|
4688 |
{
|
insilmaril@755
|
4689 |
TreeItem *pi=bi->parent();
|
insilmaril@755
|
4690 |
if (bi!=rootItem)
|
insilmaril@755
|
4691 |
{
|
insilmaril@755
|
4692 |
int i=bi->num();
|
insilmaril@755
|
4693 |
if (i<pi->branchCount() )
|
insilmaril@755
|
4694 |
{
|
insilmaril@755
|
4695 |
// select previous branch with same parent
|
insilmaril@755
|
4696 |
i++;
|
insilmaril@755
|
4697 |
select (pi->getBranchNum(i));
|
insilmaril@755
|
4698 |
return;
|
insilmaril@755
|
4699 |
}
|
insilmaril@755
|
4700 |
}
|
insilmaril@721
|
4701 |
|
insilmaril@721
|
4702 |
}
|
insilmaril@721
|
4703 |
}
|
insilmaril@721
|
4704 |
|
insilmaril@755
|
4705 |
void VymModel::selectPrevBranchInt()
|
insilmaril@755
|
4706 |
{
|
insilmaril@755
|
4707 |
|
insilmaril@755
|
4708 |
BranchItem *bi=getSelectedBranchItem();
|
insilmaril@755
|
4709 |
if (bi)
|
insilmaril@755
|
4710 |
{
|
insilmaril@755
|
4711 |
BranchItem *pi=(BranchItem*)bi->parent();
|
insilmaril@755
|
4712 |
if (bi!=rootItem)
|
insilmaril@755
|
4713 |
{
|
insilmaril@755
|
4714 |
int i=bi->num();
|
insilmaril@755
|
4715 |
if (i>0)
|
insilmaril@755
|
4716 |
{
|
insilmaril@755
|
4717 |
// select previous branch with same parent
|
insilmaril@755
|
4718 |
bi=pi->getBranchNum(i-1);
|
insilmaril@755
|
4719 |
select (bi);
|
insilmaril@755
|
4720 |
return;
|
insilmaril@755
|
4721 |
}
|
insilmaril@755
|
4722 |
bi=pi;
|
insilmaril@755
|
4723 |
while (bi->branchCount() >0)
|
insilmaril@755
|
4724 |
bi=bi->getLastBranch();
|
insilmaril@755
|
4725 |
select (bi);
|
insilmaril@755
|
4726 |
|
insilmaril@755
|
4727 |
// Try to select last branch in parent pi2 previous to own parent pi
|
insilmaril@755
|
4728 |
/*
|
insilmaril@755
|
4729 |
TreeItem *pi2=pi->parent();
|
insilmaril@755
|
4730 |
if (pi2)
|
insilmaril@755
|
4731 |
{
|
insilmaril@755
|
4732 |
int j=pi->num();
|
insilmaril@755
|
4733 |
if (pi2->)
|
insilmaril@755
|
4734 |
}
|
insilmaril@755
|
4735 |
*/
|
insilmaril@755
|
4736 |
}
|
insilmaril@755
|
4737 |
}
|
insilmaril@755
|
4738 |
}
|
insilmaril@755
|
4739 |
|
insilmaril@755
|
4740 |
void VymModel::selectAboveBranchInt()
|
insilmaril@755
|
4741 |
{
|
insilmaril@755
|
4742 |
BranchItem *bi=getSelectedBranchItem();
|
insilmaril@755
|
4743 |
if (bi)
|
insilmaril@755
|
4744 |
{
|
insilmaril@755
|
4745 |
BranchItem *newbi=NULL;
|
insilmaril@755
|
4746 |
BranchItem *pi=(BranchItem*)bi->parent();
|
insilmaril@755
|
4747 |
int i=bi->num();
|
insilmaril@755
|
4748 |
if (i>0)
|
insilmaril@755
|
4749 |
{
|
insilmaril@755
|
4750 |
// goto previous branch with same parent
|
insilmaril@755
|
4751 |
newbi=pi->getBranchNum(i-1);
|
insilmaril@755
|
4752 |
while (newbi->branchCount() >0 )
|
insilmaril@755
|
4753 |
newbi=newbi->getLastBranch();
|
insilmaril@755
|
4754 |
}
|
insilmaril@755
|
4755 |
else
|
insilmaril@755
|
4756 |
newbi=pi;
|
insilmaril@755
|
4757 |
if (newbi==rootItem)
|
insilmaril@755
|
4758 |
// already at top branch (resp. mapcenter)
|
insilmaril@755
|
4759 |
return;
|
insilmaril@755
|
4760 |
select (newbi);
|
insilmaril@755
|
4761 |
}
|
insilmaril@755
|
4762 |
}
|
insilmaril@755
|
4763 |
|
insilmaril@755
|
4764 |
void VymModel::selectBelowBranchInt()
|
insilmaril@755
|
4765 |
{
|
insilmaril@755
|
4766 |
BranchItem *bi=getSelectedBranchItem();
|
insilmaril@755
|
4767 |
if (bi)
|
insilmaril@755
|
4768 |
{
|
insilmaril@755
|
4769 |
BranchItem *newbi=NULL;
|
insilmaril@755
|
4770 |
|
insilmaril@755
|
4771 |
if (bi->branchCount() >0)
|
insilmaril@755
|
4772 |
newbi=bi->getFirstBranch();
|
insilmaril@755
|
4773 |
else
|
insilmaril@755
|
4774 |
{
|
insilmaril@755
|
4775 |
BranchItem *pi;
|
insilmaril@755
|
4776 |
int i;
|
insilmaril@755
|
4777 |
while (!newbi)
|
insilmaril@755
|
4778 |
{
|
insilmaril@755
|
4779 |
pi=(BranchItem*)bi->parent();
|
insilmaril@755
|
4780 |
i=bi->num();
|
insilmaril@755
|
4781 |
if (pi->branchCount()-1 > i)
|
insilmaril@755
|
4782 |
{
|
insilmaril@755
|
4783 |
newbi=(BranchItem*)pi->getBranchNum(i+1);
|
insilmaril@755
|
4784 |
//done...
|
insilmaril@755
|
4785 |
break;
|
insilmaril@755
|
4786 |
}
|
insilmaril@755
|
4787 |
else
|
insilmaril@755
|
4788 |
// look for siblings of myself
|
insilmaril@755
|
4789 |
// or parent, or parent of parent...
|
insilmaril@755
|
4790 |
bi=pi;
|
insilmaril@755
|
4791 |
if (bi==rootItem)
|
insilmaril@755
|
4792 |
// already at end
|
insilmaril@755
|
4793 |
return;
|
insilmaril@755
|
4794 |
}
|
insilmaril@755
|
4795 |
}
|
insilmaril@755
|
4796 |
select (newbi);
|
insilmaril@755
|
4797 |
}
|
insilmaril@755
|
4798 |
}
|
insilmaril@755
|
4799 |
|
insilmaril@755
|
4800 |
void VymModel::selectUpperBranch()
|
insilmaril@755
|
4801 |
{
|
insilmaril@755
|
4802 |
if (selection.isBlocked() ) return;
|
insilmaril@755
|
4803 |
|
insilmaril@755
|
4804 |
BranchItem *bi=getSelectedBranchItem();
|
insilmaril@755
|
4805 |
if (bi && bi->isBranchLikeType())
|
insilmaril@755
|
4806 |
selectAboveBranchInt();
|
insilmaril@755
|
4807 |
}
|
insilmaril@755
|
4808 |
|
insilmaril@721
|
4809 |
void VymModel::selectLowerBranch()
|
insilmaril@721
|
4810 |
{
|
insilmaril@721
|
4811 |
if (selection.isBlocked() ) return;
|
insilmaril@721
|
4812 |
|
insilmaril@753
|
4813 |
BranchItem *bi=getSelectedBranchItem();
|
insilmaril@755
|
4814 |
if (bi && bi->isBranchLikeType())
|
insilmaril@755
|
4815 |
selectBelowBranchInt();
|
insilmaril@721
|
4816 |
}
|
insilmaril@721
|
4817 |
|
insilmaril@721
|
4818 |
|
insilmaril@721
|
4819 |
void VymModel::selectLeftBranch()
|
insilmaril@721
|
4820 |
{
|
insilmaril@721
|
4821 |
if (selection.isBlocked() ) return;
|
insilmaril@721
|
4822 |
|
insilmaril@735
|
4823 |
QItemSelection oldsel=selModel->selection();
|
insilmaril@735
|
4824 |
|
insilmaril@753
|
4825 |
BranchItem* par;
|
insilmaril@753
|
4826 |
BranchItem *selbi=getSelectedBranchItem();
|
insilmaril@753
|
4827 |
TreeItem::Type type=selbi->getType();
|
insilmaril@753
|
4828 |
if (selbi)
|
insilmaril@721
|
4829 |
{
|
insilmaril@753
|
4830 |
if (type == TreeItem::MapCenter)
|
insilmaril@721
|
4831 |
{
|
insilmaril@753
|
4832 |
QModelIndex ix=index(selbi);
|
insilmaril@735
|
4833 |
selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect );
|
insilmaril@721
|
4834 |
} else
|
insilmaril@721
|
4835 |
{
|
insilmaril@753
|
4836 |
par=(BranchItem*)selbi->parent();
|
insilmaril@753
|
4837 |
if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO...
|
insilmaril@721
|
4838 |
{
|
insilmaril@735
|
4839 |
// right of center
|
insilmaril@753
|
4840 |
if (type == TreeItem::Branch ||
|
insilmaril@753
|
4841 |
type == TreeItem::Image)
|
insilmaril@721
|
4842 |
{
|
insilmaril@753
|
4843 |
QModelIndex ix=index (selbi->parent());
|
insilmaril@735
|
4844 |
selModel->select (ix,QItemSelectionModel::ClearAndSelect );
|
insilmaril@721
|
4845 |
}
|
insilmaril@721
|
4846 |
} else
|
insilmaril@721
|
4847 |
{
|
insilmaril@735
|
4848 |
// left of center
|
insilmaril@753
|
4849 |
if (type == TreeItem::Branch )
|
insilmaril@721
|
4850 |
{
|
insilmaril@754
|
4851 |
cout << "VM::selLeft\n";
|
insilmaril@735
|
4852 |
selectLastSelectedBranch();
|
insilmaril@735
|
4853 |
return;
|
insilmaril@721
|
4854 |
}
|
insilmaril@721
|
4855 |
}
|
insilmaril@721
|
4856 |
}
|
insilmaril@721
|
4857 |
}
|
insilmaril@721
|
4858 |
}
|
insilmaril@721
|
4859 |
|
insilmaril@721
|
4860 |
void VymModel::selectRightBranch()
|
insilmaril@721
|
4861 |
{
|
insilmaril@721
|
4862 |
if (selection.isBlocked() ) return;
|
insilmaril@721
|
4863 |
|
insilmaril@735
|
4864 |
QItemSelection oldsel=selModel->selection();
|
insilmaril@735
|
4865 |
|
insilmaril@753
|
4866 |
BranchItem* par;
|
insilmaril@753
|
4867 |
BranchItem *selbi=getSelectedBranchItem();
|
insilmaril@753
|
4868 |
TreeItem::Type type=selbi->getType();
|
insilmaril@753
|
4869 |
if (selbi)
|
insilmaril@721
|
4870 |
{
|
insilmaril@753
|
4871 |
if (type==TreeItem::MapCenter)
|
insilmaril@721
|
4872 |
{
|
insilmaril@753
|
4873 |
QModelIndex ix=index(selbi);
|
insilmaril@737
|
4874 |
selModel->select (index (0,0,ix),QItemSelectionModel::ClearAndSelect );
|
insilmaril@721
|
4875 |
} else
|
insilmaril@721
|
4876 |
{
|
insilmaril@753
|
4877 |
par=(BranchItem*)selbi->parent();
|
insilmaril@753
|
4878 |
if (selbi->getBranchObj()->getOrientation()==LinkableMapObj::RightOfCenter) //FIXME-3 check getBO
|
insilmaril@721
|
4879 |
{
|
insilmaril@737
|
4880 |
// right of center
|
insilmaril@753
|
4881 |
if ( type== TreeItem::Branch )
|
insilmaril@737
|
4882 |
{
|
insilmaril@737
|
4883 |
selectLastSelectedBranch();
|
insilmaril@737
|
4884 |
return;
|
insilmaril@737
|
4885 |
}
|
insilmaril@737
|
4886 |
} else
|
insilmaril@737
|
4887 |
{
|
insilmaril@737
|
4888 |
// left of center
|
insilmaril@753
|
4889 |
if (type == TreeItem::Branch ||
|
insilmaril@753
|
4890 |
type == TreeItem::Image)
|
insilmaril@721
|
4891 |
{
|
insilmaril@754
|
4892 |
cout << "VM::selRight\n";
|
insilmaril@753
|
4893 |
QModelIndex ix=index(selbi->parent());
|
insilmaril@735
|
4894 |
selModel->select (ix,QItemSelectionModel::ClearAndSelect );
|
insilmaril@721
|
4895 |
}
|
insilmaril@721
|
4896 |
}
|
insilmaril@737
|
4897 |
}
|
insilmaril@721
|
4898 |
}
|
insilmaril@721
|
4899 |
}
|
insilmaril@721
|
4900 |
|
insilmaril@721
|
4901 |
void VymModel::selectFirstBranch()
|
insilmaril@721
|
4902 |
{
|
insilmaril@738
|
4903 |
TreeItem *ti=getSelectedBranchItem();
|
insilmaril@738
|
4904 |
if (ti)
|
insilmaril@721
|
4905 |
{
|
insilmaril@738
|
4906 |
TreeItem *par=ti->parent();
|
insilmaril@721
|
4907 |
if (!par) return;
|
insilmaril@738
|
4908 |
TreeItem *ti2=par->getFirstBranch();
|
insilmaril@738
|
4909 |
if (ti2) {
|
insilmaril@738
|
4910 |
select(ti2);
|
insilmaril@721
|
4911 |
selection.update();
|
insilmaril@721
|
4912 |
ensureSelectionVisible();
|
insilmaril@721
|
4913 |
sendSelection();
|
insilmaril@721
|
4914 |
}
|
insilmaril@721
|
4915 |
}
|
insilmaril@721
|
4916 |
}
|
insilmaril@721
|
4917 |
|
insilmaril@721
|
4918 |
void VymModel::selectLastBranch()
|
insilmaril@721
|
4919 |
{
|
insilmaril@738
|
4920 |
TreeItem *ti=getSelectedBranchItem();
|
insilmaril@738
|
4921 |
if (ti)
|
insilmaril@721
|
4922 |
{
|
insilmaril@738
|
4923 |
TreeItem *par=ti->parent();
|
insilmaril@721
|
4924 |
if (!par) return;
|
insilmaril@738
|
4925 |
TreeItem *ti2=par->getLastBranch();
|
insilmaril@738
|
4926 |
if (ti2) {
|
insilmaril@738
|
4927 |
select(ti2);
|
insilmaril@721
|
4928 |
selection.update();
|
insilmaril@721
|
4929 |
ensureSelectionVisible();
|
insilmaril@721
|
4930 |
sendSelection();
|
insilmaril@721
|
4931 |
}
|
insilmaril@721
|
4932 |
}
|
insilmaril@721
|
4933 |
}
|
insilmaril@721
|
4934 |
|
insilmaril@735
|
4935 |
void VymModel::selectLastSelectedBranch()
|
insilmaril@735
|
4936 |
{
|
insilmaril@738
|
4937 |
TreeItem *ti=getSelectedBranchItem();
|
insilmaril@738
|
4938 |
if (ti)
|
insilmaril@735
|
4939 |
{
|
insilmaril@738
|
4940 |
ti=ti->getLastSelectedBranch();
|
insilmaril@738
|
4941 |
if (ti) select (ti);
|
insilmaril@735
|
4942 |
}
|
insilmaril@735
|
4943 |
}
|
insilmaril@735
|
4944 |
|
insilmaril@726
|
4945 |
void VymModel::selectParent()
|
insilmaril@726
|
4946 |
{
|
insilmaril@738
|
4947 |
TreeItem *ti=getSelectedItem();
|
insilmaril@738
|
4948 |
TreeItem *par;
|
insilmaril@738
|
4949 |
if (ti)
|
insilmaril@726
|
4950 |
{
|
insilmaril@738
|
4951 |
par=ti->parent();
|
insilmaril@726
|
4952 |
if (!par) return;
|
insilmaril@735
|
4953 |
select(par);
|
insilmaril@726
|
4954 |
selection.update();
|
insilmaril@726
|
4955 |
ensureSelectionVisible();
|
insilmaril@726
|
4956 |
sendSelection();
|
insilmaril@726
|
4957 |
}
|
insilmaril@726
|
4958 |
}
|
insilmaril@726
|
4959 |
|
insilmaril@735
|
4960 |
TreeItem::Type VymModel::selectionType()
|
insilmaril@721
|
4961 |
{
|
insilmaril@735
|
4962 |
QModelIndexList list=selModel->selectedIndexes();
|
insilmaril@735
|
4963 |
if (list.isEmpty()) return TreeItem::Undefined;
|
insilmaril@745
|
4964 |
TreeItem *ti = getItem (list.first() );
|
insilmaril@735
|
4965 |
return ti->getType();
|
insilmaril@735
|
4966 |
|
insilmaril@721
|
4967 |
}
|
insilmaril@721
|
4968 |
|
insilmaril@735
|
4969 |
LinkableMapObj* VymModel::getSelectedLMO()
|
insilmaril@652
|
4970 |
{
|
insilmaril@735
|
4971 |
QModelIndexList list=selModel->selectedIndexes();
|
insilmaril@735
|
4972 |
if (!list.isEmpty() )
|
insilmaril@735
|
4973 |
{
|
insilmaril@745
|
4974 |
TreeItem *ti = getItem (list.first() );
|
insilmaril@735
|
4975 |
TreeItem::Type type=ti->getType();
|
insilmaril@735
|
4976 |
if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
|
insilmaril@735
|
4977 |
{
|
insilmaril@735
|
4978 |
return ti->getLMO();
|
insilmaril@735
|
4979 |
}
|
insilmaril@735
|
4980 |
}
|
insilmaril@735
|
4981 |
return NULL;
|
insilmaril@652
|
4982 |
}
|
insilmaril@735
|
4983 |
|
insilmaril@753
|
4984 |
BranchObj* VymModel::getSelectedBranchObj() // FIXME-3 this should not be needed in the end!!!
|
insilmaril@652
|
4985 |
{
|
insilmaril@738
|
4986 |
TreeItem *ti = getSelectedBranchItem();
|
insilmaril@738
|
4987 |
if (ti)
|
insilmaril@738
|
4988 |
return (BranchObj*)ti->getLMO();
|
insilmaril@738
|
4989 |
else
|
insilmaril@738
|
4990 |
return NULL;
|
insilmaril@738
|
4991 |
}
|
insilmaril@738
|
4992 |
|
insilmaril@749
|
4993 |
BranchItem* VymModel::getSelectedBranchItem()
|
insilmaril@738
|
4994 |
{
|
insilmaril@735
|
4995 |
QModelIndexList list=selModel->selectedIndexes();
|
insilmaril@735
|
4996 |
if (!list.isEmpty() )
|
insilmaril@735
|
4997 |
{
|
insilmaril@745
|
4998 |
TreeItem *ti = getItem (list.first() );
|
insilmaril@735
|
4999 |
TreeItem::Type type=ti->getType();
|
insilmaril@735
|
5000 |
if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
|
insilmaril@749
|
5001 |
return (BranchItem*)ti;
|
insilmaril@735
|
5002 |
}
|
insilmaril@735
|
5003 |
return NULL;
|
insilmaril@735
|
5004 |
}
|
insilmaril@735
|
5005 |
|
insilmaril@738
|
5006 |
TreeItem* VymModel::getSelectedItem()
|
insilmaril@735
|
5007 |
{
|
insilmaril@746
|
5008 |
QModelIndexList list=selModel->selectedIndexes();
|
insilmaril@746
|
5009 |
if (!list.isEmpty() )
|
insilmaril@746
|
5010 |
return getItem (list.first() );
|
insilmaril@746
|
5011 |
else
|
insilmaril@746
|
5012 |
return NULL;
|
insilmaril@735
|
5013 |
}
|
insilmaril@735
|
5014 |
|
insilmaril@735
|
5015 |
QModelIndex VymModel::getSelectedIndex()
|
insilmaril@735
|
5016 |
{
|
insilmaril@735
|
5017 |
QModelIndexList list=selModel->selectedIndexes();
|
insilmaril@735
|
5018 |
if (list.isEmpty() )
|
insilmaril@735
|
5019 |
return QModelIndex();
|
insilmaril@735
|
5020 |
else
|
insilmaril@735
|
5021 |
return list.first();
|
insilmaril@652
|
5022 |
}
|
insilmaril@652
|
5023 |
|
insilmaril@721
|
5024 |
FloatImageObj* VymModel::getSelectedFloatImage()
|
insilmaril@652
|
5025 |
{
|
insilmaril@721
|
5026 |
return selection.getFloatImage();
|
insilmaril@721
|
5027 |
}
|
insilmaril@721
|
5028 |
|
insilmaril@721
|
5029 |
QString VymModel::getSelectString ()
|
insilmaril@721
|
5030 |
{
|
insilmaril@738
|
5031 |
LinkableMapObj *lmo=getSelectedLMO();
|
insilmaril@738
|
5032 |
if (lmo)
|
insilmaril@738
|
5033 |
return getSelectString(lmo);
|
insilmaril@738
|
5034 |
else
|
insilmaril@738
|
5035 |
return QString();
|
insilmaril@652
|
5036 |
}
|
insilmaril@652
|
5037 |
|
insilmaril@749
|
5038 |
QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
|
insilmaril@749
|
5039 |
{
|
insilmaril@749
|
5040 |
if (!lmo) return QString();
|
insilmaril@749
|
5041 |
return getSelectString (lmo->getTreeItem() );
|
insilmaril@749
|
5042 |
}
|
insilmaril@749
|
5043 |
|
insilmaril@749
|
5044 |
QString VymModel::getSelectString (TreeItem *ti)
|
insilmaril@652
|
5045 |
{
|
insilmaril@652
|
5046 |
QString s;
|
insilmaril@749
|
5047 |
if (!ti) return s;
|
insilmaril@749
|
5048 |
if (ti->getType() == TreeItem::Branch ||
|
insilmaril@749
|
5049 |
ti->getType() == TreeItem::MapCenter)
|
insilmaril@652
|
5050 |
{
|
insilmaril@749
|
5051 |
TreeItem *par=ti->parent();
|
insilmaril@652
|
5052 |
if (par)
|
insilmaril@652
|
5053 |
{
|
insilmaril@749
|
5054 |
if (ti->depth() ==1)
|
insilmaril@652
|
5055 |
// Mainbranch, return
|
insilmaril@749
|
5056 |
s= "bo:" + QString("%1").arg(ti->num() );
|
insilmaril@652
|
5057 |
else
|
insilmaril@652
|
5058 |
// Branch, call myself recursively
|
insilmaril@749
|
5059 |
s= getSelectString(par) + ",bo:" + QString("%1").arg(ti->num());
|
insilmaril@652
|
5060 |
} else
|
insilmaril@652
|
5061 |
{
|
insilmaril@652
|
5062 |
// MapCenter
|
insilmaril@749
|
5063 |
int i=rootItem->num(ti);
|
insilmaril@652
|
5064 |
if (i>=0) s=QString("mc:%1").arg(i);
|
insilmaril@652
|
5065 |
}
|
insilmaril@652
|
5066 |
}
|
insilmaril@652
|
5067 |
return s;
|
insilmaril@652
|
5068 |
}
|
insilmaril@652
|
5069 |
|