]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiSelectionManager.cpp
On Linux show in crash message box the backtrace
[lyx.git] / src / frontends / qt4 / GuiSelectionManager.cpp
index b39f2a79d8fdd30e58a44c622080b61ce5becb41..d3d2b01f410f9204cfb9054e33808411b88f973a 100644 (file)
 #undef ControlModifier
 #endif
 
+#ifdef FocusIn
+#undef FocusIn
+#endif
+
 
 namespace lyx {
 namespace frontend {
@@ -45,15 +49,10 @@ GuiSelectionManager::GuiSelectionManager(
        QPushButton * down,
        QAbstractListModel * amod,
        QAbstractListModel * smod)
+  : availableLV(avail), selectedLV(sel), addPB(add), deletePB(del),
+               upPB(up), downPB(down), availableModel(amod), selectedModel(smod),
+    selectedHasFocus_(false)
 {
-       availableLV = avail;
-       selectedLV = sel;
-       addPB = add;
-       deletePB = del;
-       upPB = up;
-       downPB = down;
-       availableModel = amod;
-       selectedModel = smod;
        
        selectedLV->setModel(smod);
        availableLV->setModel(amod);
@@ -225,8 +224,10 @@ void GuiSelectionManager::selectedChanged(const QModelIndex & idx, const QModelI
 bool GuiSelectionManager::insertRowToSelected(int i, 
                QMap<int, QVariant> const & itemData)
 {
-       if (i <= -1 || i > selectedModel->rowCount())
-               return false;
+       if (i <= -1)
+               i = 0;
+       if (i > selectedModel->rowCount())
+               i = selectedModel->rowCount();
        if (!selectedModel->insertRow(i))
                return false;
        return selectedModel->setItemData(selectedModel->index(i), itemData);
@@ -281,7 +282,11 @@ void GuiSelectionManager::deletePB_clicked()
 
 void GuiSelectionManager::upPB_clicked()
 {
-       QModelIndex idx = selectedLV->currentIndex();
+       QModelIndexList selIdx =
+               selectedLV->selectionModel()->selectedIndexes();
+       if (selIdx.isEmpty())
+               return;
+       QModelIndex idx = selIdx.first();
 
        int const pos = idx.row();
        if (pos <= 0)
@@ -302,7 +307,11 @@ void GuiSelectionManager::upPB_clicked()
 
 void GuiSelectionManager::downPB_clicked()
 {
-       QModelIndex idx = selectedLV->currentIndex();
+       QModelIndexList selIdx =
+               selectedLV->selectionModel()->selectedIndexes();
+       if (selIdx.isEmpty())
+               return;
+       QModelIndex idx = selIdx.first();
 
        int const pos = idx.row();
        if (pos >= selectedModel->rowCount() - 1)
@@ -346,12 +355,12 @@ bool GuiSelectionManager::eventFilter(QObject * obj, QEvent * event)
                        // This is designed to work both with the main enter key
                        // and the one on the numeric keypad.
                        if (keyPressed == Qt::Key_Enter || keyPressed == Qt::Key_Return) {
-                               if (!keyModifiers)
-                                       addPB_clicked();
-                               else if (keyModifiers == Qt::ControlModifier ||
-                                               keyModifiers == Qt::KeypadModifier  ||
-                                               keyModifiers == (Qt::ControlModifier | Qt::KeypadModifier)) {
-                                       if (addPB->isEnabled()) {
+                               if (addPB->isEnabled()) {
+                                       if (!keyModifiers) {
+                                               addPB_clicked();
+                                       } else if (keyModifiers == Qt::ControlModifier || 
+                                                 keyModifiers == Qt::KeypadModifier  ||
+                                                 keyModifiers == (Qt::ControlModifier | Qt::KeypadModifier)) {
                                                addPB_clicked();
                                                okHook(); //signal
                                        }