]> git.lyx.org Git - features.git/blobdiff - src/frontends/qt/GuiCitation.cpp
#10571 improved handling of WM's signal when switching from or to full-screen window
[features.git] / src / frontends / qt / GuiCitation.cpp
index 196ec44d2b7b5bb6c26c022353082e03e62edf61..7a554e77648c97f40f1d4cec08bb87cbe447862e 100644 (file)
@@ -284,12 +284,7 @@ void GuiCitation::updateFormatting(CitationStyle const & currentStyle)
 
        int const rows = selectedLV->model()->rowCount();
 
-       bool const qualified = currentStyle.hasQualifiedList
-               && (rows > 1
-                   || !params_["pretextlist"].empty()
-                   || !params_["posttextlist"].empty()
-                   || !getPreTexts().empty()
-                   || !getPostTexts().empty());
+       bool const qualified = currentStyle.hasQualifiedList && rows > 0;
 
        selectedLV->horizontalHeader()->setVisible(qualified);
        selectedLV->setColumnHidden(0, !qualified);
@@ -368,6 +363,8 @@ void GuiCitation::updateFormatting(CitationStyle const & currentStyle)
                availableLV->setToolTip(qt_("All references available for citing.\n"
                                            "To add the selected one, hit Add, press Enter or double-click.\n"
                                            "Hit Ctrl-Enter to add and close the dialog."));
+       // With qualified citation lists, it makes sense to add the same key multiple times
+       selectionManager->allowMultiSelection(currentStyle.hasQualifiedList);
 }
 
 
@@ -389,6 +386,8 @@ void GuiCitation::updateStyles(BiblioInfo const & bi)
        int curr = selectedLV->model()->rowCount() - 1;
 
        if (curr < 0 || selected_keys.empty()) {
+               last_chosen_style_ =
+                       citationStyleCO->itemData(citationStyleCO->currentIndex()).toString();
                citationStyleCO->clear();
                citationStyleCO->setEnabled(false);
                citationStyleLA->setEnabled(false);
@@ -411,7 +410,10 @@ void GuiCitation::updateStyles(BiblioInfo const & bi)
        // save old style selection
        QString const curdata =
                citationStyleCO->itemData(citationStyleCO->currentIndex()).toString();
-       QString const olddata = (curdata.isEmpty()) ? style_ : curdata;
+       QString const olddata = (curdata.isEmpty()) ?
+               (last_chosen_style_.isEmpty() ? style_ : last_chosen_style_): curdata;
+       // reset this
+       last_chosen_style_.clear();
        citationStyleCO->clear();
        BiblioInfo::CiteStringMap::const_iterator cit = sty.begin();
        BiblioInfo::CiteStringMap::const_iterator end = sty.end();
@@ -690,8 +692,10 @@ QStringList GuiCitation::selectedKeys()
 }
 
 
-void GuiCitation::setPreTexts(vector<docstring> const m)
+void GuiCitation::setPreTexts(vector<docstring> const m)
 {
+       // account for multiple use of the same keys
+       QList<QModelIndex> handled;
        for (docstring const & s: m) {
                QStandardItem * si = new QStandardItem();
                docstring key;
@@ -699,11 +703,17 @@ void GuiCitation::setPreTexts(vector<docstring> const m)
                si->setData(toqstr(pre));
                si->setText(toqstr(pre));
                QModelIndexList qmil =
-                               selected_model_.match(selected_model_.index(0, 1),
-                                                    Qt::DisplayRole, toqstr(key), 1,
-                                                    Qt::MatchFlags(Qt::MatchExactly | Qt::MatchWrap));
-               if (!qmil.empty())
-                       selected_model_.setItem(qmil.front().row(), 0, si);
+                       selected_model_.match(selected_model_.index(0, 1),
+                                            Qt::DisplayRole, toqstr(key), -1,
+                                            Qt::MatchFlags(Qt::MatchExactly | Qt::MatchWrap));
+               for (int i = 0; i < qmil.size(); ++i){
+                       QModelIndex idx = qmil[i];
+                       if (!handled.contains(idx)) {
+                               selected_model_.setItem(idx.row(), 0, si);
+                               handled.append(idx);
+                               break;
+                       }
+               }
        }
 }
 
@@ -714,15 +724,17 @@ vector<docstring> GuiCitation::getPreTexts()
        for (int i = 0; i != selected_model_.rowCount(); ++i) {
                QStandardItem const * key = selected_model_.item(i, 1);
                QStandardItem const * pre = selected_model_.item(i, 0);
-               if (key && pre && !key->text().isEmpty() && !pre->text().isEmpty())
+               if (key && pre && !key->text().isEmpty())
                        res.push_back(qstring_to_ucs4(key->text()) + " " + qstring_to_ucs4(pre->text()));
        }
        return res;
 }
 
 
-void GuiCitation::setPostTexts(vector<docstring> const m)
+void GuiCitation::setPostTexts(vector<docstring> const m)
 {
+       // account for multiple use of the same keys
+       QList<QModelIndex> handled;
        for (docstring const & s: m) {
                QStandardItem * si = new QStandardItem();
                docstring key;
@@ -730,11 +742,17 @@ void GuiCitation::setPostTexts(vector<docstring> const m)
                si->setData(toqstr(post));
                si->setText(toqstr(post));
                QModelIndexList qmil =
-                               selected_model_.match(selected_model_.index(0, 1),
-                                                    Qt::DisplayRole, toqstr(key), 1,
-                                                    Qt::MatchFlags(Qt::MatchExactly | Qt::MatchWrap));
-               if (!qmil.empty())
-                       selected_model_.setItem(qmil.front().row(), 2, si);
+                       selected_model_.match(selected_model_.index(0, 1),
+                                            Qt::DisplayRole, toqstr(key), -1,
+                                            Qt::MatchFlags(Qt::MatchExactly | Qt::MatchWrap));
+               for (int i = 0; i < qmil.size(); ++i){
+                       QModelIndex idx = qmil[i];
+                       if (!handled.contains(idx)) {
+                               selected_model_.setItem(idx.row(), 2, si);
+                               handled.append(idx);
+                               break;
+                       }
+               }
        }
 }
 
@@ -745,7 +763,7 @@ vector<docstring> GuiCitation::getPostTexts()
        for (int i = 0; i != selected_model_.rowCount(); ++i) {
                QStandardItem const * key = selected_model_.item(i, 1);
                QStandardItem const * post = selected_model_.item(i, 2);
-               if (key && post && !key->text().isEmpty() && !post->text().isEmpty())
+               if (key && post && !key->text().isEmpty())
                        res.push_back(qstring_to_ucs4(key->text()) + " " + qstring_to_ucs4(post->text()));
        }
        return res;
@@ -892,17 +910,17 @@ BiblioInfo::CiteStringMap GuiCitation::citationStyles(BiblioInfo const & bi, siz
                && (selectedLV->model()->rowCount() > 1
                    || !pretexts.empty()
                    || !posttexts.empty());
-       std::map<docstring, docstring> pres;
+       vector<pair<docstring, docstring>> pres;
        for (docstring const & s: pretexts) {
                docstring key;
                docstring val = split(s, key, ' ');
-               pres[key] = val;
+               pres.push_back(make_pair(key, val));
        }
-       std::map<docstring, docstring> posts;
+       vector<pair<docstring, docstring>> posts;
        for (docstring const & s: posttexts) {
                docstring key;
                docstring val = split(s, key, ' ');
-               posts[key] = val;
+               posts.push_back(make_pair(key, val));
        }
        CiteItem ci;
        ci.textBefore = qstring_to_ucs4(textBeforeED->text());