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

📄 q3datatable.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*!    Protected virtual function which is called when an error \a e has    occurred on the current cursor(). The default implementation    displays a warning message to the user with information about the    error.*/void Q3DataTable::handleError( const QSqlError& e ){    d->dat.handleError( this, e );}/*! \reimp  */void Q3DataTable::keyPressEvent( QKeyEvent* e ){    switch( e->key() ) {    case Qt::Key_Left:    case Qt::Key_Right:    case Qt::Key_Up:    case Qt::Key_Down:    case Qt::Key_Prior:    case Qt::Key_Next:    case Qt::Key_Home:    case Qt::Key_End:    case Qt::Key_F2:    case Qt::Key_Enter: case Qt::Key_Return:    case Qt::Key_Tab: case Qt::Key_BackTab:	Q3Table::keyPressEvent( e );    default:	return;    }}/*!  \reimp*/void Q3DataTable::resizeData ( int ){}/*!  \reimp*/Q3TableItem * Q3DataTable::item ( int, int ) const{    return 0;}/*!  \reimp*/void Q3DataTable::setItem ( int , int , Q3TableItem * ){}/*!  \reimp*/void Q3DataTable::clearCell ( int , int ){}/*!  \reimp*/void Q3DataTable::setPixmap ( int , int , const QPixmap &  ){}/*! \reimp */void Q3DataTable::takeItem ( Q3TableItem * ){}/*!    Installs a new SQL editor factory \a f. This enables the user to    create and instantiate their own editors for use in cell editing.    Note that Q3DataTable takes ownership of this pointer, and will    delete it when it is no longer needed or when    installEditorFactory() is called again.    \sa Q3SqlEditorFactory*/void Q3DataTable::installEditorFactory( Q3SqlEditorFactory * f ){    if( f ) {	delete d->editorFactory;	d->editorFactory = f;    }}/*!    Installs a new property map \a m. This enables the user to create    and instantiate their own property maps for use in cell editing.    Note that Q3DataTable takes ownership of this pointer, and will    delete it when it is no longer needed or when installPropertMap()    is called again.    \sa Q3SqlPropertyMap*/void Q3DataTable::installPropertyMap( Q3SqlPropertyMap* m ){    if ( m ) {	delete d->propertyMap;	d->propertyMap = m;    }}/*!  \internal  Sets the current selection to \a row, \a col.*/void Q3DataTable::setCurrentSelection( int row, int ){    if ( !sqlCursor() )	return;    if ( row == d->lastAt )	return;    if ( !sqlCursor()->seek( row ) )	return;    d->lastAt = row;    emit currentChanged( sqlCursor() );}void Q3DataTable::updateCurrentSelection(){    setCurrentSelection( currentRow(), -1 );}/*!    Returns the currently selected record, or 0 if there is no current    selection. The table owns the pointer, so do \e not delete it or    otherwise modify it or the cursor it points to.*/QSqlRecord* Q3DataTable::currentRecord() const{    if ( !sqlCursor() || currentRow() < 0 )	return 0;    if ( !sqlCursor()->seek( currentRow() ) )	return 0;    return sqlCursor();}/*!    Sorts column \a col in ascending order.    \sa setSorting()*/void Q3DataTable::sortAscending( int col ){    sortColumn( col, true );}/*!    Sorts column \a col in descending order.    \sa setSorting()*/void Q3DataTable::sortDescending( int col ){    sortColumn( col, false );}/*!    \fn void Q3DataTable::refresh( Refresh mode )    Refreshes the table. If there is no currently defined cursor (see    setSqlCursor()), nothing happens. The \a mode parameter determines    which type of refresh will take place.    \sa Refresh setSqlCursor() addColumn()*/void Q3DataTable::refresh( Q3DataTable::Refresh mode ){    Q3SqlCursor* cur = sqlCursor();    if ( !cur )	return;    bool refreshData = ( (mode & RefreshData) == RefreshData );    bool refreshCol = ( (mode & RefreshColumns) == RefreshColumns );    if ( ( (mode & RefreshAll) == RefreshAll ) ) {	refreshData = true;	refreshCol = true;    }    if ( !refreshCol && d->fld.count() && numCols() == 0 )	refreshCol = true;    viewport()->setUpdatesEnabled( false );    d->haveAllRows = false;    if ( refreshData ) {	if ( !d->cur.refresh() && d->cur.cursor() ) {	    handleError( d->cur.cursor()->lastError() );	}	d->lastAt = -1;    }    if ( refreshCol ) {	setNumCols( 0 );	d->colIndex.clear();	if ( d->fld.count() ) {	    const QSqlField* field = 0;	    int i;	    int fpos = -1;	    for ( i = 0; i < (int)d->fld.count(); ++i ) {		if ( cur->fieldPtr( i ) && cur->fieldPtr( i )->name() == d->fld[ i ] )		    // if there is a field with the desired name on the desired position		    // then we take that		    fpos = i;		else		    // otherwise we take the first field that matches the desired name		    fpos = cur->position( d->fld[ i ] );		field = cur->fieldPtr( fpos );		if ( field && ( cur->isGenerated( fpos ) ||				cur->isCalculated( field->name() ) ) )		{		    setNumCols( numCols() + 1 );		    d->colIndex.append( fpos );		    setColumnReadOnly( numCols()-1, field->isReadOnly() || isColumnReadOnly( numCols()-1 ) );		    horizontalHeader()->setLabel( numCols()-1, d->fldIcon[ i ], d->fldLabel[ i ] );		    if ( d->fldHidden[ i ] ) {			Q3Table::showColumn( i ); // ugly but necessary			Q3Table::hideColumn( i );		    } else {			Q3Table::showColumn( i );		    }		    if ( d->fldWidth[ i ] > -1 )			Q3Table::setColumnWidth( i, d->fldWidth[i] );		}	    }	}    }    viewport()->setUpdatesEnabled( true );    viewport()->repaint( false );    horizontalHeader()->repaint();    verticalHeader()->repaint();    setSize( cur );    // keep others aware    if ( d->lastAt == -1 ) 	setCurrentSelection( -1, -1 );    else if ( d->lastAt != currentRow() )	setCurrentSelection( currentRow(), currentColumn() );    if ( cur->isValid() )	emit currentChanged( sqlCursor() );}/*!    Refreshes the table. The cursor is refreshed using the current    filter, the current sort, and the currently defined columns.    Equivalent to calling refresh( Q3DataTable::RefreshData ).*/void Q3DataTable::refresh(){    refresh( RefreshData );}/*!    \internal    Selects the record in the table using the current cursor edit    buffer and the fields specified by the index \a idx. If \a atHint    is specified, it will be used as a hint about where to begin    searching.*/bool Q3DataTable::findBuffer( const QSqlIndex& idx, int atHint ){    Q3SqlCursor* cur = sqlCursor();    if ( !cur )	return false;    bool found = d->cur.findBuffer( idx, atHint );    if ( found )	setCurrentCell( cur->at(), currentColumn() );    return found;}/*! \internal    Returns the string representation of a database field.*/QString Q3DataTable::fieldToString( const QSqlField * field ){    QString text;    if ( field->isNull() ) {	text = nullText();    } else {	QVariant val = field->value();	switch ( val.type() ) {	    case QVariant::Bool:		text = val.toBool() ? d->trueTxt : d->falseTxt;		break;	    case QVariant::Date:		text = val.toDate().toString( d->datefmt );		break;	    case QVariant::Time:		text = val.toTime().toString( d->datefmt );		break;	    case QVariant::DateTime:		text = val.toDateTime().toString( d->datefmt );		break;	    default:		text = val.toString();		break;	}    }    return text;}/*!    \reimp*/void Q3DataTable::swapColumns( int col1, int col2, bool ){    QString fld = d->fld[ col1 ];    QString fldLabel = d->fldLabel[ col1 ];    QIconSet fldIcon = d->fldIcon[ col1 ];    int fldWidth = d->fldWidth[ col1 ];    d->fld[ col1 ] = d->fld[ col2 ];    d->fldLabel[ col1 ] = d->fldLabel[ col2 ];    d->fldIcon[ col1 ] = d->fldIcon[ col2 ];    d->fldWidth[ col1 ] = d->fldWidth[ col2 ];    d->fld[ col2 ] = fld;    d->fldLabel[ col2 ] = fldLabel;    d->fldIcon[ col2 ] = fldIcon;    d->fldWidth[ col2 ] = fldWidth;    int colIndex = d->colIndex[ col1 ];    d->colIndex[ col1 ] = d->colIndex[ col2 ];    d->colIndex[ col2 ] = colIndex;}/*!    \reimp*/void Q3DataTable::drawContents( QPainter * p, int cx, int cy, int cw, int ch ){    Q3Table::drawContents( p, cx, cy, cw, ch );    if ( sqlCursor() && currentRow() >= 0 )	sqlCursor()->seek( currentRow() );}/*!    \reimp */void Q3DataTable::drawContents(QPainter *){}/*!    \reimp*/void Q3DataTable::hideColumn( int col ){    d->fldHidden[col] = true;    refresh( RefreshColumns );}/*!    \reimp*/void Q3DataTable::showColumn( int col ){    d->fldHidden[col] = false;    refresh( RefreshColumns );}/*!  \reimp*/void  Q3DataTable::selectRow(int row){    setCurrentCell(row, currentColumn());}/*!    \fn void Q3DataTable::currentChanged( QSqlRecord* record )    This signal is emitted whenever a new row is selected in the    table. The \a record parameter points to the contents of the newly    selected record.*//*!    \fn void Q3DataTable::primeInsert( QSqlRecord* buf )    This signal is emitted after the cursor is primed for insert by    the table, when an insert action is beginning on the table. The \a    buf parameter points to the edit buffer being inserted. Connect to    this signal in order to, for example, prime the record buffer with    default data values.*//*!    \fn void Q3DataTable::primeUpdate( QSqlRecord* buf )    This signal is emitted after the cursor is primed for update by    the table, when an update action is beginning on the table. The \a    buf parameter points to the edit buffer being updated. Connect to    this signal in order to, for example, provide some visual feedback    that the user is in 'edit mode'.*//*!    \fn void Q3DataTable::primeDelete( QSqlRecord* buf )    This signal is emitted after the cursor is primed for delete by    the table, when a delete action is beginning on the table. The \a    buf parameter points to the edit buffer being deleted. Connect to    this signal in order to, for example, record auditing information    on deletions.*//*!    \fn void Q3DataTable::beforeInsert( QSqlRecord* buf )    This signal is emitted just before the cursor's edit buffer is    inserted into the database. The \a buf parameter points to the    edit buffer being inserted. Connect to this signal to, for    example, populate a key field with a unique sequence number.*//*!    \fn void Q3DataTable::beforeUpdate( QSqlRecord* buf )    This signal is emitted just before the cursor's edit buffer is    updated in the database. The \a buf parameter points to the edit    buffer being updated. Connect to this signal when you want to    transform the user's data behind-the-scenes.*//*!    \fn void Q3DataTable::beforeDelete( QSqlRecord* buf )    This signal is emitted just before the currently selected record    is deleted from the database. The \a buf parameter points to the    edit buffer being deleted. Connect to this signal to, for example,    copy some of the fields for later use.*//*!    \fn void Q3DataTable::cursorChanged( QSql::Op mode )    This signal is emitted whenever the cursor record was changed due    to an edit. The \a mode parameter is the type of edit that just    took place.*/#endif

⌨️ 快捷键说明

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