Xorph


Navigation
  • about
  • features
  • examples
  • requirements
  • download
  • installation
  • contact
  • SourceForge

  • SourceForge Logo

    example :: simple dialog


    This example uses only a few options, but it is sufficient to illustrate the basic concepts of of Xorph. The source file looks like this:

    Xorph source code

    <?xml version="1.0" encoding="UTF-8"?>
    <xorph:environment name="SimpleDialogEnvironment" 
                       prefix="XorphSimpleDialogEnvironment" 
                       xmlns:xorph="http://xorph.sourceforge.net/" 
                       xmlns:x0="http://www.w3.org/2001/XMLSchema">
        <options>
            <group label="Player Information" name="PlayerInfo">
                <option label="Player Name" name="Name">
                    <text case="any" defaultValue="Player 1"/>
                    <description>Enter your name here.</description>
                </option>
                <option label="Password" name="Password">
                    <text case="any" password="true"/>
                    <description>Please enter your game password here.</description>
                </option>
                <option label="Skill Level" name="Level">
                    <selectNumeric standardDisplay="radiobuttons" defaultValue="2">
                        <values>
                            <value label="Beginner" value="1"/>
                            <value label="Intermediate" value="2"/>
                            <value label="Expert" value="3"/>
                        </values>
                    </selectNumeric>
                    <description>Select your experience level.</description>
                </option>
            </group>
        </options>
        <interface name="Options" title="Game Options">
            <simpleDialog>
                <text>Please enter the following information in order to start the game.</text>
                <includeGroup name="PlayerInfo" withFrame="false"/>
            </simpleDialog>
        </interface>
    </xorph:environment>

    If you prefer using some graphic XML editor, you might want to try XAmple. The following screenshot shows how the definition might look like.

    SimpleDialog source in XAmple XML Editor

    Generating the code

    Now, we need to generate our X++ code. This is trivial:

    vwegert@sinclair SimpleDialog $ Xorph SimpleDialog.xorph
    Xorph 1.0 - see http://xorph.sourceforge.net for additional information
    Compiling SimpleDialog.xorph...
      Validating...
    Unimplemented block at xmlschemastypes.c:2213
    SimpleDialog.xorph validates
      Generating header file...
      Generating C++ source file...
    

    Setting up a test frame

    Now we're ready to use the generated classes. Here's a simple test frame.

    #include <qapplication.h>
    #include "SimpleDialog.h"
    
    int main( int argc, char ** argv )
    {
    	QApplication app( argc, argv );
    	SimpleDialogEnvironment * env;
    	
    	env = new SimpleDialogEnvironment( "Volker Wegert", "XorphSimpleDialogDemo" );
    	
    	env->execOptions();
    	
    	qDebug("Player name is " + env->getName() );
    	qDebug("Password is " + env->getPassword() );
    	qDebug("Level is " + QString::number( env->getLevel() ) );
    	
    	delete(env);
    }
    

    Screenshot

    Running this test frame display the following dialog.

    generated dialog window

    After the window is closed, the program prints out the following debugging information:

    Player name is Player 1
    Password is Hugo
    Level is 2
    

    © 2005 Volker Wegert