author | insilmaril |
Fri Aug 19 07:42:32 2005 +0000 (2005-08-19) | |
changeset 157 | 677e702c5863 |
parent 0 | 7a96bd401351 |
child 160 | 72cc3873306a |
permissions | -rw-r--r-- |
insilmaril@0 | 1 |
#include "exports.h" |
insilmaril@0 | 2 |
|
insilmaril@131 | 3 |
#include <qregexp.h> |
insilmaril@131 | 4 |
|
insilmaril@0 | 5 |
#include "linkablemapobj.h" |
insilmaril@131 | 6 |
#include "texteditor.h" |
insilmaril@0 | 7 |
|
insilmaril@0 | 8 |
|
insilmaril@0 | 9 |
Export::Export() |
insilmaril@0 | 10 |
{ |
insilmaril@0 | 11 |
indentPerDepth=" "; |
insilmaril@0 | 12 |
} |
insilmaril@0 | 13 |
|
insilmaril@0 | 14 |
void Export::setPath (const QString &p) |
insilmaril@0 | 15 |
{ |
insilmaril@0 | 16 |
filepath=p; |
insilmaril@0 | 17 |
} |
insilmaril@0 | 18 |
|
insilmaril@0 | 19 |
void Export::setMapCenter(MapCenterObj *mc) |
insilmaril@0 | 20 |
{ |
insilmaril@0 | 21 |
mapCenter=mc; |
insilmaril@0 | 22 |
} |
insilmaril@0 | 23 |
|
insilmaril@0 | 24 |
void Export::exportMap() |
insilmaril@0 | 25 |
{ |
insilmaril@0 | 26 |
QFile file (filepath); |
insilmaril@0 | 27 |
if ( !file.open( IO_WriteOnly ) ) |
insilmaril@0 | 28 |
{ |
insilmaril@131 | 29 |
// FIXME experimental, testing |
insilmaril@0 | 30 |
cout << "Export::exportMap couldn't open "<<filepath<<endl; |
insilmaril@0 | 31 |
return; |
insilmaril@0 | 32 |
} |
insilmaril@0 | 33 |
QTextStream ts( &file ); // use LANG decoding here... |
insilmaril@0 | 34 |
|
insilmaril@0 | 35 |
// Main loop over all branches |
insilmaril@0 | 36 |
QString s; |
insilmaril@0 | 37 |
QString actIndent(""); |
insilmaril@131 | 38 |
uint i; |
insilmaril@0 | 39 |
BranchObj *bo; |
insilmaril@0 | 40 |
bo=mapCenter->first(); |
insilmaril@0 | 41 |
while (bo) |
insilmaril@0 | 42 |
{ |
insilmaril@0 | 43 |
// Make indentstring |
insilmaril@0 | 44 |
for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth; |
insilmaril@0 | 45 |
|
insilmaril@0 | 46 |
// Write heading |
insilmaril@0 | 47 |
// write (actIndent + getSectionString(bo) + bo->getHeading()+ "\n"); |
insilmaril@131 | 48 |
if (bo->getDepth()==0) |
insilmaril@131 | 49 |
{ |
insilmaril@131 | 50 |
ts << (bo->getHeading()+ "\n"); |
insilmaril@131 | 51 |
for (i=0;i<bo->getHeading().length();i++) ts<<"="; |
insilmaril@131 | 52 |
ts << "\n"; |
insilmaril@131 | 53 |
} else if (bo->getDepth()==1) |
insilmaril@131 | 54 |
ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n"); |
insilmaril@131 | 55 |
else if (bo->getDepth()==2) |
insilmaril@131 | 56 |
ts << (actIndent + " o " + bo->getHeading()+ "\n"); |
insilmaril@0 | 57 |
else |
insilmaril@0 | 58 |
ts << (actIndent + " - " + bo->getHeading()+ "\n"); |
insilmaril@0 | 59 |
|
insilmaril@0 | 60 |
// If necessary, write note |
insilmaril@0 | 61 |
if (!bo->getNote().isEmpty()) |
insilmaril@0 | 62 |
{ |
insilmaril@131 | 63 |
s =textConvertToASCII(bo->getNote()); |
insilmaril@131 | 64 |
s=s.replace ("\n","\n"+actIndent); |
insilmaril@131 | 65 |
ts << (s+"\n\n"); |
insilmaril@0 | 66 |
} |
insilmaril@0 | 67 |
|
insilmaril@0 | 68 |
bo=bo->next(); |
insilmaril@0 | 69 |
actIndent=""; |
insilmaril@0 | 70 |
} |
insilmaril@0 | 71 |
file.close(); |
insilmaril@0 | 72 |
} |
insilmaril@0 | 73 |
|
insilmaril@0 | 74 |
QString Export::getSectionString(BranchObj *bostart) |
insilmaril@0 | 75 |
{ |
insilmaril@0 | 76 |
QString r; |
insilmaril@0 | 77 |
BranchObj *bo=bostart; |
insilmaril@0 | 78 |
int depth=bo->getDepth(); |
insilmaril@0 | 79 |
while (depth>0) |
insilmaril@0 | 80 |
{ |
insilmaril@0 | 81 |
r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r; |
insilmaril@0 | 82 |
bo=(BranchObj*)(bo->getParObj()); |
insilmaril@0 | 83 |
depth=bo->getDepth(); |
insilmaril@0 | 84 |
} |
insilmaril@0 | 85 |
if (r.isEmpty()) |
insilmaril@0 | 86 |
return r; |
insilmaril@0 | 87 |
else |
insilmaril@0 | 88 |
return r + " "; |
insilmaril@0 | 89 |
} |
insilmaril@0 | 90 |