]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiSymbols.cpp
Enable OK/Apply buttons when resetting to class defaults.
[lyx.git] / src / frontends / qt4 / GuiSymbols.cpp
index cdfedee4e7b2b143b2cd89358db4cb593b046288..d08689cd3cc85fcddfce113ae913bf8ee138fe6b 100644 (file)
@@ -152,6 +152,7 @@ const int no_blocks = sizeof(unicode_blocks) / sizeof(UnicodeBlocks);
 QString getBlock(char_type c)
 {
        // store an educated guess for the next search
+       // 0 <= lastBlock < no_blocks
        // FIXME THREAD
        static int lastBlock = 0;
 
@@ -159,10 +160,6 @@ QString getBlock(char_type c)
        if (c < 0x7f)
                lastBlock = 0;
 
-       // off the end already
-       if (lastBlock == no_blocks)
-               return QString();
-
        // c falls into a covered area, and we can guess which
        if (c >= unicode_blocks[lastBlock].start
            && c <= unicode_blocks[lastBlock].end)
@@ -177,15 +174,25 @@ QString getBlock(char_type c)
        int i = 0;
        while (i < no_blocks && c > unicode_blocks[i].end)
                ++i;
+
        if (i == no_blocks)
                return QString();
+
+       if (c < unicode_blocks[i].start) {
+               // 0 < i < no_blocks
+               // cache the previous block for guessing next time
+               lastBlock = i - 1;
+               return QString();
+       }
+
+       // 0 <= i < no_blocks
+       // cache the last block for guessing next time
        lastBlock = i;
-       //LYXERR0("fail: " << int(c) << ' ' << lastBlock);
        return unicode_blocks[lastBlock].qname;
 }
 
 
-} // namespace anon
+} // namespace
 
 
 /////////////////////////////////////////////////////////////////////
@@ -198,7 +205,7 @@ class GuiSymbols::Model : public QAbstractListModel
 {
 public:
        Model(GuiSymbols * parent)
-               : QAbstractListModel(parent)
+               : QAbstractListModel(parent), encoding_(0)
        {}
 
        QModelIndex index(int row, int column, QModelIndex const &) const
@@ -256,10 +263,8 @@ public:
        void setSymbols(QList<char_type> const & symbols, Encoding const * encoding)
        {
                beginResetModel();
-               beginInsertRows(QModelIndex(), 0, symbols.size() - 1);
                symbols_ = symbols;
                encoding_ = encoding;
-               endInsertRows();
                endResetModel();
        }
 
@@ -420,8 +425,7 @@ void GuiSymbols::scrollToItem(QString const & category)
 
 void GuiSymbols::updateSymbolList(bool update_combo)
 {
-       QString category = categoryCO->currentText();
-       bool const nocategory = category.isEmpty();
+       QString const category = categoryCO->currentText();
        char_type range_start = 0x0000;
        char_type range_end = 0x110000;
        QList<char_type> s;
@@ -445,11 +449,9 @@ void GuiSymbols::updateSymbolList(bool update_combo)
                        }
        }
 
-       SymbolsList::const_iterator const end = symbols_.end();
        int numItem = 0;
-       for (SymbolsList::const_iterator it = symbols_.begin(); it != end; ++it) {
-               char_type c = *it;
-               if (!update_combo && !show_all && (c <= range_start || c >= range_end))
+       for (char_type c : symbols_) {
+               if (!update_combo && !show_all && (c < range_start || c > range_end))
                        continue;
                QChar::Category const cat = QChar::category(uint(c));
                // we do not want control or space characters
@@ -460,8 +462,6 @@ void GuiSymbols::updateSymbolList(bool update_combo)
                        s.append(c);
                if (update_combo) {
                        QString block = getBlock(c);
-                       if (category.isEmpty())
-                               category = block;
                        if (used_blocks.find(block) == used_blocks.end())
                                used_blocks[block] = numItem;
                }
@@ -479,10 +479,12 @@ void GuiSymbols::updateSymbolList(bool update_combo)
        int old = categoryCO->findText(category);
        if (old != -1)
                categoryCO->setCurrentIndex(old);
-       // update again in case the combo has not yet been filled
-       // on first cycle (at dialog initialization)
-       if (nocategory && !category.isEmpty())
-               updateSymbolList();
+       else if (update_combo) {
+               // restart with a non-empty block
+               // this happens when the encoding changes when moving the cursor
+               categoryCO->setCurrentIndex(0);
+               updateSymbolList(false);
+       }
 }