exports.cpp
author insilmaril
Mon, 11 Jul 2005 19:55:57 +0000
changeset 125 8cdfa8dda71e
parent 0 7a96bd401351
child 2 608f976aa7bb
child 57 d045ba89798e
child 131 16b250a57c17
permissions -rw-r--r--
Version 1.6.10: Updated documentation
insilmaril@0
     1
#include "exports.h"
insilmaril@0
     2
insilmaril@0
     3
#include "linkablemapobj.h"
insilmaril@0
     4
insilmaril@0
     5
insilmaril@0
     6
Export::Export()
insilmaril@0
     7
{
insilmaril@0
     8
	indentPerDepth="  ";
insilmaril@0
     9
}
insilmaril@0
    10
insilmaril@0
    11
bool Export::setOutputDir(QString dirname)
insilmaril@0
    12
{
insilmaril@0
    13
	outdir.setPath (dirname);
insilmaril@0
    14
	if ( outdir.exists() )
insilmaril@0
    15
	{
insilmaril@0
    16
		// FIXME
insilmaril@0
    17
		// ask for confirmation
insilmaril@0
    18
		// then delete outdir
insilmaril@0
    19
		return true;
insilmaril@0
    20
	} else
insilmaril@0
    21
	{
insilmaril@0
    22
		// try to create directory
insilmaril@0
    23
		//return outdir.mkdir (outdir.absPath());
insilmaril@0
    24
		// FIXME
insilmaril@0
    25
		return true;
insilmaril@0
    26
	}
insilmaril@0
    27
}
insilmaril@0
    28
insilmaril@0
    29
void Export::setPath (const QString &p)
insilmaril@0
    30
{
insilmaril@0
    31
	filepath=p;
insilmaril@0
    32
}
insilmaril@0
    33
insilmaril@0
    34
void Export::setMapCenter(MapCenterObj *mc)
insilmaril@0
    35
{
insilmaril@0
    36
	mapCenter=mc;
insilmaril@0
    37
}
insilmaril@0
    38
insilmaril@0
    39
void Export::exportMap()
insilmaril@0
    40
{
insilmaril@0
    41
	QFile file (filepath);
insilmaril@0
    42
	if ( !file.open( IO_WriteOnly ) )
insilmaril@0
    43
	{
insilmaril@0
    44
		// FIXME
insilmaril@0
    45
		cout << "Export::exportMap  couldn't open "<<filepath<<endl;
insilmaril@0
    46
		return;
insilmaril@0
    47
	}
insilmaril@0
    48
	QTextStream ts( &file );	// use LANG decoding here...
insilmaril@0
    49
insilmaril@0
    50
	// Main loop over all branches
insilmaril@0
    51
	QString s;
insilmaril@0
    52
	QString actIndent("");
insilmaril@0
    53
	int i;
insilmaril@0
    54
	BranchObj *bo;
insilmaril@0
    55
	bo=mapCenter->first();
insilmaril@0
    56
	while (bo) 
insilmaril@0
    57
	{
insilmaril@0
    58
		// Make indentstring
insilmaril@0
    59
		for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
insilmaril@0
    60
insilmaril@0
    61
		// Write heading
insilmaril@0
    62
		//	write (actIndent + getSectionString(bo) + bo->getHeading()+ "\n");
insilmaril@0
    63
		if (bo->getDepth()==1)
insilmaril@0
    64
			ts << (getSectionString(bo) + bo->getHeading()+ "\n");
insilmaril@0
    65
		else	
insilmaril@0
    66
			ts << (actIndent + " - " + bo->getHeading()+ "\n");
insilmaril@0
    67
		
insilmaril@0
    68
		// If necessary, write note
insilmaril@0
    69
		if (!bo->getNote().isEmpty())
insilmaril@0
    70
		{
insilmaril@0
    71
			ts << ("-------------------Begin of Note-----------------\n");
insilmaril@0
    72
			ts << (bo->getNote());
insilmaril@0
    73
			ts << ("\n");
insilmaril@0
    74
			ts << ("-------------------End of Note-------------------\n");
insilmaril@0
    75
		}
insilmaril@0
    76
		
insilmaril@0
    77
		bo=bo->next();
insilmaril@0
    78
		actIndent="";
insilmaril@0
    79
	}
insilmaril@0
    80
	file.close();
insilmaril@0
    81
}
insilmaril@0
    82
insilmaril@0
    83
QString Export::getSectionString(BranchObj *bostart)
insilmaril@0
    84
{
insilmaril@0
    85
	QString r;
insilmaril@0
    86
	BranchObj *bo=bostart;
insilmaril@0
    87
	int depth=bo->getDepth();
insilmaril@0
    88
	while (depth>0)
insilmaril@0
    89
	{
insilmaril@0
    90
		r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
insilmaril@0
    91
		bo=(BranchObj*)(bo->getParObj());
insilmaril@0
    92
		depth=bo->getDepth();
insilmaril@0
    93
	}	
insilmaril@0
    94
	if (r.isEmpty())
insilmaril@0
    95
		return r;
insilmaril@0
    96
	else	
insilmaril@0
    97
		return r + " ";
insilmaril@0
    98
}
insilmaril@0
    99
insilmaril@0
   100
void Export::exportAsHTML()
insilmaril@0
   101
{
insilmaril@0
   102
	// FIXME  just testing...
insilmaril@0
   103
	// Main loop over all branches
insilmaril@0
   104
	QString s;
insilmaril@0
   105
	QString actIndent("");
insilmaril@0
   106
	int i;
insilmaril@0
   107
	BranchObj *bo;
insilmaril@0
   108
	bo=mapCenter->first();
insilmaril@0
   109
	while (bo) 
insilmaril@0
   110
	{
insilmaril@0
   111
		// Make indentstring
insilmaril@0
   112
		for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
insilmaril@0
   113
insilmaril@0
   114
		// Write heading
insilmaril@0
   115
		write (actIndent + getSectionString(bo) + bo->getHeading()+ "\n");
insilmaril@0
   116
		
insilmaril@0
   117
		// If necessary, write note
insilmaril@0
   118
		if (!bo->getNote().isEmpty())
insilmaril@0
   119
		{
insilmaril@0
   120
			write (bo->getNote());
insilmaril@0
   121
		}
insilmaril@0
   122
		
insilmaril@0
   123
		bo=bo->next();
insilmaril@0
   124
		actIndent="";
insilmaril@0
   125
	}
insilmaril@0
   126
}
insilmaril@0
   127
insilmaril@0
   128
void Export::write(QString s)
insilmaril@0
   129
{
insilmaril@0
   130
	cout << s;
insilmaril@0
   131
}
insilmaril@0
   132