QTfrontend/ui/widget/HistoryLineEdit.cpp
changeset 6205 7764cbe4ddd7
parent 6187 59ff93c0ae2d
child 6616 f77bb02b669f
equal deleted inserted replaced
6204:80cd75daf80f 6205:7764cbe4ddd7
    41 }
    41 }
    42 
    42 
    43 
    43 
    44 void HistoryLineEdit::rememberCurrentText()
    44 void HistoryLineEdit::rememberCurrentText()
    45 {
    45 {
    46     m_historyMutex.lock();
       
    47 
       
    48     rememberCurrentTextUnsynced();
       
    49 
       
    50     m_historyMutex.unlock();
       
    51 }
       
    52 
       
    53 
       
    54 void HistoryLineEdit::rememberCurrentTextUnsynced()
       
    55 {
       
    56     QString newEntry = text();
    46     QString newEntry = text();
    57 
    47 
    58     // don't store whitespace-only/empty text
    48     // don't store whitespace-only/empty text
    59     if (newEntry.trimmed().isEmpty())
    49     if (newEntry.trimmed().isEmpty())
    60         return;
    50         return;
    71 }
    61 }
    72 
    62 
    73 
    63 
    74 void HistoryLineEdit::clear()
    64 void HistoryLineEdit::clear()
    75 {
    65 {
    76     m_historyMutex.lock();
       
    77 
       
    78     QLineEdit::clear();
    66     QLineEdit::clear();
    79     m_curHistEntryIdx = m_history->size();
    67     m_curHistEntryIdx = m_history->size();
    80 
       
    81     m_historyMutex.unlock();
       
    82 }
    68 }
    83 
    69 
    84 
    70 
    85 void HistoryLineEdit::reset()
    71 void HistoryLineEdit::reset()
    86 {
    72 {
    87     // forget history
    73     // forget history
    88     m_historyMutex.lock();
       
    89 
       
    90     m_history->clear();
    74     m_history->clear();
    91     m_curHistEntryIdx = 0;
    75     m_curHistEntryIdx = 0;
    92 
       
    93     m_historyMutex.unlock();
       
    94 }
    76 }
    95 
    77 
    96 
    78 
    97 void HistoryLineEdit::navigateHistory(bool isGoingUp)
    79 void HistoryLineEdit::navigateHistory(bool isGoingUp)
    98 {
    80 {
    99     m_historyMutex.lock();
       
   100 
       
   101     // save possible changes to new entry
    81     // save possible changes to new entry
   102     if ((m_curHistEntryIdx >= m_history->size() ||
    82     if ((m_curHistEntryIdx >= m_history->size() ||
   103         (text() != m_history->at(m_curHistEntryIdx))))
    83         (text() != m_history->at(m_curHistEntryIdx))))
   104         {
    84         {
   105             rememberCurrentTextUnsynced();
    85             rememberCurrentText();
   106         }
    86         }
   107 
    87 
   108     if (isGoingUp)
    88     if (isGoingUp)
   109         m_curHistEntryIdx--;
    89         m_curHistEntryIdx--;
   110     else
    90     else
   123     }
   103     }
   124     // if Idx below 0
   104     // if Idx below 0
   125     else
   105     else
   126         m_curHistEntryIdx = 0;
   106         m_curHistEntryIdx = 0;
   127 
   107 
   128 
       
   129     m_historyMutex.unlock();
       
   130 }
   108 }
   131 
   109 
   132 
   110 
   133 void HistoryLineEdit::keyPressEvent(QKeyEvent * event)
   111 void HistoryLineEdit::keyPressEvent(QKeyEvent * event)
   134 {
   112 {