From 4b20972da142bbdea42c682025ab5303c35a5a92 Mon Sep 17 00:00:00 2001 From: eilers Date: Wed, 27 Nov 2002 15:21:06 +0000 Subject: Extremely improved table update --- diff --git a/core/pim/addressbook/abtable.cpp b/core/pim/addressbook/abtable.cpp index e333b17..00335ae 100644 --- a/core/pim/addressbook/abtable.cpp +++ b/core/pim/addressbook/abtable.cpp @@ -123,7 +123,8 @@ AbTable::AbTable( const QValueList order, QWidget *parent, const char *name asc( TRUE ), intFields( order ), enablePainting( true ), - columnVisible( true ) + columnVisible( true ), + countNested( 0 ) { qWarning("C'tor start"); @@ -162,7 +163,7 @@ void AbTable::setContacts( const OContactAccess::List& viewList ) m_viewList = viewList; setSorting( false ); - setUpdatesEnabled( FALSE ); + setPaintingEnabled( FALSE ); OContactAccess::List::Iterator it; setNumRows( m_viewList.count() ); @@ -170,14 +171,14 @@ void AbTable::setContacts( const OContactAccess::List& viewList ) for ( it = m_viewList.begin(); it != m_viewList.end(); ++it ) insertIntoTable( *it, row++ ); - setUpdatesEnabled( TRUE ); - setSorting( true ); resort(); updateVisible(); + setPaintingEnabled( TRUE ); + } bool AbTable::selectContact( int UID ) @@ -188,6 +189,7 @@ bool AbTable::selectContact( int UID ) OContact* foundContact = 0l; bool found = false; + setPaintingEnabled( FALSE ); for ( int r = 0; r < rows; ++r ) { abi = static_cast( item(r, 0) ); foundContact = &contactList[abi]; @@ -204,12 +206,14 @@ bool AbTable::selectContact( int UID ) setCurrentCell( 0, 0 ); } + setPaintingEnabled( TRUE ); + return true; } void AbTable::insertIntoTable( const OContact& cnt, int row ) { - // qWarning( "void AbTable::insertIntoTable( const OContact& cnt, %d )", row ); + qWarning( "void AbTable::insertIntoTable( const OContact& cnt, %d )", row ); QString strName, strContact; @@ -251,6 +255,7 @@ void AbTable::columnClicked( int col ) void AbTable::resort() { qWarning( "void AbTable::resort()" ); + setPaintingEnabled( FALSE ); if ( sorting() ) { if ( lastSortCol == -1 ) lastSortCol = 0; @@ -258,6 +263,7 @@ void AbTable::resort() //QMessageBox::information( this, "resort", "resort" ); updateVisible(); } + setPaintingEnabled( TRUE ); } OContact AbTable::currentEntry() @@ -282,6 +288,8 @@ void AbTable::clear() { qWarning( "void AbTable::clear()" ); contactList.clear(); + + setPaintingEnabled( FALSE ); for ( int r = 0; r < numRows(); ++r ) { for ( int c = 0; c < numCols(); ++c ) { if ( cellWidget( r, c ) ) @@ -290,6 +298,7 @@ void AbTable::clear() } } setNumRows( 0 ); + setPaintingEnabled( TRUE ); } // Refresh updates column 2 if the contactsettings changed @@ -300,12 +309,14 @@ void AbTable::refresh() QString value; AbTableItem *abi; + setPaintingEnabled( FALSE ); for ( int r = 0; r < rows; ++r ) { abi = static_cast( item(r, 0) ); value = findContactContact( contactList[abi], r ); static_cast( item(r, 1) )->setItem( value, abi->text() ); } resort(); + setPaintingEnabled( TRUE ); } void AbTable::keyPressEvent( QKeyEvent *e ) @@ -454,6 +465,8 @@ void AbTable::fitColumns() int contentsWidth = visibleWidth() / 2; // :SX Why too low // Fix to better value // contentsWidth = 130; + + setPaintingEnabled( FALSE ); if ( columnVisible == false ){ showColumn(0); @@ -466,6 +479,8 @@ void AbTable::fitColumns() adjustColumn(1); if ( columnWidth(1) < contentsWidth ) setColumnWidth( 1, contentsWidth ); + + setPaintingEnabled( TRUE ); } void AbTable::show() @@ -533,6 +548,8 @@ QStringList AbTable::choiceSelection(int /*index*/) const void AbTable::updateVisible() { + qWarning("void AbTable::updateVisible()"); + int visible, totalRows, row, @@ -540,10 +557,10 @@ void AbTable::updateVisible() visible = 0; - realignTable(); - setPaintingEnabled( FALSE ); + realignTable(); + totalRows = numRows(); for ( row = 0; row < totalRows; row++ ) { if ( rowHeight(row) == 0 ) { @@ -569,17 +586,33 @@ void AbTable::updateVisible() void AbTable::setPaintingEnabled( bool e ) { - if ( e != enablePainting ) { - if ( !enablePainting ) { + qWarning("IN void AbTable::setPaintingEnabled( %d )->Nested: %d", e, countNested ); + + if ( e ) { + if ( countNested > 0 ) + --countNested; + if ( ! countNested ){ + setUpdatesEnabled( true ); enablePainting = true; rowHeightChanged( 0 ); viewport()->update(); - } else { - enablePainting = false; } + } else { + ++countNested; + enablePainting = false; + setUpdatesEnabled( false ); } + qWarning("OUT void AbTable::setPaintingEnabled( %d )->Nested: %d", e, countNested ); } +void AbTable::viewportPaintEvent( QPaintEvent* e ) { + qWarning(" void AbTable::viewportPaintEvent( QPaintEvent* e ) -> %d", enablePainting); + if ( enablePainting ) + QTable::viewportPaintEvent( e ); +} + + + void AbTable::rowHeightChanged( int row ) { if ( enablePainting ) diff --git a/core/pim/addressbook/abtable.h b/core/pim/addressbook/abtable.h index 83bd5a7..9825665 100644 --- a/core/pim/addressbook/abtable.h +++ b/core/pim/addressbook/abtable.h @@ -85,6 +85,7 @@ public: void show(); void setPaintingEnabled( bool e ); + void viewportPaintEvent( QPaintEvent* e); // addresspicker mode (What's that ? se) void setChoiceNames( const QStringList& list); @@ -127,8 +128,8 @@ private: QValueList intFields; QStringList choicenames; bool enablePainting; - bool columnVisible; + int countNested; OContactAccess::List m_viewList; diff --git a/core/pim/addressbook/abview.cpp b/core/pim/addressbook/abview.cpp index 8d22129..3af7663 100644 --- a/core/pim/addressbook/abview.cpp +++ b/core/pim/addressbook/abview.cpp @@ -1,3 +1,19 @@ +/********************************************************************** +** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de) +** +** This file is part of Qt Palmtop Environment. +** +** 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. +** +** +**********************************************************************/ + #include "abview.h" #include @@ -137,9 +153,6 @@ void AbView::load() clearForCategory(); - // Feed all views with new lists - updateListinViews(); - qWarning ("Number of contacts: %d", m_list.count()); updateView(); @@ -159,20 +172,9 @@ void AbView::clear() // :SX } -void AbView::setShowByCategory( Views view, const QString& cat ) +void AbView::setShowByCategory( const QString& cat ) { - qWarning("AbView::setShowCategory( Views view, const QString& cat )"); - -// if ( view == PersonalView ){ -// if ( ! m_inPersonal ) -// showPersonal( true ); - -// }else{ -// if ( m_inPersonal ) -// showPersonal( false ); - -// m_curr_View = view; -// } + qWarning("AbView::setShowCategory( const QString& cat )"); int intCat = 0; @@ -182,18 +184,10 @@ void AbView::setShowByCategory( Views view, const QString& cat ) else intCat = mCat.id("Contacts", cat ); - // If we just change the view, we don't have to reload any data.. - // This speeds up a lot of things ! - if ( intCat == m_curr_category ){ - qWarning ("Just change the View (Category is: %d)", m_curr_category); - m_prev_View = m_curr_View; - m_curr_View = view; - - updateView(); - }else{ + // Just do anything if we really change the category + if ( intCat != m_curr_category ){ qWarning ("Categories: Selected %s.. Number: %d", cat.latin1(), m_curr_category); - m_curr_View = view; m_curr_category = intCat; emit signalClearLetterPicker(); @@ -201,6 +195,22 @@ void AbView::setShowByCategory( Views view, const QString& cat ) } } + +void AbView::setShowToView( Views view ) +{ + qWarning("void AbView::setShowToView( View %d )", view); + + qWarning ("Change the View (Category is: %d)", m_curr_category); + + if ( m_curr_View != view ){ + m_prev_View = m_curr_View; + m_curr_View = view; + + updateView(); + } + +} + void AbView::setShowByLetter( char c ) { qWarning("void AbView::setShowByLetter( %c )", c ); @@ -401,6 +411,9 @@ void AbView::updateView() { qWarning("AbView::updateView()"); + // Feed all views with new lists + updateListinViews(); + if ( m_viewStack -> visibleWidget() ){ m_viewStack -> visibleWidget() -> clearFocus(); } @@ -415,23 +428,24 @@ void AbView::updateView() m_curr_Contact = m_ablabel -> currentEntry_UID(); break; } - emit signalViewSwitched ( (int) m_curr_View ); }else m_curr_Contact = 0; + // Inform the world that the view is changed + if ( m_curr_View != m_prev_View ) + emit signalViewSwitched ( (int) m_curr_View ); + m_prev_View = m_curr_View; // Switch to new View switch ( (int) m_curr_View ) { case TableView: m_abTable -> setChoiceSelection( m_orderedFields ); - m_abTable -> setContacts( m_list ); if ( m_curr_Contact != 0 ) m_abTable -> selectContact ( m_curr_Contact ); m_abTable -> setFocus(); break; case CardView: - m_ablabel -> setContacts( m_list ); if ( m_curr_Contact != 0 ) m_ablabel -> selectContact( m_curr_Contact ); m_ablabel -> setFocus(); diff --git a/core/pim/addressbook/abview.h b/core/pim/addressbook/abview.h index 201b521..2c10cfa 100644 --- a/core/pim/addressbook/abview.h +++ b/core/pim/addressbook/abview.h @@ -29,7 +29,8 @@ public: void setView( Views view ); void showPersonal( bool personal ); - void setShowByCategory( Views view, const QString& cat ); + void setShowByCategory( const QString& cat ); + void setShowToView( Views view ); void setShowByLetter( char c ); void setListOrder( const QValueList& ordered ); diff --git a/core/pim/addressbook/addressbook.cpp b/core/pim/addressbook/addressbook.cpp index 3b2e4b8..5d588da 100644 --- a/core/pim/addressbook/addressbook.cpp +++ b/core/pim/addressbook/addressbook.cpp @@ -821,15 +821,18 @@ void AddressbookWindow::slotSetCategory( int c ) if ( c <= 0 ) return; - // Checkmark Book Menu Item Selected + // Switch view if ( c < 3 ) - for ( unsigned int i = 1; i < 3; i++ ) - catMenu->setItemChecked( i, c == (int)i ); - // Checkmark Category Menu Item Selected + for ( unsigned int i = 1; i < 3; i++ ){ + if ( catMenu ) + catMenu->setItemChecked( i, c == (int)i ); + } else + // Checkmark Category Menu Item Selected for ( unsigned int i = 3; i < catMenu->count(); i++ ) catMenu->setItemChecked( i, c == (int)i ); + // Now switch to the selected category for ( unsigned int i = 1; i < catMenu->count(); i++ ) { if (catMenu->isItemChecked( i )) { if ( i == 1 ){ // default List view @@ -852,9 +855,11 @@ void AddressbookWindow::slotSetCategory( int c ) } } + // Switch to the selected View slotViewSwitched( view ); - m_abView -> setShowByCategory( view, cat ); + // Tell the view about the selected category + m_abView -> setShowByCategory( cat ); if ( book.isEmpty() ) book = "List"; @@ -868,6 +873,8 @@ void AddressbookWindow::slotViewSwitched( int view ) { qWarning( "void AddressbookWindow::slotViewSwitched( %d )", view ); int menu = 0; + + // Switch to selected view switch ( view ){ case AbView::TableView: menu = 1; @@ -879,31 +886,26 @@ void AddressbookWindow::slotViewSwitched( int view ) m_tableViewButton->setOn(false); m_cardViewButton->setOn(true); break; -// case AbView::PersonalView: -// menu = 3; -// break; -// case AbView::CompanyBook: -// menu = 3; -// break; -// case AbView::EmailBook: -// menu = 4; -// break; } for ( unsigned int i = 1; i < 3; i++ ){ if ( catMenu ) catMenu->setItemChecked( i, menu == (int)i ); } + + // Tell the view about the selected view + m_abView -> setShowToView ( (AbView::Views) view ); + } void AddressbookWindow::slotListView() { - emit slotSetCategory( AbView::TableView +1 ); + slotViewSwitched( AbView::TableView ); } void AddressbookWindow::slotCardView() { - emit slotSetCategory( AbView::CardView +1 ); + slotViewSwitched( AbView::CardView ); } void AddressbookWindow::slotSetLetter( char c ) { @@ -937,18 +939,6 @@ void AddressbookWindow::populateCategories() ++id; } - // :SX -// if ( abList->showBook().isEmpty() ) { -// catMenu->setItemChecked( 1, true ); -// } else if ( abList->showBook() == "Phone" ) { -// catMenu->setItemChecked( 2, true ); -// } else if ( abList->showBook() == "Company" ) { -// catMenu->setItemChecked( 3, true ); -// } else if ( abList->showBook() == "Email" ) { -// catMenu->setItemChecked( 4, true ); -// } else if ( abList->showBook() == "Cards" ) { -// catMenu->setItemChecked( 5, true ); -// } if ( m_abView -> showCategory().isEmpty() ) { slotSetCategory( 3 ); -- cgit v0.9.0.2