]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiSelectionManager.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / GuiSelectionManager.cpp
index 3b802081b6979443be9a5ecf20a683c0af313c86..9eeb5c96851c76d4b528bebbd6b8dd4e1f273d50 100644 (file)
@@ -49,7 +49,7 @@ GuiSelectionManager::GuiSelectionManager(QObject * parent,
                                          QPushButton * del,
                                          QPushButton * up,
                                          QPushButton * down,
-                                         QAbstractListModel * amod,
+                                         QAbstractItemModel * amod,
                                          QAbstractItemModel * smod,
                                          int const main_sel_col)
 : QObject(parent), availableLV(avail), selectedLV(sel),
@@ -71,9 +71,15 @@ GuiSelectionManager::GuiSelectionManager(QObject * parent,
        connect(availableLV->selectionModel(),
                SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
                this, SLOT(availableChanged(QItemSelection, QItemSelection)));
+       connect(availableLV->selectionModel(),
+               SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
+               this, SLOT(updateButtons()));
        connect(selectedLV->selectionModel(),
                SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
                this, SLOT(selectedChanged(QItemSelection, QItemSelection)));
+       connect(selectedLV->selectionModel(),
+               SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
+               this, SLOT(updateButtons()));
        connect(selectedLV->itemDelegate(), SIGNAL(commitData(QWidget*)),
                this, SLOT(selectedEdited()));
        connect(addPB, SIGNAL(clicked()),
@@ -101,9 +107,16 @@ void GuiSelectionManager::update()
 }
 
 
+void GuiSelectionManager::updateButtons()
+{
+       update();
+       updateHook();
+}
+
+
 QModelIndex GuiSelectionManager::getSelectedIndex(int const c) const
 {
-       QModelIndexList avail = availableLV->selectionModel()->selectedIndexes();
+       QModelIndexList avail = availableLV->selectionModel()->selectedRows(c);
        QModelIndexList sel   = selectedLV->selectionModel()->selectedRows(c);
        bool const have_avl = !avail.isEmpty();
        bool const have_sel = !sel.isEmpty();
@@ -293,18 +306,19 @@ void GuiSelectionManager::deletePB_clicked()
        if (selIdx.isEmpty())
                return;
        QModelIndex idx = selIdx.first();
-       selectedModel->removeRow(idx.row());
-       selectionChanged(); //signal
 
+       int const row = idx.row();
        int nrows = selectedLV->model()->rowCount();
-       if (idx.row() == nrows) //was last item on list
-               idx = idx.sibling(idx.row() - 1, idx.column());
 
-       if (nrows > 1)
-               selectedLV->setCurrentIndex(idx);
-       else if (nrows == 1)
+       selectedModel->removeRow(row);
+       selectionChanged(); //signal
+
+       // select previous item
+       if (nrows > 0)
+               selectedLV->setCurrentIndex(selectedLV->model()->index(row - 1, 0));
+       else if (nrows == 0)
                selectedLV->setCurrentIndex(selectedLV->model()->index(0, 0));
-       selectedHasFocus_ = (nrows > 0);
+       selectedHasFocus_ = (nrows > 1);
        updateHook();
 }