From 16768d5474de2f5fac9e53eda3e24fe4de4ed046 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Fri, 3 May 2019 15:28:02 +0200 Subject: [PATCH] dbhub: Respect the order of the licence list and remove "Unspecified" Respect the suggested order of the licences as provided by the dbhub.io server instead of sorting them alphabetically by their internal key. Also remove the hard-coded "Unspecified" licence option because the dbhub.io server provided its own "No licence specified" option. --- src/RemoteDatabase.cpp | 14 +++++++++----- src/RemoteDatabase.h | 2 +- src/RemotePushDialog.cpp | 5 ++--- src/RemotePushDialog.h | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/RemoteDatabase.cpp b/src/RemoteDatabase.cpp index 5d45bada..1d7656c4 100644 --- a/src/RemoteDatabase.cpp +++ b/src/RemoteDatabase.cpp @@ -199,13 +199,17 @@ void RemoteDatabase::gotReply(QNetworkReply* reply) if(obj.is_discarded() || !obj.is_object()) break; - // Parse data and build licence map (short name -> long name) - std::map licences; + // Parse data and build ordered licence map: order -> (short name, long name) + std::map> licences; for(auto it=obj.cbegin();it!=obj.cend();++it) - licences.insert({it.key(), it.value()["full_name"]}); + licences.insert({it.value()["order"], {it.key(), it.value()["full_name"]}}); - // Send licence map to anyone who's interested - emit gotLicenceList(licences); + // Convert the map into an ordered vector and send it to anyone who's interested + std::vector> licence_list; + std::transform(licences.begin(), licences.end(), std::back_inserter(licence_list), [](const std::pair>& it) { + return it.second; + }); + emit gotLicenceList(licence_list); break; } case RequestTypeBranchList: diff --git a/src/RemoteDatabase.h b/src/RemoteDatabase.h index 0d536271..f013a7d7 100644 --- a/src/RemoteDatabase.h +++ b/src/RemoteDatabase.h @@ -63,7 +63,7 @@ signals: // a directory listing or the licence list. void gotDirList(QString json, QVariant userdata); void gotCurrentVersion(QString version, QString url); - void gotLicenceList(std::map licences); + void gotLicenceList(std::vector> licences); void gotBranchList(std::vector branches, std::string default_branch); // The uploadFinished() signal is emitted when a push() call is finished, i.e. a database upload has completed. diff --git a/src/RemotePushDialog.cpp b/src/RemotePushDialog.cpp index 7245a7e7..8ab67e82 100644 --- a/src/RemotePushDialog.cpp +++ b/src/RemotePushDialog.cpp @@ -104,11 +104,10 @@ bool RemotePushDialog::forcePush() const return ui->checkForce->isChecked(); } -void RemotePushDialog::fillInLicences(const std::map& licences) +void RemotePushDialog::fillInLicences(const std::vector>& licences) { - // Clear licence list and add default item for unspecified licence + // Clear licence list ui->comboLicence->clear(); - ui->comboLicence->addItem(tr("Unspecified"), QString()); // Parse licence list and fill combo box. Show the full name to the user and use the short name as user data. for(const auto& it : licences) diff --git a/src/RemotePushDialog.h b/src/RemotePushDialog.h index 3b1b071f..add056fb 100644 --- a/src/RemotePushDialog.h +++ b/src/RemotePushDialog.h @@ -45,7 +45,7 @@ protected slots: void reloadBranchList(); - void fillInLicences(const std::map& licences); + void fillInLicences(const std::vector>& licences); void fillInBranches(const std::vector& branches, const std::string& default_branch); };