]> Git trees. - libqmvoc.git/commitdiff
API cleanup: don't use byref return values when not necessary, pass by constref when...
authorPino Toscano <pino@kde.org>
Sat, 3 Mar 2007 22:28:11 +0000 (22:28 +0000)
committerPino Toscano <pino@kde.org>
Sat, 3 Mar 2007 22:28:11 +0000 (22:28 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=638975

kdeeducore/leitnerbox.cpp
kdeeducore/leitnerbox.h
kdeeducore/leitnersystem.cpp
kdeeducore/leitnersystem.h

index eef1e5d0adc3201d6f25795370f53dbb5d7065eb..83453ef0ed25ba7d3d4aef16019e4fcd0489c0f3 100644 (file)
@@ -40,11 +40,21 @@ LeitnerBox* LeitnerBox::correctWordBox()
        return m_correctWordBox;
 }
 
+const LeitnerBox* LeitnerBox::correctWordBox() const
+{
+       return m_correctWordBox;
+}
+
 LeitnerBox* LeitnerBox::wrongWordBox()
 {
        return m_wrongWordBox;
 }
 
+const LeitnerBox* LeitnerBox::wrongWordBox() const
+{
+       return m_wrongWordBox;
+}
+
 void LeitnerBox::setBoxName( const QString& name )
 {
        m_name = name;
index 7e74413b0f805d843c74f2a282fa59caf7658622..03733a3d6ed78855733bee31a355fb77eed17d0f 100644 (file)
@@ -89,12 +89,16 @@ public:
         */
        LeitnerBox* correctWordBox();
 
+       const LeitnerBox* correctWordBox() const;
+
        /**
         * Returns a pointer to the LeitnerBox wrong cards of this LeitnerBox here are assigned to
         * @return a pointer to a LeitnerBox
         */
        LeitnerBox* wrongWordBox();
        
+       const LeitnerBox* wrongWordBox() const;
+
        bool operator == ( const LeitnerBox& a ) const;
 
 private:
index 0533d60980bb6b275a36b2494e2be288969d7cea..4ad884a561f15cd17caf7de3b9da927cc06c8174 100644 (file)
@@ -50,6 +50,11 @@ LeitnerBox* LeitnerSystem::boxWithNumber( int number )
        return &m_boxes[ number ];
 }
 
+const LeitnerBox* LeitnerSystem::boxWithNumber( int number ) const
+{
+       return &m_boxes.at( number );
+}
+
 LeitnerBox* LeitnerSystem::boxWithName( const QString& name )
 {
        QList<LeitnerBox>::iterator it, it2;
@@ -64,12 +69,26 @@ LeitnerBox* LeitnerSystem::boxWithName( const QString& name )
        return 0;
 }
 
-QString& LeitnerSystem::systemName()
+const LeitnerBox* LeitnerSystem::boxWithName( const QString& name ) const
+{
+       QList<LeitnerBox>::const_iterator it, it2;
+       it = m_boxes.begin();
+       it2 = m_boxes.end();
+       for ( ; it != it2; ++it)
+       {
+               if ( (*it).boxName() == name )
+                       return &(*it);
+       }
+
+       return 0;
+}
+
+QString LeitnerSystem::systemName() const
 {
        return m_systemName;
 }
 
-QString LeitnerSystem::nextBox( QString& previousBox )
+QString LeitnerSystem::nextBox( const QString& previousBox )
 {
        for( int i = 0; i < m_boxes.count(); i++ )
        {
@@ -80,32 +99,32 @@ QString LeitnerSystem::nextBox( QString& previousBox )
        return QString();
 }
 
-const QString& LeitnerSystem::correctBox( int box )
+QString LeitnerSystem::correctBox( int box ) const
 {
        return m_boxes[ box ].correctWordBox()->boxName();
 }
 
-const QString& LeitnerSystem::wrongBox( int box )
+QString LeitnerSystem::wrongBox( int box ) const
 {
        return m_boxes[ box ].wrongWordBox()->boxName();
 }
 
-const QString& LeitnerSystem::correctBox( QString& box )
+QString LeitnerSystem::correctBox( const QString& box ) const
 {
        return boxWithName( box )->correctWordBox()->boxName();
 }
 
-const QString& LeitnerSystem::wrongBox( QString& box )
+QString LeitnerSystem::wrongBox( const QString& box ) const
 {
        return boxWithName( box )->wrongWordBox()->boxName();
 }
 
-int LeitnerSystem::wrongBoxNumber( int box )
+int LeitnerSystem::wrongBoxNumber( int box ) const
 {
        return number( m_boxes[ box ].wrongWordBox() );
 }
 
-int LeitnerSystem::correctBoxNumber( int box )
+int LeitnerSystem::correctBoxNumber( int box ) const
 {
        return number( m_boxes[ box ].correctWordBox() );
 }
@@ -148,7 +167,7 @@ void LeitnerSystem::setSystemName( const QString& name )
        m_systemName = name;
 }
 
-int LeitnerSystem::number( LeitnerBox* box ) const
+int LeitnerSystem::number( const LeitnerBox* box ) const
 {
        if( box == 0 )
                return -1;
@@ -202,9 +221,9 @@ void LeitnerSystem::setWrongBox( const QString& box, const QString& wrongWordBox
        boxWithName( box )->setWrongWordBox( boxWithName( wrongWordBox ) );
 }
 
-const QString& LeitnerSystem::box( int i ) const
+QString LeitnerSystem::box( int i ) const
 {
-       return m_boxes[ i ].boxName();
+       return m_boxes.at( i ).boxName();
 }
 
 void LeitnerSystem::setBoxVocabCount( QString& box, int vocabCount )
@@ -217,13 +236,13 @@ int LeitnerSystem::boxVocabCount( QString& box )
        return boxWithName( box )->vocabCount();
 }
 
-void LeitnerSystem::incrementBoxVocabCount( QString& box )
+void LeitnerSystem::incrementBoxVocabCount( const QString& box )
 {
        int tmp = boxWithName( box )->vocabCount();
        boxWithName( box )->setVocabCount( tmp++ );
 }
 
-void LeitnerSystem::decrementBoxVocabCount( QString& box )
+void LeitnerSystem::decrementBoxVocabCount( const QString& box )
 {
        int tmp = boxWithName( box )->vocabCount();
        boxWithName( box )->setVocabCount( tmp-- );
index 4bd7f7a371be2543a626ff0d1de5526b135eb20e..18a477614a53d51c4d6873d91862b8b597de3d61 100644 (file)
@@ -28,7 +28,7 @@ class KDEEDUCORE_EXPORT LeitnerSystem
 {
 public:
        /**Constructor without arguments*/
-       LeitnerSystem();
+       explicit LeitnerSystem();
 
        /**Constructor with arguments
         * @param boxes reference to a QList of LeitnerBox
@@ -52,7 +52,7 @@ public:
        /**Returns the LeitnerSystem's name
         * @return the LeitnerSystem's name as reference to QString
         */
-       QString& systemName();
+       QString systemName() const;
 
        /**Sets the LeitnerSystem's name
    *
@@ -66,6 +66,8 @@ public:
         */
        LeitnerBox* boxWithNumber( int number );
 
+       const LeitnerBox* boxWithNumber( int number ) const;
+
        /**Returns a LeitnerBox by name
         * @param name the name of the LeitnerBox to be returned
         * @return a pointer to the LeitnerBox with the name,
@@ -73,31 +75,37 @@ public:
         */
        LeitnerBox* boxWithName( const QString& name );
 
+       const LeitnerBox* boxWithName( const QString& name ) const;
+
        /**Returns the number of the given LeitnerBox
         * @param box a pointer to the LeitnerBox
         * @return the number of the given LeitnerBox
         */
-       int number( LeitnerBox* box ) const;
+       int number( const LeitnerBox* box ) const;
 
        /**Returns the name of the LeitnerBox with number @p i
         * @param i the LeitnerBox's number
         * @return the name of the LeitnerBox with number @p i
         */
-       const QString& box( int i ) const;
+       QString box( int i ) const;
 
        /**Returns the LeitnerBox following @p previousBox
         * @param previousBox the name of the LeitnerBox
         * @return the name of the LeitnerBox following previousBox
         */
-       QString nextBox( QString& previousBox );
+       QString nextBox( const QString& previousBox );
 
-       const QString& correctBox( int box );   //returns the correct word box of "int box"
-       const QString& wrongBox( int box );             //returns the wrong word box of "int box"
-       const QString& correctBox( QString& box );
-       const QString& wrongBox( QString& box );
+       /**Returns the correct word box of "int box"
+        */
+       QString correctBox( int box ) const;
+       /**Returns the wrong word box of "int box"
+        */
+       QString wrongBox( int box ) const;
+       QString correctBox( const QString& box ) const;
+       QString wrongBox( const QString& box ) const;
 
-       int wrongBoxNumber( int box );
-       int correctBoxNumber( int box );
+       int wrongBoxNumber( int box ) const;
+       int correctBoxNumber( int box ) const;
 
        void setCorrectBox( const QString& box, const QString& correctWordBox );
        void setWrongBox( const QString& box, const QString& wrongWordBox );
@@ -108,8 +116,8 @@ public:
        void setBoxVocabCount( QString& box, int vocabCount );
        int boxVocabCount( QString& box );
 
-       void incrementBoxVocabCount( QString& box );
-       void decrementBoxVocabCount( QString& box );
+       void incrementBoxVocabCount( const QString& box );
+       void decrementBoxVocabCount( const QString& box );
 
        //inserts a box with number, name, correct and wrong word box
        bool insertBox( const QString& name, int correctWordBox, int wrongWordBox );