-rw-r--r-- | noncore/games/tetrix/ohighscoredlg.cpp | 75 | ||||
-rw-r--r-- | noncore/games/tetrix/ohighscoredlg.h | 13 | ||||
-rw-r--r-- | noncore/games/tetrix/tetrix.pro | 2 |
3 files changed, 48 insertions, 42 deletions
diff --git a/noncore/games/tetrix/ohighscoredlg.cpp b/noncore/games/tetrix/ohighscoredlg.cpp index 8d8079e..66f4917 100644 --- a/noncore/games/tetrix/ohighscoredlg.cpp +++ b/noncore/games/tetrix/ohighscoredlg.cpp | |||
@@ -21,2 +21,3 @@ | |||
21 | #include <qstring.h> | 21 | #include <qstring.h> |
22 | #include <qlist.h> | ||
22 | #include <qhbox.h> | 23 | #include <qhbox.h> |
@@ -29,3 +30,3 @@ | |||
29 | 30 | ||
30 | OHighscore::OHighscore( int score , int playerLevel ) | 31 | OHighscore::OHighscore( int score , int playerLevel ) : playerData() |
31 | { | 32 | { |
@@ -34,2 +35,3 @@ OHighscore::OHighscore( int score , int playerLevel ) | |||
34 | checkIfItIsANewhighscore( score ); | 35 | checkIfItIsANewhighscore( score ); |
36 | playerData.setAutoDelete( TRUE ); | ||
35 | } | 37 | } |
@@ -38,7 +40,2 @@ OHighscore::~OHighscore() | |||
38 | { | 40 | { |
39 | std::list<t_playerData*>::iterator deleteIterator = playerData.begin(); | ||
40 | for ( ; deleteIterator != playerData.end() ; deleteIterator++ ) | ||
41 | { | ||
42 | delete ( *deleteIterator ); | ||
43 | } | ||
44 | } | 41 | } |
@@ -66,3 +63,3 @@ void OHighscore::getList() | |||
66 | 63 | ||
67 | playerData.push_back( pPlayerData ); | 64 | playerData.append( pPlayerData ); |
68 | 65 | ||
@@ -85,3 +82,3 @@ void OHighscore::getList() | |||
85 | 82 | ||
86 | playerData.push_back( pPlayerData ); | 83 | playerData.append( pPlayerData ); |
87 | } | 84 | } |
@@ -102,7 +99,11 @@ void OHighscore::insertData( QString name , int punkte , int playerLevel ) | |||
102 | Config cfg ( "tetrix" ); | 99 | Config cfg ( "tetrix" ); |
100 | t_playerData * Run; | ||
101 | int index = 0; | ||
103 | int entryNumber = 1; | 102 | int entryNumber = 1; |
104 | std::list<t_playerData*>::iterator insertIterator = playerData.begin(); | 103 | |
105 | while ( insertIterator != playerData.end() ) | 104 | for ( Run=playerData.first(); |
106 | { | 105 | Run != 0; |
107 | if ( punkte > ( *insertIterator )->points ) | 106 | index ++, Run=playerData.next() ) { |
107 | |||
108 | if ( punkte > Run->points ) | ||
108 | { | 109 | { |
@@ -112,9 +113,7 @@ void OHighscore::insertData( QString name , int punkte , int playerLevel ) | |||
112 | temp->level = playerLevel; | 113 | temp->level = playerLevel; |
113 | playerData.insert( insertIterator , temp ); | 114 | |
115 | playerData.insert( index, temp ); | ||
114 | 116 | ||
115 | //now we have to delete the last entry | 117 | //now we have to delete the last entry |
116 | insertIterator = playerData.end(); | 118 | playerData.remove( playerData.count() ); |
117 | insertIterator--; | ||
118 | //X delete *insertIterator; //memleak? | ||
119 | playerData.erase( insertIterator ); | ||
120 | 119 | ||
@@ -122,11 +121,10 @@ void OHighscore::insertData( QString name , int punkte , int playerLevel ) | |||
122 | //this block just rewrites the highscore | 121 | //this block just rewrites the highscore |
123 | insertIterator = playerData.begin(); | 122 | for ( t_playerData * Run2=playerData.first(); |
124 | while ( insertIterator != playerData.end() ) | 123 | Run2 != 0; |
125 | { | 124 | Run2=playerData.next() ) { |
126 | cfg.setGroup( QString::number( entryNumber ) ); | 125 | cfg.setGroup( QString::number( entryNumber ) ); |
127 | cfg.writeEntry( "Name" , ( *insertIterator )->sName ); | 126 | cfg.writeEntry( "Name" , Run2->sName ); |
128 | cfg.writeEntry( "Points" , ( *insertIterator )->points ); | 127 | cfg.writeEntry( "Points" , Run2->points ); |
129 | cfg.writeEntry( "Level" , ( *insertIterator )->level ); | 128 | cfg.writeEntry( "Level" , Run2->level ); |
130 | entryNumber++; | 129 | entryNumber++; |
131 | insertIterator++; | ||
132 | } | 130 | } |
@@ -136,3 +134,2 @@ void OHighscore::insertData( QString name , int punkte , int playerLevel ) | |||
136 | } | 134 | } |
137 | insertIterator++; | ||
138 | } | 135 | } |
@@ -179,16 +176,26 @@ void OHighscoreDialog::createHighscoreListView() | |||
179 | int level_ = 0; | 176 | int level_ = 0; |
177 | QListViewItem * Prev = 0; | ||
180 | 178 | ||
181 | std::list<t_playerData*>::reverse_iterator iListe = hs_->playerData.rbegin(); | 179 | for ( t_playerData * Run = hs_->playerData.first(); |
182 | 180 | Run != 0; | |
183 | for ( ; iListe != hs_->playerData.rend() ; ++iListe ) | 181 | Run=hs_->playerData.next() ) |
184 | { | 182 | { |
185 | QListViewItem *item = new QListViewItem( list ); | 183 | QListViewItem *item; |
184 | |||
185 | if( Prev ) { | ||
186 | // after previous | ||
187 | item = new QListViewItem( list, Prev ); | ||
188 | Prev = item; | ||
189 | } else { | ||
190 | item = new QListViewItem( list ); | ||
191 | |||
192 | } | ||
186 | item->setText( 0 , QString::number( pos ) ); //number | 193 | item->setText( 0 , QString::number( pos ) ); //number |
187 | item->setText( 1 , ( *iListe )->sName ); //name | 194 | item->setText( 1 , Run->sName ); //name |
188 | if ( ( *iListe )->points == -1 ) | 195 | if ( Run->points == -1 ) |
189 | points_ = 0; | 196 | points_ = 0; |
190 | else points_ = ( *iListe )->points; | 197 | else points_ = Run->points; |
191 | if ( ( *iListe )->level == -1 ) | 198 | if ( Run->level == -1 ) |
192 | level_ = 0; | 199 | level_ = 0; |
193 | else level_ = ( *iListe )->level; | 200 | else level_ = Run->level; |
194 | item->setText( 2 , QString::number( points_ ) ); //points | 201 | item->setText( 2 , QString::number( points_ ) ); //points |
diff --git a/noncore/games/tetrix/ohighscoredlg.h b/noncore/games/tetrix/ohighscoredlg.h index fdbe623..845e639 100644 --- a/noncore/games/tetrix/ohighscoredlg.h +++ b/noncore/games/tetrix/ohighscoredlg.h | |||
@@ -14,8 +14,9 @@ class QListView; | |||
14 | #include <qdialog.h> | 14 | #include <qdialog.h> |
15 | #include <list> | 15 | #include <qlist.h> |
16 | 16 | ||
17 | using namespace std; | 17 | class t_playerData |
18 | |||
19 | struct t_playerData | ||
20 | { | 18 | { |
19 | |||
20 | public : | ||
21 | |||
21 | QString sName; | 22 | QString sName; |
@@ -47,3 +48,3 @@ class OHighscore : public QWidget | |||
47 | 48 | ||
48 | list<t_playerData*> playerData; | 49 | QList<t_playerData> playerData; |
49 | 50 | ||
@@ -55,4 +56,2 @@ class OHighscore : public QWidget | |||
55 | 56 | ||
56 | list<t_playerData*>::iterator iPlayerData; | ||
57 | |||
58 | /* | 57 | /* |
diff --git a/noncore/games/tetrix/tetrix.pro b/noncore/games/tetrix/tetrix.pro index 580a542..96f452f 100644 --- a/noncore/games/tetrix/tetrix.pro +++ b/noncore/games/tetrix/tetrix.pro | |||
@@ -14,3 +14,3 @@ INCLUDEPATH += $(OPIEDIR)/include | |||
14 | DEPENDPATH+= $(OPIEDIR)/include | 14 | DEPENDPATH+= $(OPIEDIR)/include |
15 | LIBS += -lqpe -lopiecore2 -lstdc++ | 15 | LIBS += -lqpe -lopiecore2 |
16 | INTERFACES= | 16 | INTERFACES= |