Lars Gullik Bjønnes wrote:

A space after '&' as well please.

Also; can list be a const reference?

it can be a const reference --> new patch attached - now really

Does the enableButtons() have a default arg?
If that is our own function I think it should be removed so that have
to use true/false explictly. (Should not become part of this patch of
course.)


enableButtons() has the dafault arg true. I can create another patch for that.

Bernhard

Index: QTocDialog.C
===================================================================
--- QTocDialog.C        (revision 17395)
+++ QTocDialog.C        (working copy)
@@ -140,9 +140,12 @@
 void QTocDialog::on_moveUpPB_clicked()
 {
        enableButtons(false);
-       QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
-       form_->goTo(index);
-       form_->outlineUp();
+       const QModelIndexList & list = 
tocTV->selectionModel()->selectedIndexes();
+       if (!list.isEmpty()) {
+               QModelIndex index = list[0];
+               form_->goTo(index);
+               form_->outlineUp();
+       }
        update();
 }
 
@@ -150,9 +153,12 @@
 void QTocDialog::on_moveDownPB_clicked()
 {
        enableButtons(false);
-       QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
-       form_->goTo(index);
-       form_->outlineDown();
+       const QModelIndexList & list = 
tocTV->selectionModel()->selectedIndexes();
+       if (!list.isEmpty()) {
+               QModelIndex index = list[0];
+               form_->goTo(index);
+               form_->outlineDown();
+       }
        update();
 }
 
@@ -160,9 +166,12 @@
 void QTocDialog::on_moveInPB_clicked()
 {
        enableButtons(false);
-       QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
-       form_->goTo(index);
-       form_->outlineIn();
+       const QModelIndexList & list = 
tocTV->selectionModel()->selectedIndexes();
+       if (!list.isEmpty()) {
+               QModelIndex index = list[0];
+               form_->goTo(index);
+               form_->outlineIn();
+       }
        update();
 }
 
@@ -170,9 +179,12 @@
 void QTocDialog::on_moveOutPB_clicked()
 {
        enableButtons(false);
-       QModelIndex index = tocTV->selectionModel()->selectedIndexes()[0];
-       form_->goTo(index);
-       form_->outlineOut();
+       const QModelIndexList & list = 
tocTV->selectionModel()->selectedIndexes();
+       if (!list.isEmpty()) {
+               QModelIndex index = list[0];
+               form_->goTo(index);
+               form_->outlineOut();
+       }
        update();
 }
 
@@ -217,7 +229,7 @@
 {
        QStringListModel * type_model = form_->typeModel();
        if (type_model->stringList().isEmpty()) {
-               enableButtons();
+               enableButtons(false);
                typeCO->setModel(type_model);
                tocTV->setModel(new QStandardItemModel);
                tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers);
@@ -228,19 +240,21 @@
        typeCO->setModel(type_model);
        typeCO->setCurrentIndex(form_->getType());
 
+       bool buttonsEnabled = false;
        if (form_->tocModel()) {
+               buttonsEnabled = form_->tocModel()->rowCount() > 0;
                tocTV->setModel(form_->tocModel());
                tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers);
        }
        // avoid flickering
-       tocTV-> setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
+       tocTV->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
        tocTV->showColumn(0);
        // hide the pointless QHeader for now
        // in the future, new columns may appear
        // like labels, bookmarks, etc...
        // tocTV->header()->hide();
        tocTV->header()->setVisible(false);
-       enableButtons();
+       enableButtons(buttonsEnabled);
 
        reconnectSelectionModel();
        depthSL->setEnabled(true);

Reply via email to