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