xml.cpp
changeset 425 7014be3ac7d0
parent 412 8059b6aa74d7
child 428 9ae68208e2ff
     1.1 --- a/xml.cpp	Fri Dec 29 13:52:17 2006 +0000
     1.2 +++ b/xml.cpp	Mon Feb 12 09:28:46 2007 +0000
     1.3 @@ -28,6 +28,8 @@
     1.4      errorProt = "";
     1.5      state = StateInit;
     1.6      laststate = StateInit;
     1.7 +	stateStack.clear();
     1.8 +	stateStack.append(StateInit);
     1.9      branchDepth=0;
    1.10  	htmldata="";
    1.11  	isVymPart=false;
    1.12 @@ -52,9 +54,10 @@
    1.13  	/* Testing
    1.14  	cout << "startElement <"<< eName.ascii()<<
    1.15  		">  state="<<state <<
    1.16 -		"  laststate="<<laststate<<
    1.17 +		"  laststate="<<stateStack.last()<<
    1.18  		"   loadMode="<<loadMode<<endl;
    1.19  	*/	
    1.20 +	stateStack.append (state);	
    1.21      if ( state == StateInit && (eName == "vymmap")  ) 
    1.22  	{
    1.23          state = StateMap;
    1.24 @@ -148,28 +151,33 @@
    1.25  				return false;
    1.26  		}
    1.27  		readBranchAttr (atts);
    1.28 -	} else if ( (eName == "standardflag" ||eName == "standardFlag") && state == StateMapCenter) 
    1.29 +	} else if ( 
    1.30 +		(eName == "standardflag" ||eName == "standardFlag") && 
    1.31 +		(state == StateMapCenter || state==StateBranch)) 
    1.32  	{
    1.33 -		state=StateMapCenterStandardFlag;
    1.34 -	} else if ( eName == "heading" && state == StateMapCenter) 
    1.35 +		state=StateStandardFlag;
    1.36 +	} else if ( eName == "heading" && (state == StateMapCenter||state==StateBranch)) 
    1.37  	{
    1.38 -		state=StateMapCenterHeading;
    1.39 +		laststate=state;
    1.40 +		state=StateHeading;
    1.41  		if (!atts.value( "textColor").isEmpty() ) 
    1.42  		{
    1.43  			col.setNamedColor(atts.value("textColor"));
    1.44  			lastBranch->setColor(col );
    1.45  		}	    
    1.46 -	} else if ( eName == "note" && state == StateMapCenter) 
    1.47 +	} else if ( eName == "note" && 
    1.48 +				(state == StateMapCenter ||state==StateBranch))
    1.49  	{	// only for backward compatibility (<1.4.6). Use htmlnote now.
    1.50 -		state=StateMapCenterNote;
    1.51 +		state=StateNote;
    1.52  		if (!readNoteAttr (atts) ) return false;
    1.53  	} else if ( eName == "htmlnote" && state == StateMapCenter) 
    1.54  	{
    1.55  		laststate=state;
    1.56  		state=StateHtmlNote;
    1.57 -    } else if ( eName == "floatimage" && state == StateMapCenter ) 
    1.58 +    } else if ( eName == "floatimage" && 
    1.59 +				(state == StateMapCenter ||state==StateBranch)) 
    1.60  	{
    1.61 -		state=StateMapCenterFloatImage;
    1.62 +		state=StateFloatImage;
    1.63          lastBranch->addFloatImage();
    1.64  		lastFloat=lastBranch->getLastFloatImage();
    1.65  		if (!readFloatImageAttr(atts)) return false;
    1.66 @@ -217,21 +225,6 @@
    1.67  		lastBranch->addBranch();
    1.68  		lastBranch=lastBranch->getLastBranch();
    1.69  		readBranchAttr (atts);
    1.70 -	} else if ( (eName=="standardflag" ||eName == "standardFlag") && state == StateBranch) 
    1.71 -	{
    1.72 -		state=StateBranchStandardFlag;
    1.73 -	} else if ( eName == "heading" && state == StateBranch) 
    1.74 -	{
    1.75 -		state=StateBranchHeading;
    1.76 -		if (!atts.value( "textColor").isEmpty() ) 
    1.77 -		{
    1.78 -			col.setNamedColor(atts.value("textColor"));
    1.79 -			lastBranch->setColor(col );
    1.80 -		}	    
    1.81 -    } else if ( eName == "note" && state == StateBranch) 
    1.82 -	{
    1.83 -        state=StateBranchNote;
    1.84 -		if (!readNoteAttr (atts) ) return false;
    1.85  	} else if ( eName == "htmlnote" && state == StateBranch) 
    1.86  	{
    1.87  		laststate=state;
    1.88 @@ -239,12 +232,11 @@
    1.89  		no.clear();
    1.90  		if (!atts.value( "fonthint").isEmpty() ) 
    1.91  			no.setFontHint(atts.value ("fonthint") );
    1.92 -    } else if ( eName == "floatimage" && state == StateBranch ) 
    1.93 +	} else if ( eName == "frame" && (state == StateBranch||state==StateMapCenter)) 
    1.94  	{
    1.95 -		state=StateBranchFloatImage;
    1.96 -        lastBranch->addFloatImage();
    1.97 -		lastFloat=lastBranch->getLastFloatImage();
    1.98 -		if (!readFloatImageAttr(atts)) return false;
    1.99 +		laststate=state;
   1.100 +		state=StateFrame;
   1.101 +		if (!readFrameAttr(atts)) return false;
   1.102      } else if ( eName == "xlink" && state == StateBranch ) 
   1.103  	{
   1.104  		state=StateBranchXLink;
   1.105 @@ -274,38 +266,18 @@
   1.106  
   1.107  bool mapBuilderHandler::endElement  ( const QString&, const QString&, const QString &eName)
   1.108  {
   1.109 -//	cout << "endElement </"<<eName<<">  state="<<state <<"  laststate="<<laststate<<endl;
   1.110 +	/* Testing
   1.111 +	cout << "endElement </" <<eName.ascii()
   1.112 +		<<">  state=" <<state 
   1.113 +		<<"  laststate=" <<laststate
   1.114 +		<<"  stateStack="<<stateStack.last() 
   1.115 +		<<endl;
   1.116 +	*/
   1.117      switch ( state ) 
   1.118  	{
   1.119 -        case StateMapSelect: state=StateMap;  return true;
   1.120 -        case StateMapSetting: state=StateMap;  return true;
   1.121 -        case StateMapCenter: state=StateMap;  return true;
   1.122 -        case StateMapCenterStandardFlag: state=StateMapCenter;  return true;
   1.123 -        case StateMapCenterHeading: state=StateMapCenter;  return true;
   1.124 -        case StateMapCenterNote: state=StateMapCenter;  return true;
   1.125 -        case StateMapCenterFloatImage: state=StateMapCenter;  return true;
   1.126 -        case StateFloatImage: state=StateMap; return true;
   1.127          case StateBranch: 
   1.128 -            if (branchDepth>1) 
   1.129 -			{
   1.130 -                branchDepth--;
   1.131 -                state=StateBranch;
   1.132 -            } else  
   1.133 -			{
   1.134 -                branchDepth=0;
   1.135 -				if (isVymPart)
   1.136 -					state=StateMap;
   1.137 -				else
   1.138 -					state=StateMapCenter;
   1.139 -            }   
   1.140  			lastBranch=(BranchObj*)(lastBranch->getParObj());
   1.141 -             return true;
   1.142 -        case StateBranchStandardFlag: state=StateBranch;  return true;
   1.143 -        case StateBranchHeading: state=StateBranch;  return true;
   1.144 -        case StateBranchNote: state=StateBranch; return true;
   1.145 -        case StateBranchFloatImage: state=StateBranch;  return true;
   1.146 -        case StateBranchXLink: state=StateBranch;  return true;
   1.147 -        case StateHtmlNote: state=laststate; return true;
   1.148 +            break;
   1.149          case StateHtml: 
   1.150  			htmldata+="</"+eName+">";
   1.151  			if (eName=="html")
   1.152 @@ -314,16 +286,13 @@
   1.153  				htmldata.replace ("<br></br>","<br />");
   1.154  				no.setNote (htmldata);
   1.155  				lastBranch->setNote (no);
   1.156 -				return true;
   1.157 -			}	else
   1.158 -			{
   1.159 -				return true;
   1.160  			}	
   1.161 -        case StateMap: state=StateInit;  return true;
   1.162 -        default : 
   1.163 -			// even for HTML includes, this should never be reached
   1.164 -			return false;
   1.165 -    }   
   1.166 +			break;
   1.167 +		default: 
   1.168 +			break;
   1.169 +    }  
   1.170 +	state=stateStack.takeLast();	
   1.171 +	return true;
   1.172  }
   1.173  
   1.174  bool mapBuilderHandler::characters   ( const QString& ch)
   1.175 @@ -343,30 +312,21 @@
   1.176  			break;
   1.177  		case StateMapSetting:break;
   1.178          case StateMapCenter: break;
   1.179 -        case StateMapCenterStandardFlag: 
   1.180 -            lastBranch->activateStandardFlag(ch_simplified); 
   1.181 -            break;
   1.182 -        case StateMapCenterHeading: 
   1.183 -            lastBranch->setHeading(ch_simplified); 
   1.184 -            break;
   1.185 -        case StateMapCenterNote:
   1.186 +        case StateNote:
   1.187  			lastBranch->setNote(ch_simplified);
   1.188  			break;
   1.189          case StateBranch: break;
   1.190 -        case StateBranchStandardFlag: 
   1.191 +        case StateStandardFlag: 
   1.192              lastBranch->activateStandardFlag(ch_simplified); 
   1.193              break;
   1.194 -        case StateBranchHeading: 
   1.195 -            lastBranch->setHeading(ch_simplified);
   1.196 -            break;
   1.197 -        case StateBranchNote: 
   1.198 -			lastBranch->setNote(ch_simplified);
   1.199 -			break;
   1.200 -        case StateBranchFloatImage: break;
   1.201 +        case StateFloatImage: break;
   1.202          case StateHtmlNote: break;
   1.203          case StateHtml:
   1.204  			htmldata+=ch_org;
   1.205  			break;
   1.206 +        case StateHeading: 
   1.207 +            lastBranch->setHeading(ch_simplified);
   1.208 +            break;
   1.209          default: 
   1.210  			return false;
   1.211      }
   1.212 @@ -452,6 +412,16 @@
   1.213  	return true;	
   1.214  }
   1.215  
   1.216 +bool mapBuilderHandler::readFrameAttr (const QXmlAttributes& a)
   1.217 +{
   1.218 +	if (lastOO)
   1.219 +	{
   1.220 +		if (!a.value( "frameType").isEmpty() ) 
   1.221 +			lastOO->setFrameType (a.value("frameType"));
   1.222 +	}		
   1.223 +	return true;
   1.224 +}
   1.225 +
   1.226  bool mapBuilderHandler::readOOAttr (const QXmlAttributes& a)
   1.227  {
   1.228  	if (lastOO)
   1.229 @@ -532,10 +502,7 @@
   1.230  	}		
   1.231  	if (!a.value( "fonthint").isEmpty() ) 
   1.232  		no.setFontHint(a.value ("fonthint") );
   1.233 -	if (state == StateMapCenterNote) 	
   1.234 -		mc->setNote(no);
   1.235 -	else
   1.236 -		lastBranch->setNote(no);
   1.237 +	lastBranch->setNote(no);
   1.238  	return true;
   1.239  }
   1.240