Пример #1
0
// A save or restore has been requested (Probably by QEGui itself)
void saveRestoreManager::saveRestore( SaveRestoreSignal::saveRestoreOptions option )
{
    PersistanceManager* pm = profile.getPersistanceManager();

    switch( option )
    {
        // Save the application data
        case SaveRestoreSignal::SAVE:
            {
                // Start with the top level element - the QEGui application
                PMElement appElement =  pm->addNamedConfiguration( SAVERESTORE_NAME );

                // Note the number of main windows. This will determine how many main windows are expected on restore
                appElement.addValue( "MainWindows", app->getMainWindowCount() );

                // Note the current user level
                userLevelTypes meta;
                appElement.addValue ("UserLevel", QEUtilities::enumToString( meta, "userLevels", getUserLevel() ));
            }
            break;

        // First restore phase.
        // This application will create the main windows and the GUIs they contain
        case SaveRestoreSignal::RESTORE_APPLICATION:
            {
                // Get the data for this application
                PMElement QEGuiData = pm->getNamedConfiguration( SAVERESTORE_NAME );

                // If none, do nothing
                if( QEGuiData.isNull() )
                {
                    return;
                }

                // Note the current user level
                QString levelString;
                QEGuiData.getValue( "UserLevel", levelString );
                userLevelTypes meta;
                userLevelTypes::userLevels levelInt;
                bool ok;
                levelInt = (userLevelTypes::userLevels)QEUtilities::stringToEnum( meta, "userLevels", levelString, &ok );
                if( ok )
                {
                    setUserLevel( levelInt );
                }

                // Get the number of expected main windows
                int numMainWindows = 0;
                QEGuiData.getValue( "MainWindows", numMainWindows );

                // Create the main windows. They will restore themselves
                setupProfile( NULL, app->getParams()->pathList, "", app->getParams()->substitutions );
                for( int i = 0; i < numMainWindows; i++ )
                {
                    MainWindow* mw = new MainWindow( app, "", "", "", QEFormMapper::nullHandle(), false );
                    mw->show();
                }

                releaseProfile();
            }
            break;

        // Second resore phase.
        // This application has done it's work. The widgets that have been created will be able to act on the second phase
        case SaveRestoreSignal::RESTORE_QEFRAMEWORK:
            break;

    }

}
/*
    Button click event.
*/
void QEGenericButton::userClicked( bool checked )
{
    // Do nothing if nothing to do. (no point asking for confirmation or password)
    // Then keep doing nothing if user confirmation required but not given, or password required but not given
    if(( !writeOnClick && programLauncher.getProgram().isEmpty() && guiName.isEmpty() ) ||  !confirmAction() || !checkPassword() )
        return;

    // Get the variable to write to
    QEString *qca = (QEString*)getQcaItem(0);

    // If the object is set up to write when the user clicks the button
    // emit a signal
    // Also, if a QCa object is present (if there is a variable to write to)
    // then write the value
    if( writeOnClick )
    {
        // Determine the string to write
        QString writeText;
        if( !checked )
        {
            writeText = clickText;
        }
        else
        {
            writeText = clickCheckedText;
        }

        writeText = substituteThis( writeText );

        // Emit a 'clicked' signal
        emitClicked( writeText.toInt() );

        // Write to the variable if present
        if( qca )
        {
            QString error;
            if( !qca->writeString( writeText, error ) )
            {
                QMessageBox::warning( (QWidget*)getButtonQObject(), QString( "Write failed" ), error, QMessageBox::Cancel );
            }
        }
    }

    // If there is a command to run, run it, with substitutions applied to the command and arguments
    programLauncher.launch( (VariableNameManager*)this, getButtonQObject() );

    // If a new GUI is required, start it
    if( !guiName.isEmpty() )
    {

        // Publish the profile this button recieved
        publishOwnProfile();

        // Extend any variable name substitutions with this button's substitutions
        // Like most other macro substitutions, the substitutions already present take precedence.
        addMacroSubstitutions( getVariableNameSubstitutions() );

        // Extend any variable name substitutions with this button's priority substitutions
        // Unlike most other macro substitutions, these macro substitutions take precedence over
        // substitutions already present.
        addPriorityMacroSubstitutions( prioritySubstitutions );

        // Start the GUI
        emitNewGui( QEActionRequests( substituteThis( guiName ), customisationName, creationOption ) );

        // Remove this button's priority macro substitutions now all its children are created
        removePriorityMacroSubstitutions();

        // Remove this button's normal macro substitutions now all its children are created
        removeMacroSubstitutions();

        // Release the profile now all QE widgets have been created
        releaseProfile();
    }
}