SVN commit 1226672 by ehuguet: Save / restore (part of) column layout SVN_SILENT: M +63 -38 infolist.cpp --- branches/work/kmldonkey/kmldonkey/infolist.cpp #1226671:1226672 @@ -119,15 +119,6 @@ void InfoList::initialise() { - KSharedConfigPtr conf = KGlobal::config(); - - if ( !m_name.isEmpty() ) - { - KConfigGroup group = conf->group( m_name ); - if ( group.hasKey( "HideHeader" ) ) - hideHeader = group.readEntry( "HideHeader", QStringList() ); - } - // initialize columns: setColumnCount( m_columnCount ); @@ -138,38 +129,17 @@ hi->setText( i, m_columns[i] ); h->setResizeMode( i, m_columnResizeMode[i] ); h->resizeSection( i, m_columnWidth[i] ); - - bool hidecol = m_headerMenu && hideHeader.indexOf( m_columns[i] ) >= 0; - if ( m_headerMenu ) - { - m_headerMenu->insertItem( m_columns[i], i ); - m_headerMenu->setItemChecked( i, ! hidecol ); } - if ( hidecol ) - hideColumn( i ); - } // event filter, used to detect mouse r-click on header: // (see http://www.qtcentre.org/threads/25622-Capture-mouse-event-on-QHeaderView) h->viewport()->installEventFilter( this ); + // restore settings: + KSharedConfigPtr conf = KGlobal::config(); if ( !m_name.isEmpty() ) { restoreLayout( conf.data(), m_name ); - - KConfigGroup group = conf->group( m_name ); - QStringList cols = group.readEntry( "ColumnWidths", QStringList() ); - int i = 0; - - kDebug() << m_name; - - QStringList::ConstIterator it = cols.constBegin(); - const QStringList::ConstIterator itEnd = cols.constEnd(); - for ( ; it != itEnd; ++it ) - setColumnWidth( i++, (*it).toInt() ); - - if ( sortColumn() >= header()->count() && header()->count() > 0 ) - sortByColumn( 0 ); // workaround } } @@ -182,37 +152,92 @@ return; saveLayout( conf.data(), m_name ); - KConfigGroup group = conf->group( m_name ); +} + +void InfoList::saveLayout( KSharedConfig * cfg, const QString &name ) +{ + KConfigGroup group = cfg->group( name ); + + // save column widths; QStringList widths; const int colCount = model()->columnCount(); for ( int i = 0; i < colCount; ++i ) - widths << QString::number( columnWidth( i ) ); + { + int w = 0; + if( isColumnHidden( i ) ) + w = m_columnWidth[i]; // hidden columns return 0, so avoid it & store default width for it + else + w = columnWidth( i ); + widths << QString::number( w ); + } + group.writeEntry( "ColumnWidths", widths ); + // save hide state: if ( m_headerMenu ) { QStringList hideHeader; for ( int i = 0; i < m_columnCount; i++ ) + { if( isColumnHidden( i )) hideHeader.append( m_columns[i] ); + } + group.writeEntry( "HideHeader", hideHeader ); } -} + // TODO: save column ordering -void InfoList::saveLayout( KSharedConfig * cfg, const QString &name ) + // save sorting order: + // TODO: save asc/desc order -> how can we to determine it...? + if( isSortingEnabled() ) { - // TODO... + group.writeEntry( "SortColumn", sortColumn() ); } + else + group.writeEntry( "SortColumn", -1 ); +} void InfoList::restoreLayout( const KSharedConfig * cfg, const QString &name ) { - // TODO... + KConfigGroup group = cfg->group( name ); + QStringList cols = group.readEntry( "ColumnWidths", QStringList() ); + hideHeader = group.readEntry( "HideHeader", QStringList() ); + + // restore column widths & hide state: + QStringList::ConstIterator it = cols.constBegin(); + const QStringList::ConstIterator itEnd = cols.constEnd(); + int i = 0; + for ( ; it != itEnd; ++it, ++i ) + { + setColumnWidth( i, (*it).toInt() ); + + bool hidecol = m_headerMenu && hideHeader.indexOf( m_columns[i] ) >= 0; + if ( m_headerMenu ) + { + m_headerMenu->insertItem( m_columns[i], i ); + m_headerMenu->setItemChecked( i, ! hidecol ); } + if ( hidecol ) + hideColumn( i ); + } + // restore sorting order: + int col = group.readEntry( "SortColumn", -1 ); + if( col >= 0 ) + { + if ( col >= header()->count() && header()->count() > 0 ) + col = 0; // workaround + sortByColumn( col ); + } + + // TODO: restore column ordering +} + + QList InfoList::selectedItems() const {