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