exports.cpp
branchvendor
changeset 0 7a96bd401351
child 2 608f976aa7bb
child 57 d045ba89798e
child 131 16b250a57c17
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/exports.cpp	Sun Jan 30 12:58:47 2005 +0000
     1.3 @@ -0,0 +1,132 @@
     1.4 +#include "exports.h"
     1.5 +
     1.6 +#include "linkablemapobj.h"
     1.7 +
     1.8 +
     1.9 +Export::Export()
    1.10 +{
    1.11 +	indentPerDepth="  ";
    1.12 +}
    1.13 +
    1.14 +bool Export::setOutputDir(QString dirname)
    1.15 +{
    1.16 +	outdir.setPath (dirname);
    1.17 +	if ( outdir.exists() )
    1.18 +	{
    1.19 +		// FIXME
    1.20 +		// ask for confirmation
    1.21 +		// then delete outdir
    1.22 +		return true;
    1.23 +	} else
    1.24 +	{
    1.25 +		// try to create directory
    1.26 +		//return outdir.mkdir (outdir.absPath());
    1.27 +		// FIXME
    1.28 +		return true;
    1.29 +	}
    1.30 +}
    1.31 +
    1.32 +void Export::setPath (const QString &p)
    1.33 +{
    1.34 +	filepath=p;
    1.35 +}
    1.36 +
    1.37 +void Export::setMapCenter(MapCenterObj *mc)
    1.38 +{
    1.39 +	mapCenter=mc;
    1.40 +}
    1.41 +
    1.42 +void Export::exportMap()
    1.43 +{
    1.44 +	QFile file (filepath);
    1.45 +	if ( !file.open( IO_WriteOnly ) )
    1.46 +	{
    1.47 +		// FIXME
    1.48 +		cout << "Export::exportMap  couldn't open "<<filepath<<endl;
    1.49 +		return;
    1.50 +	}
    1.51 +	QTextStream ts( &file );	// use LANG decoding here...
    1.52 +
    1.53 +	// Main loop over all branches
    1.54 +	QString s;
    1.55 +	QString actIndent("");
    1.56 +	int i;
    1.57 +	BranchObj *bo;
    1.58 +	bo=mapCenter->first();
    1.59 +	while (bo) 
    1.60 +	{
    1.61 +		// Make indentstring
    1.62 +		for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
    1.63 +
    1.64 +		// Write heading
    1.65 +		//	write (actIndent + getSectionString(bo) + bo->getHeading()+ "\n");
    1.66 +		if (bo->getDepth()==1)
    1.67 +			ts << (getSectionString(bo) + bo->getHeading()+ "\n");
    1.68 +		else	
    1.69 +			ts << (actIndent + " - " + bo->getHeading()+ "\n");
    1.70 +		
    1.71 +		// If necessary, write note
    1.72 +		if (!bo->getNote().isEmpty())
    1.73 +		{
    1.74 +			ts << ("-------------------Begin of Note-----------------\n");
    1.75 +			ts << (bo->getNote());
    1.76 +			ts << ("\n");
    1.77 +			ts << ("-------------------End of Note-------------------\n");
    1.78 +		}
    1.79 +		
    1.80 +		bo=bo->next();
    1.81 +		actIndent="";
    1.82 +	}
    1.83 +	file.close();
    1.84 +}
    1.85 +
    1.86 +QString Export::getSectionString(BranchObj *bostart)
    1.87 +{
    1.88 +	QString r;
    1.89 +	BranchObj *bo=bostart;
    1.90 +	int depth=bo->getDepth();
    1.91 +	while (depth>0)
    1.92 +	{
    1.93 +		r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
    1.94 +		bo=(BranchObj*)(bo->getParObj());
    1.95 +		depth=bo->getDepth();
    1.96 +	}	
    1.97 +	if (r.isEmpty())
    1.98 +		return r;
    1.99 +	else	
   1.100 +		return r + " ";
   1.101 +}
   1.102 +
   1.103 +void Export::exportAsHTML()
   1.104 +{
   1.105 +	// FIXME  just testing...
   1.106 +	// Main loop over all branches
   1.107 +	QString s;
   1.108 +	QString actIndent("");
   1.109 +	int i;
   1.110 +	BranchObj *bo;
   1.111 +	bo=mapCenter->first();
   1.112 +	while (bo) 
   1.113 +	{
   1.114 +		// Make indentstring
   1.115 +		for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
   1.116 +
   1.117 +		// Write heading
   1.118 +		write (actIndent + getSectionString(bo) + bo->getHeading()+ "\n");
   1.119 +		
   1.120 +		// If necessary, write note
   1.121 +		if (!bo->getNote().isEmpty())
   1.122 +		{
   1.123 +			write (bo->getNote());
   1.124 +		}
   1.125 +		
   1.126 +		bo=bo->next();
   1.127 +		actIndent="";
   1.128 +	}
   1.129 +}
   1.130 +
   1.131 +void Export::write(QString s)
   1.132 +{
   1.133 +	cout << s;
   1.134 +}
   1.135 +