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