[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/games/kpicross/src
From:       Jeremy Paul Whiting <jeremy () scitools ! com>
Date:       2008-02-29 23:50:19
Message-ID: 1204329019.048514.22025.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 780784 by whiting:

reload list of boards on save signal from create window, also store boards in a map by their title

 M  +3 -0      createwindow.cpp  
 M  +4 -0      createwindow.h  
 M  +8 -7      levels.cpp  
 M  +4 -2      levels.h  
 M  +3 -3      mainwindow.cpp  


--- trunk/playground/games/kpicross/src/createwindow.cpp #780783:780784
@@ -2,6 +2,7 @@
  * createwindow.cpp
  *
  * Copyright (C)  2004  Zack Rusin <zack@kde.org>
+ * Copyright (C) 2008 Jeremy Whiting (jeremy@scitools.com)
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -105,6 +106,8 @@
     saveBoard->save( str );
     file.close();
     delete saveBoard;
+
+    emit boardSaved();
 }
 
 void CreateWindow::slotChangeSize( int i )
--- trunk/playground/games/kpicross/src/createwindow.h #780783:780784
@@ -2,6 +2,7 @@
  * createwindow.h
  *
  * Copyright (C)  2004  Zack Rusin <zack@kde.org>
+ * Copyright (C) 2008 Jeremy Whiting (jeremy@scitools.com)
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -41,6 +42,9 @@
     void slotTitleChanged( const QString& title );
     void slotChangeSize( int i );
 
+signals:
+    void boardSaved();
+
 private:
     BoardView *m_view;
 };
--- trunk/playground/games/kpicross/src/levels.cpp #780783:780784
@@ -2,6 +2,7 @@
  * levels.cpp
  *
  * Copyright (C)  2004  Zack Rusin <zack@kde.org>
+ * Copyright (C) 2008 Jeremy Whiting (jeremy@scitools.com)
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -53,16 +54,18 @@
         board->save( str );
         file.close();
     }
-    m_boards.append( board );
+    m_boards.insert( board->title(), board );
 }
 
 QList<Board*> Levels::boards() const
 {
-    return m_boards;
+    return m_boards.values();
 }
 
 void Levels::load()
 {
+    m_boards.clear();
+
     QStringList datafiles = KGlobal::dirs()->findAllResources( "data", "kpicross/*.pic" );
 
     for (int i = 0; i < datafiles.size(); ++i)
@@ -73,17 +76,15 @@
             QDataStream str( &file );
             Board *board = new Board( "new", this );
             board->load( str );
-            m_boards.append( board );
+            m_boards.insert( board->title(), board );
         }
     }
 }
 
 Board * Levels::board( const QString& title ) const
 {
-    for ( QList<Board*>::const_iterator it = m_boards.begin(); it != m_boards.end(); ++it ) {
-        Board *board = *it;
-        if ( board->title() == title )
-            return board;
+    if (m_boards.contains(title)) {
+        return m_boards[title];
     }
     return 0;
 }
--- trunk/playground/games/kpicross/src/levels.h #780783:780784
@@ -2,6 +2,7 @@
  * levels.h
  *
  * Copyright (C)  2004  Zack Rusin <zack@kde.org>
+ * Copyright (C) 2008 Jeremy Whiting (jeremy@scitools.com)
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -23,7 +24,8 @@
 
 #include <qobject.h>
 
-#include <qlist.h>
+#include <QMap>
+#include <QString>
 
 class Board;
 class KURL;
@@ -43,7 +45,7 @@
     void load();
 
 private:
-    QList<Board*> m_boards;
+    QMap<QString, Board*> m_boards;
 };
 
 #endif
--- trunk/playground/games/kpicross/src/mainwindow.cpp #780783:780784
@@ -2,6 +2,7 @@
  * mainwindow.cpp
  *
  * Copyright (C)  2004  Zack Rusin <zack@kde.org>
+ * Copyright (C) 2008 Jeremy Whiting (jeremy@scitools.com)
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -35,7 +36,7 @@
 #include <kdebug.h>
 
 MainWindow::MainWindow( QWidget *parent )
-    : KXmlGuiWindow( parent ), m_view(NULL)
+    : KXmlGuiWindow( parent ), m_view(NULL), m_createWindow(NULL)
 {
     statusBar()->showMessage( i18n( "Picross" ) );
 
@@ -52,8 +53,6 @@
     setCentralWidget( mainFrame );
 
     setupGUI( Default, "kpicross.rc" );
-
-    m_createWindow = new CreateWindow(this);
 }
 
 void MainWindow::changeBoard( Board *board )
@@ -69,6 +68,7 @@
     if (m_createWindow == NULL)
     {
         m_createWindow = new CreateWindow(this);
+        connect(m_createWindow, SIGNAL(boardSaved()), m_levels, SLOT(load()));
     }
     m_createWindow->show();
 }
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic