[yast-commit] r57328 - in /trunk/ncurses-pkg/src: NCPkgTable.cc NCPkgTable.h
Author: gs Date: Wed May 27 12:01:10 2009 New Revision: 57328 URL: http://svn.opensuse.org/viewcvs/yast?rev=57328&view=rev Log: sort strategy for package table sorting added Modified: trunk/ncurses-pkg/src/NCPkgTable.cc trunk/ncurses-pkg/src/NCPkgTable.h Modified: trunk/ncurses-pkg/src/NCPkgTable.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/ncurses-pkg/src/NCPkgTable.cc?rev=57328&r1=57327&r2=57328&view=diff ============================================================================== --- trunk/ncurses-pkg/src/NCPkgTable.cc (original) +++ trunk/ncurses-pkg/src/NCPkgTable.cc Wed May 27 12:01:10 2009 @@ -99,6 +99,9 @@ , haveInstalledVersion ( false ) { fillHeader(); + vector<string> pkgHeader; + getHeader( pkgHeader ); + setSortStrategy( new NCPkgTableSort( pkgHeader ) ); setVisibleInfo( I_Technical ); // set default yuiDebug() << endl; } Modified: trunk/ncurses-pkg/src/NCPkgTable.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/ncurses-pkg/src/NCPkgTable.h?rev=57328&r1=57327&r2=57328&view=diff ============================================================================== --- trunk/ncurses-pkg/src/NCPkgTable.h (original) +++ trunk/ncurses-pkg/src/NCPkgTable.h Wed May 27 12:01:10 2009 @@ -23,6 +23,7 @@ #include "NCPadWidget.h" #include "NCTablePad.h" #include "NCTable.h" +#include "NCPkgStrings.h" #include <map> #include <string> @@ -67,6 +68,74 @@ ZyppSel getSelPointer() const { return selPointer; } }; + +class NCPkgTableSort : public NCTableSortStrategyBase { + +public: + + NCPkgTableSort( const vector<string> & head ) + : _header ( head ) + { } + + virtual void sort ( + vector<NCTableLine *>::iterator itemsBegin, + vector<NCTableLine *>::iterator itemsEnd, + int uiColumn + ) + { + if ( _header[ uiColumn ] == NCPkgStrings::PkgSize() ) + { + std::sort( itemsBegin, itemsEnd, CompareSize() ); + } + else + { + std::sort( itemsBegin, itemsEnd, Compare( uiColumn ) ); + } + } + +private: + vector<string> _header; + + class CompareSize + { + public: + CompareSize ( ) + {} + + bool operator() ( NCTableLine * first, + NCTableLine * second + ) const + { + YTableItem *firstItem = dynamic_cast<YTableItem*> (first->origItem() ); + YTableItem *secondItem = dynamic_cast<YTableItem*> (second->origItem() ); + NCPkgTableTag *firstTag = static_cast<NCPkgTableTag *>( firstItem->cell(0) ); + NCPkgTableTag *secondTag = static_cast<NCPkgTableTag *>( secondItem->cell(0) ); + + return firstTag->getDataPointer()->installSize() < + secondTag->getDataPointer()->installSize(); + } + + }; + + class Compare + { + public: + Compare ( int uiCol) + : _uiCol (uiCol) + {} + + bool operator() ( NCTableLine * first, + NCTableLine * second + ) const + { + return first->GetCol( _uiCol )->Label().getText().begin()->str() + < second->GetCol( _uiCol )->Label().getText().begin()->str(); + } + private: + int _uiCol; + }; +}; + /** * The package table class. Provides methods to fill the table, * set the status info and so on. @@ -130,6 +199,8 @@ NCPkgTableTag * getTag ( const int & index ); NCPkgTableInfoType visibleInfo; + + vector<string> header; // the table header protected: -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
gs@svn.opensuse.org