exports.cpp
author insilmaril
Mon, 05 Sep 2005 16:48:10 +0000
changeset 161 88efbd21cff1
parent 160 72cc3873306a
child 163 30b22f7bd009
permissions -rw-r--r--
copied vym-48x48.png to vym.png
     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 	int i;
    39 	uint j;
    40 	BranchObj *bo;
    41 	bo=mapCenter->first();
    42 	while (bo) 
    43 	{
    44 		// Make indentstring
    45 		for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
    46 
    47 		// Write heading
    48 		//	write (actIndent + getSectionString(bo) + bo->getHeading()+ "\n");
    49 		if (bo->getDepth()==0)
    50 		{
    51 			ts << (bo->getHeading()+ "\n");
    52 			for (j=0;j<bo->getHeading().length();j++) ts<<"=";
    53 			ts << "\n";
    54 		} else 	if (bo->getDepth()==1)
    55 			ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
    56 		else	if (bo->getDepth()==2)
    57 			ts << (actIndent + " o " + bo->getHeading()+ "\n");
    58 		else	
    59 			ts << (actIndent + " - " + bo->getHeading()+ "\n");
    60 		
    61 		// If necessary, write note
    62 		if (!bo->getNote().isEmpty())
    63 		{
    64 			s =textConvertToASCII(bo->getNote());
    65 			s=s.replace ("\n","\n"+actIndent);
    66 			ts << (s+"\n\n");
    67 		}
    68 		
    69 		bo=bo->next();
    70 		actIndent="";
    71 	}
    72 	file.close();
    73 }
    74 
    75 QString Export::getSectionString(BranchObj *bostart)
    76 {
    77 	QString r;
    78 	BranchObj *bo=bostart;
    79 	int depth=bo->getDepth();
    80 	while (depth>0)
    81 	{
    82 		r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
    83 		bo=(BranchObj*)(bo->getParObj());
    84 		depth=bo->getDepth();
    85 	}	
    86 	if (r.isEmpty())
    87 		return r;
    88 	else	
    89 		return r + " ";
    90 }
    91