[yast-commit] r57242 - in /trunk/ncurses/src: NCTable.cc NCTable.h NCTablePad.cc NCTablePad.h

Author: gs Date: Tue May 19 14:13:55 2009 New Revision: 57242 URL: http://svn.opensuse.org/viewcvs/yast?rev=57242&view=rev Log: add the possibility to set a particular sort strategy for table sorting Modified: trunk/ncurses/src/NCTable.cc trunk/ncurses/src/NCTable.h trunk/ncurses/src/NCTablePad.cc trunk/ncurses/src/NCTablePad.h Modified: trunk/ncurses/src/NCTable.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/ncurses/src/NCTable.cc?rev=57242&... ============================================================================== --- trunk/ncurses/src/NCTable.cc (original) +++ trunk/ncurses/src/NCTable.cc Tue May 19 14:13:55 2009 @@ -137,6 +137,18 @@ YTable::setTableHeader( th ); } +// +// Return table header as string vector (alignment removed) +// +void NCTable::getHeader( vector<string> & header ) +{ + header.assign( _header.size(), "" ); + + for ( unsigned int i = 0; i < _header.size(); i++ ) + { + header[ i ] = _header[i].Str().substr( 1 ); // remove alignment + } +} // Set alignment of i-th table column (left, right, center). Modified: trunk/ncurses/src/NCTable.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/ncurses/src/NCTable.h?rev=57242&r... ============================================================================== --- trunk/ncurses/src/NCTable.h (original) +++ trunk/ncurses/src/NCTable.h Tue May 19 14:13:55 2009 @@ -37,6 +37,10 @@ bool bigList() const { return biglist; } void setHeader( vector <string> head ); + void getHeader( vector <string> & head ); + + //vector<NCstring> getHeader( ) const { return _header }; + virtual void setAlignment( int col, YAlignmentType al ); void setBigList( const bool big ) { biglist = big; } @@ -82,6 +86,7 @@ void stripHotkeys() { myPad()->stripHotkeys(); } + void setSortStrategy( NCTableSortStrategyBase * newStrategy ) { myPad()->setSortStrategy( newStrategy ); } protected: Modified: trunk/ncurses/src/NCTablePad.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/ncurses/src/NCTablePad.cc?rev=572... ============================================================================== --- trunk/ncurses/src/NCTablePad.cc (original) +++ trunk/ncurses/src/NCTablePad.cc Tue May 19 14:13:55 2009 @@ -33,6 +33,7 @@ , Headline( 0 ) , Items( 0 ) , citem( 0 ) + , sortStrategy ( new NCTableSortDefault ) { } @@ -316,24 +317,23 @@ return false; } -static int column = -1; - -static bool compare_column( NCTableLine* first, NCTableLine* second ) -{ - return first->GetCol( column )->Label().getText().begin()->str() - < second->GetCol( column )->Label().getText().begin()->str(); -} - +// +// Set order, means sort the table according to given column +// (call particular sort strategy). +// void NCTablePad::setOrder( int col ) { - if (column != col) + if ( col < 0 ) + return; + + if ( sortStrategy->getColumn() != col ) { - column = col; - std::sort( Items.begin(), Items.end(), compare_column ); + sortStrategy->setColumn( col ); + sortStrategy->sort( Items.begin(), Items.end(), col ); } else std::reverse( Items.begin(), Items.end() ); - + dirty = true; update(); } Modified: trunk/ncurses/src/NCTablePad.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/ncurses/src/NCTablePad.h?rev=5724... ============================================================================== --- trunk/ncurses/src/NCTablePad.h (original) +++ trunk/ncurses/src/NCTablePad.h Tue May 19 14:13:55 2009 @@ -31,6 +31,59 @@ using std::vector; +class NCTableSortStrategyBase +{ +public: + NCTableSortStrategyBase( ) { _uiColumn = -1; } + + virtual ~NCTableSortStrategyBase() {} + + virtual void sort ( + vector<NCTableLine *>::iterator itemsBegin, + vector<NCTableLine *>::iterator itemsEnd, + int uiColumn + ) = 0; + int getColumn () { return _uiColumn; } + void setColumn ( int column) { _uiColumn = column; } + +private: + int _uiColumn; + +}; + +class NCTableSortDefault : public NCTableSortStrategyBase { +public: + virtual void sort ( + vector<NCTableLine *>::iterator itemsBegin, + vector<NCTableLine *>::iterator itemsEnd, + int uiColumn + ) + { + std::sort ( itemsBegin, itemsEnd, Compare(uiColumn) ); + } + +private: + 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; + }; + + +}; + class NCTableTag : public NCTableCol { private: @@ -93,6 +146,8 @@ vector<NCTableLine*> Items; wpos citem; + std::auto_ptr<NCTableSortStrategyBase> sortStrategy; + void assertLine( unsigned idx ); protected: @@ -178,6 +233,13 @@ NCTableLine * ModifyLine( unsigned idx ); void stripHotkeys(); + + void setSortStrategy ( + NCTableSortStrategyBase* newSortStrategy // dyn. allocated + ) + { + sortStrategy.reset ( newSortStrategy ); + } }; -- 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