⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqlformwizardimpl.cpp

📁 Linux下的基于X11的图形开发环境。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
 /************************************************************************ Copyright (C) 2000 Trolltech AS.  All rights reserved.**** This file is part of Qt Designer.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "sqlformwizardimpl.h"#include <qlistbox.h>#include <qwidget.h>#include <qcheckbox.h>#include <qlineedit.h>#include <qlabel.h>#include <qgroupbox.h>#include <qlayout.h>#include <qregexp.h>#include <qpushbutton.h>#include <qmultilineedit.h>#include <qlistview.h>#include <qfeatures.h>#include <qradiobutton.h>#include <qspinbox.h>#include <limits.h>#ifndef QT_NO_SQL#include <qdatatable.h>#include <qdatabrowser.h>#include <qsqleditorfactory.h>#include <qsqlindex.h>#include <qsqlcursor.h>#endifSqlFormWizard::SqlFormWizard( QUnknownInterface *aIface, QWidget *w,			      QWidget* parent, DesignerFormWindow *fw, const char* name, bool modal, WFlags fl )    : SqlFormWizardBase( parent, name, modal, fl ), widget( w ), appIface( aIface ),     mode( None ){    appIface->addRef();    formWindow = fw;    setFinishEnabled( finishPage, TRUE );    /* set mode of operation */    if ( widget->inherits( "QDataTable" ) ) {	setCaption( "Data Table Wizard" );	mode = Table;	setAppropriate( navigPage, FALSE );	setAppropriate( layoutPage, FALSE );	checkBoxAutoEdit->setChecked( FALSE );    } else if ( widget->inherits( "QDataBrowser" ) ) {	setCaption( "Data Browser Wizard" );	setAppropriate( tablePropertiesPage, FALSE );	mode = Browser;	checkBoxAutoEdit->setChecked( TRUE );    } else if ( widget->inherits( "QDataView" ) ) {	setCaption( "Data View Wizard" );	setAppropriate( tablePropertiesPage, FALSE );	setAppropriate( navigPage, FALSE );	setAppropriate( sqlPage, FALSE);	checkCreateFieldLayout->hide();	checkCreateButtonLayout->hide();	checkBoxAutoEdit->hide();	mode = View;    }    setupPage1();}SqlFormWizard::~SqlFormWizard(){    appIface->release();}void SqlFormWizard::connectionSelected( const QString &c ){    if ( !appIface )	return;    DesignerProject *proIface = (DesignerProject*)( (DesignerInterface*)appIface )->currentProject();    if ( !proIface )	return;    listBoxTable->clear();    QPtrList<DesignerDatabase> databases = proIface->databaseConnections();    for ( DesignerDatabase *d = databases.first(); d; d = databases.next() ) {	if ( d->name() == c  || ( d->name() == "(default)" || d->name().isEmpty() ) && c == "(default)")	    listBoxTable->insertStringList( d->tables() );    }    setNextEnabled( databasePage, ( listBoxTable->currentItem() >= 0 ) );}void SqlFormWizard::tableSelected( const QString & ){    if ( listBoxTable->currentItem() >= 0 ) {	autoPopulate( TRUE );	setNextEnabled( databasePage, TRUE );    } else {	setNextEnabled( databasePage, FALSE );    }}void SqlFormWizard::autoPopulate( bool populate ){    DesignerProject *proIface = (DesignerProject*)( (DesignerInterface*)appIface )->currentProject();    if ( !proIface )	return;    QPtrList<DesignerDatabase> databases = proIface->databaseConnections();    listBoxField->clear();    listBoxSortField->clear();    listBoxSelectedField->clear();    if ( populate ) {	for ( DesignerDatabase *d = databases.first(); d; d = databases.next() ) {	    if ( d->name() == listBoxConnection->currentText() ||		 ( ( d->name() == "(default)" || d->name().isEmpty() ) &&		 listBoxConnection->currentText() == "(default)" ) ) {		QStringList lst = *d->fields().find( listBoxTable->currentText() );		// remove primary index fields, if any		d->open( FALSE );#ifndef QT_NO_SQL		QSqlCursor tab( listBoxTable->currentText(), TRUE, d->connection() );		QSqlIndex pIdx = tab.primaryIndex();		for ( uint i = 0; i < pIdx.count(); i++ ) {		    listBoxField->insertItem( pIdx.field( i )->name() );		    lst.remove( pIdx.field( i )->name() );		}#endif		d->close();		listBoxSelectedField->insertStringList( lst );		listBoxSortField->insertStringList( lst );	    }	}    }}void SqlFormWizard::fieldDown(){    if ( listBoxSelectedField->currentItem() == -1 ||	 listBoxSelectedField->currentItem() == (int)listBoxSelectedField->count() - 1 ||	 listBoxSelectedField->count() < 2 )	return;    int index = listBoxSelectedField->currentItem() + 1;    QListBoxItem *i = listBoxSelectedField->item( listBoxSelectedField->currentItem() );    listBoxSelectedField->takeItem( i );    listBoxSelectedField->insertItem( i, index );    listBoxSelectedField->setCurrentItem( i );}void SqlFormWizard::fieldUp(){    if ( listBoxSelectedField->currentItem() <= 0 ||	 listBoxSelectedField->count() < 2 )	return;    int index = listBoxSelectedField->currentItem() - 1;    QListBoxItem *i = listBoxSelectedField->item( listBoxSelectedField->currentItem() );    listBoxSelectedField->takeItem( i );    listBoxSelectedField->insertItem( i, index );    listBoxSelectedField->setCurrentItem( i );}void SqlFormWizard::removeField(){    int i = listBoxSelectedField->currentItem();    if ( i != -1 ) {	listBoxField->insertItem( listBoxSelectedField->currentText() );	listBoxSelectedField->removeItem( i );    }}void SqlFormWizard::addField(){    int i = listBoxField->currentItem();    if ( i == -1 )	return;    QString f = listBoxField->currentText();    if ( !f.isEmpty() )	listBoxSelectedField->insertItem( f );    listBoxField->removeItem( i );}void SqlFormWizard::addSortField(){    int i = listBoxSortField->currentItem();    if ( i == -1 )	return;    QString f = listBoxSortField->currentText();    if ( !f.isEmpty() )	listBoxSortedField->insertItem( f + " ASC" );}void SqlFormWizard::reSortSortField(){    int i = listBoxSortedField->currentItem();    if ( i != -1 ) {	QString text = listBoxSortedField->currentText();	if ( text.mid( text.length() - 3 ) == "ASC" )	    text = text.mid( 0, text.length() - 3 ) + "DESC";	else if ( text.mid( text.length() - 4 ) == "DESC" )	    text = text.mid( 0, text.length() - 4 ) + "ASC";	listBoxSortedField->removeItem( i );	listBoxSortedField->insertItem( text, i );	listBoxSortedField->setCurrentItem( i );    }}void SqlFormWizard::removeSortField(){    int i = listBoxSortedField->currentItem();    if ( i != -1 ) {	listBoxSortedField->removeItem( i );    }}void SqlFormWizard::sortFieldUp(){    if ( listBoxSortedField->currentItem() <= 0 ||	 listBoxSortedField->count() < 2 )	return;    int index = listBoxSortedField->currentItem() - 1;    QListBoxItem *i = listBoxSortedField->item( listBoxSortedField->currentItem() );    listBoxSortedField->takeItem( i );    listBoxSortedField->insertItem( i, index );    listBoxSortedField->setCurrentItem( i );}void SqlFormWizard::sortFieldDown(){    if ( listBoxSortedField->currentItem() == -1 ||	 listBoxSortedField->currentItem() == (int)listBoxSortedField->count() - 1 ||	 listBoxSortedField->count() < 2 )	return;    int index = listBoxSortedField->currentItem() + 1;    QListBoxItem *i = listBoxSortedField->item( listBoxSortedField->currentItem() );    listBoxSortedField->takeItem( i );    listBoxSortedField->insertItem( i, index );    listBoxSortedField->setCurrentItem( i );}void SqlFormWizard::setupDatabaseConnections(){    if ( !appIface )	return;    DesignerProject *proIface = (DesignerProject*)( (DesignerInterface*)appIface )->currentProject();    if ( !proIface )	return;    proIface->setupDatabases();    raise();    setupPage1();}void SqlFormWizard::setupPage1(){    if ( !appIface )	return;    DesignerProject *proIface = (DesignerProject*)( (DesignerInterface*)appIface )->currentProject();    if ( !proIface )	return;    listBoxTable->clear();    listBoxConnection->clear();    QPtrList<DesignerDatabase> databases = proIface->databaseConnections();    QStringList lst;    for ( DesignerDatabase *d = databases.first(); d; d = databases.next() )	lst << d->name();    listBoxConnection->insertStringList( lst );    if ( lst.count() )	listBoxConnection->setCurrentItem( 0 );    setNextEnabled( databasePage, FALSE );}static QPushButton *create_widget( QWidget *parent, const char *name,				   const QString &txt, const QRect &r, DesignerFormWindow *fw ){    QPushButton *pb = (QPushButton*)fw->create( "QPushButton", parent, name );    pb->setText( txt );    pb->setGeometry( r );    fw->setPropertyChanged( pb, "text", TRUE );    fw->setPropertyChanged( pb, "geometry", TRUE );    return pb;}void SqlFormWizard::accept(){    if ( !appIface || mode == None )	return;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -