]> git.lyx.org Git - features.git/blobdiff - src/frontends/qt4/TocWidget.cpp
cosmetics; compile fix
[features.git] / src / frontends / qt4 / TocWidget.cpp
index d46a7d3a65c58799809fcba16129094319e0154b..eb3fc493314bdcff8b4d1af1fdd177632371a736 100644 (file)
@@ -21,6 +21,7 @@
 #include "LyXFunc.h"
 
 #include "support/debug.h"
+#include "support/lassert.h"
 
 #include <QHeaderView>
 #include <QTimer>
@@ -89,17 +90,18 @@ void TocWidget::on_updateTB_clicked()
        gui_view_.tocModels().updateBackend();
 }
 
+
 /* FIXME (Ugras 17/11/06):
-I have implemented a getIndexDepth function to get the model indices. In my
+I have implemented a indexDepth function to get the model indices. In my
 opinion, somebody should derive a new qvariant class for tocModelItem
-which saves the string data and depth information. that will save the
-depth calculation.
-*/
-int TocWidget::getIndexDepth(QModelIndex const & index, int depth)
+which saves the string data and depth information. That will save the
+depth calculation.  */
+
+static int indexDepth(QModelIndex const & index, int depth = -1)
 {
        ++depth;
-       return (index.parent() == QModelIndex())
-               ? depth : getIndexDepth(index.parent(),depth);
+       return index.parent() == QModelIndex()
+               ? depth : indexDepth(index.parent(), depth);
 }
 
 
@@ -127,14 +129,14 @@ void TocWidget::setTreeDepth(int depth)
        int size = indices.size();
        for (int i = 0; i < size; i++) {
                QModelIndex index = indices[i];
-               tocTV->setExpanded(index, getIndexDepth(index) < depth_);
+               tocTV->setExpanded(index, indexDepth(index) < depth_);
        }
 }
 
 
-void TocWidget::on_typeCO_currentIndexChanged(int value)
+void TocWidget::on_typeCO_currentIndexChanged(int)
 {
-       setTocModel(value);
+       updateView();
        gui_view_.setFocus();
 }
 
@@ -209,6 +211,7 @@ void TocWidget::enableControls(bool enable)
 void TocWidget::updateView()
 {
        LYXERR(Debug::GUI, "In TocWidget::updateView()");
+       setTocModel();
        setTreeDepth(depth_);
        select(gui_view_.tocModels().currentIndex(typeCO->currentIndex()));
 }
@@ -219,12 +222,14 @@ void TocWidget::init(QString const & str)
        QStringList const & type_names = gui_view_.tocModels().typeNames();
        if (type_names.isEmpty()) {
                enableControls(false);
-               typeCO->clear();
+               typeCO->setEnabled(false);
                tocTV->setModel(new QStandardItemModel);
-               tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers);
+               tocTV->setEnabled(false);
                return;
        }
 
+       typeCO->setEnabled(true);
+       tocTV->setEnabled(true);
        int selected_type = gui_view_.tocModels().decodeType(str);
 
        QString const current_text = typeCO->currentText();
@@ -244,34 +249,30 @@ void TocWidget::init(QString const & str)
 
        typeCO->blockSignals(false);
 
-       setTocModel(typeCO->currentIndex());
+       // setTocModel produce QTreeView reset and setting depth again
+       // is needed. That must be done after all Qt updates are processed.
+       QTimer::singleShot(0, this, SLOT(updateView()));
 }
 
 
-void TocWidget::setTocModel(size_t type)
+void TocWidget::setTocModel()
 {
-       bool controls_enabled = false;
-       QStandardItemModel * toc_model = gui_view_.tocModels().model(type);
-       if (toc_model) {
-               controls_enabled = toc_model->rowCount() > 0;
+       int const toc_type = typeCO->currentIndex();
+       QStandardItemModel * toc_model = gui_view_.tocModels().model(toc_type);
+       LASSERT(toc_model, return);
+       
+       if (tocTV->model() != toc_model) {
                tocTV->setModel(toc_model);
                tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers);
-               LYXERR(Debug::GUI, "tocModel()->rowCount "
-                       << toc_model->rowCount()
-                       << "\nform_->tocModel()->columnCount "
-                       << toc_model->columnCount());
        }
 
+       bool controls_enabled = toc_model->rowCount() > 0;;
        enableControls(controls_enabled);
 
        if (controls_enabled) {
-               depthSL->setMaximum(gui_view_.tocModels().depth(type));
+               depthSL->setMaximum(gui_view_.tocModels().depth(toc_type));
                depthSL->setValue(depth_);
        }
-
-       // setTocModel produce QTreeView reset and setting depth again
-       // is needed. That must be done after all Qt updates are processed.
-       QTimer::singleShot(0, this, SLOT(updateView()));
 }
 
 } // namespace frontend