* adding destructors to my line edit subclasses
authorsheepluva
Sat, 22 Oct 2011 20:41:23 +0200
changeset 6187 59ff93c0ae2d
parent 6186 255aff92216d
child 6188 e48280142001
* adding destructors to my line edit subclasses + case-insensitive sorting for suggested nicknames
QTfrontend/ui/widget/HistoryLineEdit.cpp
QTfrontend/ui/widget/HistoryLineEdit.h
QTfrontend/ui/widget/SmartLineEdit.cpp
QTfrontend/ui/widget/SmartLineEdit.h
--- a/QTfrontend/ui/widget/HistoryLineEdit.cpp	Sat Oct 22 19:37:39 2011 +0200
+++ b/QTfrontend/ui/widget/HistoryLineEdit.cpp	Sat Oct 22 20:41:23 2011 +0200
@@ -35,6 +35,12 @@
 }
 
 
+HistoryLineEdit::~HistoryLineEdit()
+{
+    delete m_history;
+}
+
+
 void HistoryLineEdit::rememberCurrentText()
 {
     m_historyMutex.lock();
--- a/QTfrontend/ui/widget/HistoryLineEdit.h	Sat Oct 22 19:37:39 2011 +0200
+++ b/QTfrontend/ui/widget/HistoryLineEdit.h	Sat Oct 22 20:41:23 2011 +0200
@@ -25,8 +25,10 @@
 #ifndef HEDGEWARS_HISTORYLINEEDIT
 #define HEDGEWARS_HISTORYLINEEDIT
 
+#include <QStringList>
+#include <QString>
+
 #include <QLineEdit>
-#include <QString>
 
 #include <QKeyEvent>
 
@@ -56,6 +58,11 @@
     HistoryLineEdit(QWidget * parent = 0, int maxHistorySize = 64);
 
     /**
+    * @brief Class destructor.
+    */
+    ~HistoryLineEdit();
+
+    /**
      * @brief Appends current text to history (if not only whitespaces);
      */
     void rememberCurrentText();
--- a/QTfrontend/ui/widget/SmartLineEdit.cpp	Sat Oct 22 19:37:39 2011 +0200
+++ b/QTfrontend/ui/widget/SmartLineEdit.cpp	Sat Oct 22 20:41:23 2011 +0200
@@ -31,6 +31,7 @@
 
     m_cmds  = new QStringList();
     m_nicks = new QStringList();
+    m_sorted_nicks = new QMap<QString, QString>();
 
     resetAutoCompletionStatus();
 
@@ -42,6 +43,14 @@
 }
 
 
+SmartLineEdit::~SmartLineEdit()
+{
+    delete m_cmds;
+    delete m_nicks;
+    delete m_sorted_nicks;
+}
+
+
 void SmartLineEdit::addCommands(const QStringList & commands)
 {
     m_keywordMutex.lock();
@@ -69,6 +78,7 @@
 {
     m_keywordMutex.lock();
 
+    m_sorted_nicks->insert(name.toLower(), name);
     m_nicks->append(name);
 
     m_keywordMutex.unlock();
@@ -79,6 +89,7 @@
 {
     m_keywordMutex.lock();
 
+    m_sorted_nicks->remove(name.toLower());
     m_nicks->removeAll(name);
 
     m_keywordMutex.unlock();
@@ -91,6 +102,7 @@
     m_keywordMutex.lock();
 
     m_cmds->clear();
+    m_sorted_nicks->clear();
     m_nicks->clear();
     resetAutoCompletionStatus();
 
@@ -163,7 +175,7 @@
     {
         m_keywordMutex.lock();
         m_cmds->sort();
-        m_nicks->sort();
+        m_nicks = new QStringList(m_sorted_nicks->values());
         m_keywordMutex.unlock();
 
         int cp = cursorPosition();
--- a/QTfrontend/ui/widget/SmartLineEdit.h	Sat Oct 22 19:37:39 2011 +0200
+++ b/QTfrontend/ui/widget/SmartLineEdit.h	Sat Oct 22 20:41:23 2011 +0200
@@ -25,9 +25,13 @@
 #ifndef HEDGEWARS_SMARTLINEEDIT_H
 #define HEDGEWARS_SMARTLINEEDIT_H
 
+#include <QMap>
+#include <QString>
 #include <QStringList>
 
 #include <QEvent>
+#include <QKeyEvent>
+
 #include <QRegExp>
 
 #include "HistoryLineEdit.h"
@@ -59,6 +63,11 @@
     SmartLineEdit(QWidget * parent = 0, int maxHistorySize = 64);
 
     /**
+    * @brief Class destructor.
+    */
+    ~SmartLineEdit();
+
+    /**
      * @brief Adds commands to the auto-completion feature.
      * @param commands list of commands to be added.
      */
@@ -116,6 +125,8 @@
 
     QStringList * m_cmds;  ///< list of recognized commands
     QStringList * m_nicks; ///< list of recognized nicknames
+    /// list of recognized commands, sorted case-insensitive
+    QMap<QString, QString> * m_sorted_nicks;
 
     // these variables contain information about the last replacement
     // they get reset whenever cursor is moved or text is changed