void ConnectionEditor::okClicked()
{
    MacroCommand *rmConn = 0, *addConn = 0;
    QString n = tr( "Connect/Disconnect signals and slots of '%1' and '%2'" ).arg( sender->name() ).arg( receiver->name() );
    QValueList<MetaDataBase::Connection>::Iterator cit;
    if ( !oldConnections.isEmpty() ) {
	QList<Command> commands;
	for ( cit = oldConnections.begin(); cit != oldConnections.end(); ++cit ) {
	    commands.append( new RemoveConnectionCommand( tr( "Remove connection" ),
							  formWindow, *cit ) );
	}
	rmConn = new MacroCommand( tr( "Remove connections" ), formWindow, commands );
    }

    if ( !connections.isEmpty() ) {
	QMap<QListViewItem*, Connection>::Iterator it = connections.begin();
	QList<Command> commands;
	for ( ; it != connections.end(); ++it ) {
	    Connection c = *it;
	    MetaDataBase::Connection conn;
	    conn.sender = sender;
	    conn.signal = c.signal;
	    conn.receiver = receiver;
	    conn.slot = c.slot;
	    commands.append( new AddConnectionCommand( tr( "Add connection" ),
						       formWindow, conn ) );
	}
	addConn = new MacroCommand( tr( "Add connections" ), formWindow, commands );
    }

    if ( rmConn || addConn ) {
	QList<Command> commands;
	if ( rmConn )
	    commands.append( rmConn );
	if ( addConn )
	    commands.append( addConn );
	MacroCommand *cmd = new MacroCommand( n, formWindow, commands );
	formWindow->commandHistory()->addCommand( cmd );
	cmd->execute();
    }

    accept();
}
示例#2
0
void WizardEditor::applyClicked()
{
    if ( commands.isEmpty() ) return;

    // schedule macro command
    MacroCommand* cmd = new MacroCommand( tr( "Edit Wizard Pages" ), formwindow, commands );
    formwindow->commandHistory()->addCommand( cmd );
    cmd->execute();

    // clear command list
    commands.clear();

    // fix wizard buttons
    for ( int i = 0; i < wizard->pageCount(); i++ ) {

	QWidget * page = wizard->page( i );
	if ( i == 0 ) { // first page

	    wizard->setBackEnabled( page, FALSE );
	    wizard->setNextEnabled( page, TRUE );
	}
	else if ( i == wizard->pageCount() - 1 ) { // last page

	    wizard->setBackEnabled( page, TRUE );
	    wizard->setNextEnabled( page, FALSE );
	}
	else {

	    wizard->setBackEnabled( page, TRUE );
	    wizard->setNextEnabled( page, TRUE );
	}
	wizard->setFinishEnabled( page, FALSE );
    }

    // update listbox
    int index = listBox->currentItem();
    fillListBox();
    listBox->setCurrentItem( index );

    // show current page
    wizard->showPage( wizard->page( 0 ) );
}
示例#3
0
void ConnectionEditor::okClicked()
{
  MacroCommand* rmConn = 0, *addConn = 0;
  QString n = i18n("Connect/Disconnect the signals and slots of '%1' and '%2'").arg(m_sender->name()).
      arg(m_receiver->name());
  QValueList <MetaDataBase::Connection>::Iterator cit;
  if (!m_oldConnections.isEmpty())
  {
    QPtrList <Command> commands;
    for (cit = m_oldConnections.begin(); cit != m_oldConnections.end(); ++cit)
      commands.append(new RemoveConnectionCommand(i18n("Remove Connection"), m_formWindow, *cit));
    rmConn = new MacroCommand(i18n("Remove Connections"), m_formWindow, commands);
  }
  if (!m_connections.isEmpty())
  {
    QMap<QListViewItem*, MetaDataBase::Connection>::Iterator it = m_connections.begin();
    QPtrList<Command> commands;
    for (; it != m_connections.end(); ++it)
    {
      MetaDataBase::Connection conn = *it;
      commands.append(new AddConnectionCommand(i18n("Add Connection"), m_formWindow, conn));
    }
    addConn = new MacroCommand(i18n("Add Connections"), m_formWindow, commands);
  }

  if (rmConn || addConn)
  {
    QPtrList < Command > commands;
    if (rmConn)
      commands.append(rmConn);
    if (addConn)
      commands.append(addConn);
    MacroCommand *cmd = new MacroCommand(n, m_formWindow, commands);
    m_formWindow->commandHistory()->addCommand(cmd);
    cmd->execute();
  }

  accept();
}
void EditFunctions::okClicked()
{
    QValueList<MetaDataBase::Function> functionList = MetaDataBase::functionList( formWindow );
    QString n = tr( "Add/Remove functions of '%1'" ).arg( formWindow->name() );
    QPtrList<Command> commands;
    QValueList<MetaDataBase::Function>::Iterator fit;
    if ( !functionList.isEmpty() ) {
        for ( fit = functionList.begin(); fit != functionList.end(); ++fit ) {
            bool functionFound = FALSE;
            QValueList<FunctItem>::Iterator it = functList.begin();
            for ( ; it != functList.end(); ++it ) {
                if ( MetaDataBase::normalizeFunction( (*it).oldName ) ==
                        MetaDataBase::normalizeFunction( (*fit).function ) ) {
                    functionFound = TRUE;
                    break;
                }
            }
            if ( !functionFound )
                commands.append( new RemoveFunctionCommand( tr( "Remove function" ),
                                 formWindow, (*fit).function, (*fit).specifier,
                                 (*fit).access,
                                 (*fit).type,
                                 formWindow->project()->language(),
                                 (*fit).returnType ) );
        }
    }

    bool invalidFunctions = FALSE;
    QValueList<FunctItem> invalidItems;

    if ( !functList.isEmpty() ) {
        QStrList lst;
        QValueList<FunctItem>::Iterator it = functList.begin();
        for ( ; it != functList.end(); ++it ) {
            MetaDataBase::Function function;
            function.function = (*it).newName;
            function.returnType = (*it).retTyp;
            function.specifier = (*it).spec;
            function.access = (*it).access;
            function.type = (*it).type;
            function.language = formWindow->project()->language();
            if ( function.returnType.isEmpty() )
                function.returnType = "void";
            QString s = function.function;
            s = s.simplifyWhiteSpace();
            bool startNum = s[ 0 ] >= '0' && s[ 0 ] <= '9';
            bool noParens = s.contains( '(' ) != 1 || s.contains( ')' ) != 1;
            bool illegalSpace = s.find( ' ' ) != -1 && s.find( ' ' ) < s.find( '(' );

            if ( startNum || noParens || illegalSpace || lst.find( function.function ) != -1 ) {
                invalidFunctions = TRUE;
                invalidItems.append( (*it) );
                continue;
            }
            bool functionFound = FALSE;
            for ( fit = functionList.begin(); fit != functionList.end(); ++fit ) {
                if ( MetaDataBase::normalizeFunction( (*fit).function ) ==
                        MetaDataBase::normalizeFunction( (*it).oldName ) ) {
                    functionFound = TRUE;
                    break;
                }
            }
            if ( !functionFound )
                commands.append( new AddFunctionCommand( tr( "Add function" ),
                                 formWindow, function.function, function.specifier,
                                 function.access,
                                 function.type, formWindow->project()->language(),
                                 function.returnType ) );
            if ( MetaDataBase::normalizeFunction( (*it).newName ) != MetaDataBase::normalizeFunction( (*it).oldName ) ||
                    (*it).spec != (*it).oldSpec || (*it).access != (*it).oldAccess || (*it).type != (*it).oldType ||
                    (*it).retTyp != (*it).oldRetTyp ) {
                QString normalizedOldName = MetaDataBase::normalizeFunction( (*it).oldName );
                if ((*it).oldName.endsWith("const")) // make sure we get the 'const' when we remove the old name
                    normalizedOldName += " const";
                commands.append( new ChangeFunctionAttribCommand( tr( "Change function attributes" ),
                                 formWindow, function, normalizedOldName,
                                 (*it).oldSpec, (*it).oldAccess, (*it).oldType,
                                 formWindow->project()->language(), (*it).oldRetTyp ) );
            }
            lst.append( function.function );
        }
    }

    if ( invalidFunctions ) {
        if ( QMessageBox::information( this, tr( "Edit Functions" ),
                                       tr( "Some syntactically incorrect functions have been defined.\n"
                                           "Remove these functions?" ), tr( "&Yes" ), tr( "&No" ) ) == 0 ) {
            QValueList<FunctItem>::Iterator it = functList.begin();
            while ( it != functList.end() ) {
                bool found = FALSE;
                QValueList<FunctItem>::Iterator vit = invalidItems.begin();
                for ( ; vit != invalidItems.end(); ++vit ) {
                    if ( (*vit).newName == (*it).newName ) {
                        invalidItems.remove( vit );
                        found = TRUE;
                        break;
                    }
                }
                if ( found ) {
                    int delId = (*it).id;
                    it = functList.remove( it );
                    QMap<QListViewItem*, int>::Iterator fit = functionIds.begin();
                    while ( fit != functionIds.end() ) {
                        if ( *fit == delId ) {
                            QListViewItem *litem = fit.key();
                            functionIds.remove( fit );
                            delete litem;
                            if ( functionListView->currentItem() )
                                functionListView->setSelected( functionListView->currentItem(), TRUE );
                            currentItemChanged( functionListView->currentItem() );
                            break;
                        }
                        ++fit;
                    }
                }
                else
                    ++it;
            }
            if ( functionListView->firstChild() ) {
                functionListView->setCurrentItem( functionListView->firstChild() );
                functionListView->setSelected( functionListView->firstChild(), TRUE );
            }
        }
        formWindow->mainWindow()->objectHierarchy()->updateFormDefinitionView();
        return;
    }

    if ( !commands.isEmpty() ) {
        MacroCommand *cmd = new MacroCommand( n, formWindow, commands );
        formWindow->commandHistory()->addCommand( cmd );
        cmd->execute();
    }

    formWindow->mainWindow()->objectHierarchy()->updateFormDefinitionView();
    accept();
}