From e356721479acd0a356883a0802efcebb5a880346 Mon Sep 17 00:00:00 2001 From: Diogo Rodrigues Date: Fri, 5 Jan 2024 22:09:40 +0000 Subject: [PATCH 01/12] Improve desktop place page dialog Signed-off-by: Diogo Rodrigues --- qt/place_page_dialog.cpp | 433 ++++++++++++++++++++++++++++++--------- 1 file changed, 331 insertions(+), 102 deletions(-) diff --git a/qt/place_page_dialog.cpp b/qt/place_page_dialog.cpp index ef5afd1e9b..379b8d2bf5 100644 --- a/qt/place_page_dialog.cpp +++ b/qt/place_page_dialog.cpp @@ -3,6 +3,7 @@ #include "qt/qt_common/text_dialog.hpp" #include "map/place_page_info.hpp" +#include "indexer/validate_and_format_contacts.hpp" #include #include @@ -10,128 +11,356 @@ #include #include +#include +#include +#include +#include +#include #include +const int place_page_description_max_length = 500; +const int short_description_minimum_width = 390; + +class QHLine : public QFrame +{ +public: + QHLine(QWidget * parent = nullptr) : QFrame(parent) + { + setFrameShape(QFrame::HLine); + setFrameShadow(QFrame::Sunken); + } +}; + +std::string getShortDescription(std::string description) +{ + size_t paragraphStart = description.find("

"); + size_t paragraphEnd = description.find("

"); + if (paragraphStart == 0 && paragraphEnd != std::string::npos) + description = description.substr(3, paragraphEnd); + + if (description.length() > place_page_description_max_length) + { + description = description.substr(0, place_page_description_max_length-3) + "..."; + } + + return description; +} + PlacePageDialog::PlacePageDialog(QWidget * parent, place_page::Info const & info, search::ReverseGeocoder::Address const & address) : QDialog(parent) { - QGridLayout * grid = new QGridLayout(); - int row = 0; - - auto const addEntry = [grid, &row](std::string const & key, std::string const & value, bool isLink = false) - { - grid->addWidget(new QLabel(QString::fromStdString(key)), row, 0); - QLabel * label = new QLabel(QString::fromStdString(value)); - label->setTextInteractionFlags(Qt::TextSelectableByMouse); - if (isLink) - { - label->setOpenExternalLinks(true); - label->setTextInteractionFlags(Qt::TextBrowserInteraction); - label->setText(QString::fromStdString("" + value + "")); - } - grid->addWidget(label, row++, 1); - return label; - }; - - { - ms::LatLon const ll = info.GetLatLon(); - addEntry("lat, lon", strings::to_string_dac(ll.m_lat, 7) + ", " + strings::to_string_dac(ll.m_lon, 7)); - } - - addEntry("CountryId", info.GetCountryId()); - - auto const & title = info.GetTitle(); - if (!title.empty()) - addEntry("Title", title); - - if (auto const & subTitle = info.GetSubtitle(); !subTitle.empty()) - addEntry("Subtitle", subTitle); - - addEntry("Address", address.FormatAddress()); - - if (info.IsBookmark()) - { - grid->addWidget(new QLabel("Bookmark"), row, 0); - grid->addWidget(new QLabel("Yes"), row++, 1); - } - - if (info.IsMyPosition()) - { - grid->addWidget(new QLabel("MyPosition"), row, 0); - grid->addWidget(new QLabel("Yes"), row++, 1); - } - - if (info.HasApiUrl()) - { - grid->addWidget(new QLabel("Api URL"), row, 0); - grid->addWidget(new QLabel(QString::fromStdString(info.GetApiUrl())), row++, 1); - } - - if (info.IsFeature()) - { - addEntry("Feature ID", DebugPrint(info.GetID())); - addEntry("Raw Types", DebugPrint(info.GetTypes())); - } - - auto const layer = info.GetLayer(); - if (layer != feature::LAYER_EMPTY) - addEntry("Layer", std::to_string(layer)); - using PropID = osm::MapObject::MetadataID; - if (auto cuisines = info.FormatCuisines(); !cuisines.empty()) - addEntry(DebugPrint(PropID::FMD_CUISINE), cuisines); + auto const & title = info.GetTitle(); - QDialogButtonBox * dbb = new QDialogButtonBox(); - QPushButton * closeButton = new QPushButton("Close"); - closeButton->setDefault(true); - connect(closeButton, &QAbstractButton::clicked, this, &PlacePageDialog::OnClose); - dbb->addButton(closeButton, QDialogButtonBox::RejectRole); - - if (info.ShouldShowEditPlace()) + QVBoxLayout * layout = new QVBoxLayout(); { - QPushButton * editButton = new QPushButton("Edit Place"); - connect(editButton, &QAbstractButton::clicked, this, &PlacePageDialog::OnEdit); - dbb->addButton(editButton, QDialogButtonBox::AcceptRole); + QVBoxLayout * header = new QVBoxLayout(); + + if (!title.empty()) + header->addWidget(new QLabel(QString::fromStdString("

" + title + "

"))); + + if (auto subTitle = info.GetSubtitle(); !subTitle.empty()) + header->addWidget(new QLabel(QString::fromStdString(subTitle))); + + if (auto addressFormatted = address.FormatAddress(); !addressFormatted.empty()) + header->addWidget(new QLabel(QString::fromStdString(addressFormatted))); + + layout->addLayout(header); } - if (auto const & descr = info.GetWikiDescription(); !descr.empty()) { - QPushButton * wikiButton = new QPushButton("Wiki Description"); - connect(wikiButton, &QAbstractButton::clicked, this, [this, descr, title]() - { - auto textDialog = TextDialog(this, QString::fromStdString(descr), QString::fromStdString("Wikipedia: " + title)); - textDialog.exec(); - }); - dbb->addButton(wikiButton, QDialogButtonBox::ActionRole); + QHLine * line = new QHLine(); + layout->addWidget(line); } - info.ForEachMetadataReadable([&addEntry](PropID id, std::string const & value) { - bool isLink = false; - switch (id) + QGridLayout * data = new QGridLayout(); + + int row = 0; + + auto const addEntry = [data, &row](std::string const & key, std::string const & value, bool isLink = false) { - case PropID::FMD_EMAIL: - case PropID::FMD_WEBSITE: - case PropID::FMD_CONTACT_FACEBOOK: - case PropID::FMD_CONTACT_INSTAGRAM: - case PropID::FMD_CONTACT_TWITTER: - case PropID::FMD_CONTACT_VK: - case PropID::FMD_CONTACT_LINE: - case PropID::FMD_WIKIPEDIA: - case PropID::FMD_WIKIMEDIA_COMMONS: - isLink = true; - break; - default: - break; + data->addWidget(new QLabel(QString::fromStdString(key)), row, 0); + QLabel * label = new QLabel(QString::fromStdString(value)); + label->setTextInteractionFlags(Qt::TextSelectableByMouse); + if (isLink) + { + label->setOpenExternalLinks(true); + label->setTextInteractionFlags(Qt::TextBrowserInteraction); + label->setText(QString::fromStdString("" + value + "")); + } + data->addWidget(label, row++, 1); + return label; + }; + + if (info.IsBookmark()) + { + addEntry("Bookmark", "Yes"); } - addEntry(DebugPrint(id), value, isLink); - }); + // Description + + if (auto description = info.GetWikiDescription(); !description.empty()) + { + // Wikipedia fragment - grid->addWidget(dbb); - setLayout(grid); + QLabel * name = new QLabel("Wikipedia"); + auto const & wikipedia = info.GetMetadata(feature::Metadata::EType::FMD_WIKIPEDIA); + if (!wikipedia.empty()){ + name->setOpenExternalLinks(true); + name->setTextInteractionFlags(Qt::TextBrowserInteraction); + name->setText(QString::fromStdString("Wikipedia")); + } + + data->addWidget(new QLabel("Wikipedia"), row, 0); + data->addWidget(name, row++, 1); + + auto descriptionShort = getShortDescription(description); + + QLabel * value = new QLabel(QString::fromStdString(descriptionShort)); + value->setWordWrap(true); + value->setMinimumWidth(short_description_minimum_width); + + data->addWidget(value, row++, 0, 1, 2); + + QPushButton * wikiButton = new QPushButton("More...", value); + connect(wikiButton, &QAbstractButton::clicked, this, [this, description, title]() + { + auto textDialog = TextDialog(this, QString::fromStdString(description), QString::fromStdString("Wikipedia: " + title)); + textDialog.exec(); + }); + + data->addWidget(wikiButton, row++, 0, 1, 2, Qt::AlignLeft); + } + + // Opening hours fragment + if (auto openingHours = info.GetOpeningHours(); !openingHours.empty()) + addEntry("Opening hours", std::string(openingHours)); + + // Cuisine fragment + if (auto cuisines = info.FormatCuisines(); !cuisines.empty()) + addEntry("Cuisine", cuisines); + + // Entrance fragment + // TODO + + // Phone fragment + if (auto phoneNumber = info.GetMetadata(feature::Metadata::EType::FMD_PHONE_NUMBER); !phoneNumber.empty()){ + data->addWidget(new QLabel("Phone"), row, 0); + + QLabel * value = new QLabel(QString::fromStdString("" + std::string(phoneNumber) + "")); + value->setOpenExternalLinks(true); + + data->addWidget(value, row++, 1); + } + + // Operator fragment + if (auto operatorName = info.GetMetadata(feature::Metadata::EType::FMD_OPERATOR); !operatorName.empty()) + addEntry("Operator", std::string(operatorName)); + + // Wifi fragment + if (info.HasWifi()){ + addEntry("Wi-Fi", "Yes"); + } + + // Links fragment + if (auto website = info.GetMetadata(feature::Metadata::EType::FMD_WEBSITE); !website.empty()) + addEntry("Website", std::string(website), true); + + if (auto email = info.GetMetadata(feature::Metadata::EType::FMD_EMAIL); !email.empty()){ + data->addWidget(new QLabel("Email"), row, 0); + + QLabel * value = new QLabel(QString::fromStdString("" + std::string(email) + "")); + value->setOpenExternalLinks(true); + + data->addWidget(value, row++, 1); + } + + if (auto facebook = info.GetMetadata(feature::Metadata::EType::FMD_CONTACT_FACEBOOK); !facebook.empty()){ + data->addWidget(new QLabel("Facebook"), row, 0); + + QLabel * value = new QLabel(QString::fromStdString("" + std::string(facebook) + "")); + value->setOpenExternalLinks(true); + value->setTextInteractionFlags(Qt::TextBrowserInteraction); + + data->addWidget(value, row++, 1); + } + + if (auto instagram = info.GetMetadata(feature::Metadata::EType::FMD_CONTACT_INSTAGRAM); !instagram.empty()){ + data->addWidget(new QLabel("Instagram"), row, 0); + + QLabel * value = new QLabel(QString::fromStdString("" + std::string(instagram) + "")); + value->setOpenExternalLinks(true); + value->setTextInteractionFlags(Qt::TextBrowserInteraction); + + data->addWidget(value, row++, 1); + } + + if (auto twitter = info.GetMetadata(feature::Metadata::EType::FMD_CONTACT_TWITTER); !twitter.empty()){ + data->addWidget(new QLabel("Twitter"), row, 0); + + QLabel * value = new QLabel(QString::fromStdString("" + std::string(twitter) + "")); + value->setOpenExternalLinks(true); + value->setTextInteractionFlags(Qt::TextBrowserInteraction); + + data->addWidget(value, row++, 1); + } + + if (auto vk = info.GetMetadata(feature::Metadata::EType::FMD_CONTACT_VK); !vk.empty()){ + data->addWidget(new QLabel("VK"), row, 0); + + QLabel * value = new QLabel(QString::fromStdString("" + std::string(vk) + "")); + value->setOpenExternalLinks(true); + value->setTextInteractionFlags(Qt::TextBrowserInteraction); + + data->addWidget(value, row++, 1); + } + + if (auto line = info.GetMetadata(feature::Metadata::EType::FMD_CONTACT_LINE); !line.empty()){ + data->addWidget(new QLabel("Line"), row, 0); + + QLabel * value = new QLabel(QString::fromStdString("" + std::string(line) + "")); + value->setOpenExternalLinks(true); + value->setTextInteractionFlags(Qt::TextBrowserInteraction); + + data->addWidget(value, row++, 1); + } + + if (auto wikimedia_commons = info.GetMetadata(feature::Metadata::EType::FMD_WIKIMEDIA_COMMONS); !wikimedia_commons.empty()){ + data->addWidget(new QLabel("Wikimedia Commons"), row, 0); + + QLabel * value = new QLabel(QString::fromStdString("Wikimedia Commons")); + value->setOpenExternalLinks(true); + value->setTextInteractionFlags(Qt::TextBrowserInteraction); + + data->addWidget(value, row++, 1); + } + + // Level fragment + if (auto level = info.GetMetadata(feature::Metadata::EType::FMD_LEVEL); !level.empty()){ + addEntry("Level", std::string(level)); + } + + // ATM fragment + if (info.HasAtm()){ + addEntry("ATM", "Yes"); + } + + // Latlon fragment + + { + ms::LatLon const ll = info.GetLatLon(); + addEntry("lat, lon", strings::to_string_dac(ll.m_lat, 7) + ", " + strings::to_string_dac(ll.m_lon, 7)); + } + + layout->addLayout(data); + } + + { + QHLine * line = new QHLine(); + layout->addWidget(line); + } + + { + QDialogButtonBox * dbb = new QDialogButtonBox(); + + if (info.ShouldShowEditPlace()) + { + QPushButton * editButton = new QPushButton("Edit Place"); + connect(editButton, &QAbstractButton::clicked, this, &PlacePageDialog::OnEdit); + dbb->addButton(editButton, QDialogButtonBox::ActionRole); + } + + // Advanced + { + QPushButton * advancedButton = new QPushButton("Advanced"); + connect(advancedButton, &QAbstractButton::clicked, this, [this, info]() + { + auto dialog = QDialog(this); + + QGridLayout * grid = new QGridLayout(&dialog); + + int row = 0; + + auto const addEntry = [grid, &row](std::string const & key, std::string const & value, bool isLink = false) + { + grid->addWidget(new QLabel(QString::fromStdString(key)), row, 0); + QLabel * label = new QLabel(QString::fromStdString(value)); + label->setTextInteractionFlags(Qt::TextSelectableByMouse); + if (isLink) + { + label->setOpenExternalLinks(true); + label->setTextInteractionFlags(Qt::TextBrowserInteraction); + label->setText(QString::fromStdString("" + value + "")); + } + grid->addWidget(label, row++, 1); + return label; + }; + + if (info.IsMyPosition()) + { + grid->addWidget(new QLabel("MyPosition"), row, 0); + grid->addWidget(new QLabel("Yes"), row++, 1); + } + + if (info.HasApiUrl()) + { + grid->addWidget(new QLabel("Api URL"), row, 0); + grid->addWidget(new QLabel(QString::fromStdString(info.GetApiUrl())), row++, 1); + } + + addEntry("CountryId", info.GetCountryId()); + + if (info.IsFeature()) + { + addEntry("Feature ID", DebugPrint(info.GetID())); + addEntry("Raw Types", DebugPrint(info.GetTypes())); + } + + auto const layer = info.GetLayer(); + if (layer != feature::LAYER_EMPTY) + addEntry("Layer", std::to_string(layer)); + + QHLine * line = new QHLine(); + grid->addWidget(line, row++, 0, 1, 2); + + grid->addWidget(new QLabel("Metadata"), row++, 0, 1, 2); + + info.ForEachMetadataReadable([&addEntry](PropID id, std::string const & value) + { + bool isLink = false; + switch (id) + { + case PropID::FMD_EMAIL: + case PropID::FMD_WEBSITE: + case PropID::FMD_CONTACT_FACEBOOK: + case PropID::FMD_CONTACT_INSTAGRAM: + case PropID::FMD_CONTACT_TWITTER: + case PropID::FMD_CONTACT_VK: + case PropID::FMD_CONTACT_LINE: + case PropID::FMD_WIKIPEDIA: + case PropID::FMD_WIKIMEDIA_COMMONS: + isLink = true; + break; + default: + break; + } + + addEntry(DebugPrint(id), value, isLink); + }); + + dialog.exec(); + }); + + dbb->addButton(advancedButton, QDialogButtonBox::AcceptRole); + } + + layout->addWidget(dbb, Qt::AlignCenter); + } + + setLayout(layout); auto const ppTitle = std::string("Place Page") + (info.IsBookmark() ? " (bookmarked)" : ""); setWindowTitle(ppTitle.c_str()); -- 2.45.3 From dab4b88a111a24c97b63937d3df9068f24638780 Mon Sep 17 00:00:00 2001 From: Diogo Rodrigues Date: Sat, 20 Jan 2024 14:06:53 +0000 Subject: [PATCH 02/12] nit Signed-off-by: Diogo Rodrigues --- indexer/map_object.hpp | 21 +++++ qt/place_page_dialog.cpp | 175 ++++++++++++++++++++------------------- 2 files changed, 111 insertions(+), 85 deletions(-) diff --git a/indexer/map_object.hpp b/indexer/map_object.hpp index 98e912c659..2c5ed62891 100644 --- a/indexer/map_object.hpp +++ b/indexer/map_object.hpp @@ -44,6 +44,27 @@ public: std::string_view GetMetadata(MetadataID type) const; + bool HasMetadataReadable() const + { + bool has = false; + m_metadata.ForEach([&has](MetadataID id, std::string const & value) + { + switch (id) + { + case MetadataID::FMD_WIKIPEDIA: + case MetadataID::FMD_WIKIMEDIA_COMMONS: + case MetadataID::FMD_DESCRIPTION: + case MetadataID::FMD_CUSTOM_IDS: + case MetadataID::FMD_PRICE_RATES: + case MetadataID::FMD_RATINGS: + has = true; + break; + default: break; + } + }); + return has; + } + template void ForEachMetadataReadable(FnT && fn) const { m_metadata.ForEach([&fn](MetadataID id, std::string const & value) diff --git a/qt/place_page_dialog.cpp b/qt/place_page_dialog.cpp index 379b8d2bf5..209b37f0d8 100644 --- a/qt/place_page_dialog.cpp +++ b/qt/place_page_dialog.cpp @@ -252,12 +252,96 @@ PlacePageDialog::PlacePageDialog(QWidget * parent, place_page::Info const & info { ms::LatLon const ll = info.GetLatLon(); - addEntry("lat, lon", strings::to_string_dac(ll.m_lat, 7) + ", " + strings::to_string_dac(ll.m_lon, 7)); + addEntry("Coordinates", strings::to_string_dac(ll.m_lat, 7) + ", " + strings::to_string_dac(ll.m_lon, 7)); } layout->addLayout(data); } + // Advanced +#ifdef DEBUG + { + { + QHLine * line = new QHLine(); + layout->addWidget(line); + } + + layout->addWidget(new QLabel("Advanced")); + + QGridLayout * grid = new QGridLayout(); + + int row = 0; + + auto const addEntry = [grid, &row](std::string const & key, std::string const & value, bool isLink = false) + { + grid->addWidget(new QLabel(QString::fromStdString(key)), row, 0); + QLabel * label = new QLabel(QString::fromStdString(value)); + label->setTextInteractionFlags(Qt::TextSelectableByMouse); + if (isLink) + { + label->setOpenExternalLinks(true); + label->setTextInteractionFlags(Qt::TextBrowserInteraction); + label->setText(QString::fromStdString("" + value + "")); + } + grid->addWidget(label, row++, 1); + return label; + }; + + if (info.IsMyPosition()) + { + grid->addWidget(new QLabel("MyPosition"), row, 0); + grid->addWidget(new QLabel("Yes"), row++, 1); + } + + if (info.HasApiUrl()) + { + grid->addWidget(new QLabel("Api URL"), row, 0); + grid->addWidget(new QLabel(QString::fromStdString(info.GetApiUrl())), row++, 1); + } + + addEntry("CountryId", info.GetCountryId()); + + if (info.IsFeature()) + { + addEntry("Feature ID", DebugPrint(info.GetID())); + addEntry("Raw Types", DebugPrint(info.GetTypes())); + } + + auto const layer = info.GetLayer(); + if (layer != feature::LAYER_EMPTY) + addEntry("Layer", std::to_string(layer)); + + if(info.HasMetadataReadable()){ + grid->addWidget(new QLabel("Metadata"), row++, 0, 1, 2); + + info.ForEachMetadataReadable([&addEntry](PropID id, std::string const & value) + { + bool isLink = false; + switch (id) + { + case PropID::FMD_EMAIL: + case PropID::FMD_WEBSITE: + case PropID::FMD_CONTACT_FACEBOOK: + case PropID::FMD_CONTACT_INSTAGRAM: + case PropID::FMD_CONTACT_TWITTER: + case PropID::FMD_CONTACT_VK: + case PropID::FMD_CONTACT_LINE: + case PropID::FMD_WIKIPEDIA: + case PropID::FMD_WIKIMEDIA_COMMONS: + isLink = true; + break; + default: + break; + } + + addEntry(DebugPrint(id), value, isLink); + }); + } + + layout->addLayout(grid); + } +#endif + { QHLine * line = new QHLine(); layout->addWidget(line); @@ -266,6 +350,11 @@ PlacePageDialog::PlacePageDialog(QWidget * parent, place_page::Info const & info { QDialogButtonBox * dbb = new QDialogButtonBox(); + QPushButton * closeButton = new QPushButton("Close"); + closeButton->setDefault(true); + connect(closeButton, &QAbstractButton::clicked, this, &PlacePageDialog::OnClose); + dbb->addButton(closeButton, QDialogButtonBox::RejectRole); + if (info.ShouldShowEditPlace()) { QPushButton * editButton = new QPushButton("Edit Place"); @@ -273,90 +362,6 @@ PlacePageDialog::PlacePageDialog(QWidget * parent, place_page::Info const & info dbb->addButton(editButton, QDialogButtonBox::ActionRole); } - // Advanced - { - QPushButton * advancedButton = new QPushButton("Advanced"); - connect(advancedButton, &QAbstractButton::clicked, this, [this, info]() - { - auto dialog = QDialog(this); - - QGridLayout * grid = new QGridLayout(&dialog); - - int row = 0; - - auto const addEntry = [grid, &row](std::string const & key, std::string const & value, bool isLink = false) - { - grid->addWidget(new QLabel(QString::fromStdString(key)), row, 0); - QLabel * label = new QLabel(QString::fromStdString(value)); - label->setTextInteractionFlags(Qt::TextSelectableByMouse); - if (isLink) - { - label->setOpenExternalLinks(true); - label->setTextInteractionFlags(Qt::TextBrowserInteraction); - label->setText(QString::fromStdString("" + value + "")); - } - grid->addWidget(label, row++, 1); - return label; - }; - - if (info.IsMyPosition()) - { - grid->addWidget(new QLabel("MyPosition"), row, 0); - grid->addWidget(new QLabel("Yes"), row++, 1); - } - - if (info.HasApiUrl()) - { - grid->addWidget(new QLabel("Api URL"), row, 0); - grid->addWidget(new QLabel(QString::fromStdString(info.GetApiUrl())), row++, 1); - } - - addEntry("CountryId", info.GetCountryId()); - - if (info.IsFeature()) - { - addEntry("Feature ID", DebugPrint(info.GetID())); - addEntry("Raw Types", DebugPrint(info.GetTypes())); - } - - auto const layer = info.GetLayer(); - if (layer != feature::LAYER_EMPTY) - addEntry("Layer", std::to_string(layer)); - - QHLine * line = new QHLine(); - grid->addWidget(line, row++, 0, 1, 2); - - grid->addWidget(new QLabel("Metadata"), row++, 0, 1, 2); - - info.ForEachMetadataReadable([&addEntry](PropID id, std::string const & value) - { - bool isLink = false; - switch (id) - { - case PropID::FMD_EMAIL: - case PropID::FMD_WEBSITE: - case PropID::FMD_CONTACT_FACEBOOK: - case PropID::FMD_CONTACT_INSTAGRAM: - case PropID::FMD_CONTACT_TWITTER: - case PropID::FMD_CONTACT_VK: - case PropID::FMD_CONTACT_LINE: - case PropID::FMD_WIKIPEDIA: - case PropID::FMD_WIKIMEDIA_COMMONS: - isLink = true; - break; - default: - break; - } - - addEntry(DebugPrint(id), value, isLink); - }); - - dialog.exec(); - }); - - dbb->addButton(advancedButton, QDialogButtonBox::AcceptRole); - } - layout->addWidget(dbb, Qt::AlignCenter); } -- 2.45.3 From d4fbb5f1f21b153cf62dc1152009ad5a24994180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20G=C3=A9czi?= Date: Fri, 1 Mar 2024 00:00:10 +0000 Subject: [PATCH 03/12] [qt] Make Close focused by default instead of More... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ferenc Géczi --- qt/place_page_dialog.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/qt/place_page_dialog.cpp b/qt/place_page_dialog.cpp index 209b37f0d8..64915ab192 100644 --- a/qt/place_page_dialog.cpp +++ b/qt/place_page_dialog.cpp @@ -126,6 +126,7 @@ PlacePageDialog::PlacePageDialog(QWidget * parent, place_page::Info const & info data->addWidget(value, row++, 0, 1, 2); QPushButton * wikiButton = new QPushButton("More...", value); + wikiButton->setAutoDefault(false); connect(wikiButton, &QAbstractButton::clicked, this, [this, description, title]() { auto textDialog = TextDialog(this, QString::fromStdString(description), QString::fromStdString("Wikipedia: " + title)); -- 2.45.3 From 95a6b0a174cd3ea26910f2d0e9a0fa164cfdc4c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20G=C3=A9czi?= Date: Fri, 1 Mar 2024 00:00:04 +0000 Subject: [PATCH 04/12] [qt] Strip http(s):// schemes from displayed URIs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ferenc Géczi --- qt/place_page_dialog.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/qt/place_page_dialog.cpp b/qt/place_page_dialog.cpp index 64915ab192..c1bea54df0 100644 --- a/qt/place_page_dialog.cpp +++ b/qt/place_page_dialog.cpp @@ -21,6 +21,18 @@ const int place_page_description_max_length = 500; const int short_description_minimum_width = 390; +namespace { + std::string stripSchemeFromURI(std::string const & input) { + std::string result = input; + if (size(input) > 8 && ("https://" == input.substr(0, 8))) { + result = result.substr(8, size(input)); + } else if (size(input) > 7 && ("http://" == input.substr(0, 7))) { + result = result.substr(7, size(input)); + } + return result; + } +} + class QHLine : public QFrame { public: @@ -101,7 +113,7 @@ PlacePageDialog::PlacePageDialog(QWidget * parent, place_page::Info const & info } // Description - + if (auto description = info.GetWikiDescription(); !description.empty()) { // Wikipedia fragment @@ -140,7 +152,7 @@ PlacePageDialog::PlacePageDialog(QWidget * parent, place_page::Info const & info if (auto openingHours = info.GetOpeningHours(); !openingHours.empty()) addEntry("Opening hours", std::string(openingHours)); - // Cuisine fragment + // Cuisine fragment if (auto cuisines = info.FormatCuisines(); !cuisines.empty()) addEntry("Cuisine", cuisines); @@ -153,7 +165,7 @@ PlacePageDialog::PlacePageDialog(QWidget * parent, place_page::Info const & info QLabel * value = new QLabel(QString::fromStdString("" + std::string(phoneNumber) + "")); value->setOpenExternalLinks(true); - + data->addWidget(value, row++, 1); } @@ -168,14 +180,14 @@ PlacePageDialog::PlacePageDialog(QWidget * parent, place_page::Info const & info // Links fragment if (auto website = info.GetMetadata(feature::Metadata::EType::FMD_WEBSITE); !website.empty()) - addEntry("Website", std::string(website), true); + addEntry("Website", stripSchemeFromURI(std::string(website)), true); if (auto email = info.GetMetadata(feature::Metadata::EType::FMD_EMAIL); !email.empty()){ data->addWidget(new QLabel("Email"), row, 0); QLabel * value = new QLabel(QString::fromStdString("" + std::string(email) + "")); value->setOpenExternalLinks(true); - + data->addWidget(value, row++, 1); } @@ -282,7 +294,7 @@ PlacePageDialog::PlacePageDialog(QWidget * parent, place_page::Info const & info { label->setOpenExternalLinks(true); label->setTextInteractionFlags(Qt::TextBrowserInteraction); - label->setText(QString::fromStdString("" + value + "")); + label->setText(QString::fromStdString("" + stripSchemeFromURI(value) + "")); } grid->addWidget(label, row++, 1); return label; -- 2.45.3 From 96a904ebf19d170b3c450a0355be18a7bea83158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20G=C3=A9czi?= Date: Fri, 1 Mar 2024 00:00:06 +0000 Subject: [PATCH 05/12] [qt] Make the first Wikipedia clickable and remove the second MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ferenc Géczi --- qt/place_page_dialog.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/qt/place_page_dialog.cpp b/qt/place_page_dialog.cpp index c1bea54df0..45f7223c98 100644 --- a/qt/place_page_dialog.cpp +++ b/qt/place_page_dialog.cpp @@ -126,8 +126,7 @@ PlacePageDialog::PlacePageDialog(QWidget * parent, place_page::Info const & info name->setText(QString::fromStdString("Wikipedia")); } - data->addWidget(new QLabel("Wikipedia"), row, 0); - data->addWidget(name, row++, 1); + data->addWidget(name, row++, 0); auto descriptionShort = getShortDescription(description); -- 2.45.3 From 392a157a207d8f2d373b7dd8c16d2c25bc331ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20G=C3=A9czi?= Date: Fri, 1 Mar 2024 00:00:04 +0000 Subject: [PATCH 06/12] [qt] Add a preference for Developer Mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ferenc Géczi --- platform/settings.cpp | 1 + platform/settings.hpp | 2 ++ qt/main.cpp | 11 +++++++++++ qt/place_page_dialog.cpp | 5 +++-- qt/preferences_dialog.cpp | 13 +++++++++++++ 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/platform/settings.cpp b/platform/settings.cpp index abd908c15b..6d09c99917 100644 --- a/platform/settings.cpp +++ b/platform/settings.cpp @@ -21,6 +21,7 @@ namespace settings using namespace std; char const * kMeasurementUnits = "Units"; +char const * kDeveloperMode = "DeveloperMode"; StringStorage::StringStorage() : StringStorageBase(GetPlatform().SettingsPathForFile(SETTINGS_FILE_NAME)) {} diff --git a/platform/settings.hpp b/platform/settings.hpp index 0a225ceb65..9f9b9cd44c 100644 --- a/platform/settings.hpp +++ b/platform/settings.hpp @@ -11,6 +11,8 @@ namespace settings /// Metric or Imperial. extern char const * kMeasurementUnits; +extern char const * kDeveloperMode; + template bool FromString(std::string const & str, T & outValue); diff --git a/qt/main.cpp b/qt/main.cpp index 17766fc4d3..54d796919c 100644 --- a/qt/main.cpp +++ b/qt/main.cpp @@ -148,6 +148,17 @@ int main(int argc, char * argv[]) QApplication::setApplicationName("Organic Maps"); #endif + +#ifdef DEBUG + bool developerMode = true; +#else + bool developerMode = false; +#endif + if (!settings::Get(settings::kDeveloperMode, developerMode)) + { + settings::Set(settings::kDeveloperMode, developerMode); + } + // Display EULA if needed. char const * settingsEULA = "EulaAccepted"; bool eulaAccepted = false; diff --git a/qt/place_page_dialog.cpp b/qt/place_page_dialog.cpp index 45f7223c98..27543da76a 100644 --- a/qt/place_page_dialog.cpp +++ b/qt/place_page_dialog.cpp @@ -4,6 +4,7 @@ #include "map/place_page_info.hpp" #include "indexer/validate_and_format_contacts.hpp" +#include "platform/settings.hpp" #include #include @@ -271,7 +272,8 @@ PlacePageDialog::PlacePageDialog(QWidget * parent, place_page::Info const & info } // Advanced -#ifdef DEBUG + bool developerMode; + if (settings::Get(settings::kDeveloperMode, developerMode) && developerMode) { { QHLine * line = new QHLine(); @@ -352,7 +354,6 @@ PlacePageDialog::PlacePageDialog(QWidget * parent, place_page::Info const & info layout->addLayout(grid); } -#endif { QHLine * line = new QHLine(); diff --git a/qt/preferences_dialog.cpp b/qt/preferences_dialog.cpp index 69ce85a863..2a80e88498 100644 --- a/qt/preferences_dialog.cpp +++ b/qt/preferences_dialog.cpp @@ -86,6 +86,18 @@ namespace qt }); } + QCheckBox * developerModeCheckBox = new QCheckBox("Developer Mode"); + { + + bool developerMode; + if (settings::Get(settings::kDeveloperMode, developerMode) && developerMode) + developerModeCheckBox->setChecked(developerMode); + connect(developerModeCheckBox, &QCheckBox::stateChanged, [](int i) + { + settings::Set(settings::kDeveloperMode, static_cast(i)); + }); + } + #ifdef BUILD_DESIGNER QCheckBox * indexRegenCheckBox = new QCheckBox("Enable auto regeneration of geometry index"); { @@ -115,6 +127,7 @@ namespace qt QVBoxLayout * finalLayout = new QVBoxLayout(); finalLayout->addWidget(unitsRadioBox); finalLayout->addWidget(largeFontCheckBox); + finalLayout->addWidget(developerModeCheckBox); #ifdef BUILD_DESIGNER finalLayout->addWidget(indexRegenCheckBox); #endif -- 2.45.3 From 8effd98bdcf6eaff87256d03fd7af3621e85e829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20G=C3=A9czi?= Date: Fri, 1 Mar 2024 00:00:07 +0000 Subject: [PATCH 07/12] [qt] Skip already displayed lines in Developer Mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ferenc Géczi --- qt/place_page_dialog.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/qt/place_page_dialog.cpp b/qt/place_page_dialog.cpp index 27543da76a..8d2c965e8a 100644 --- a/qt/place_page_dialog.cpp +++ b/qt/place_page_dialog.cpp @@ -330,25 +330,26 @@ PlacePageDialog::PlacePageDialog(QWidget * parent, place_page::Info const & info info.ForEachMetadataReadable([&addEntry](PropID id, std::string const & value) { - bool isLink = false; switch (id) - { + { // SKIP those that are already listed in the non-advanced (non-developer) mode case PropID::FMD_EMAIL: - case PropID::FMD_WEBSITE: case PropID::FMD_CONTACT_FACEBOOK: case PropID::FMD_CONTACT_INSTAGRAM: case PropID::FMD_CONTACT_TWITTER: case PropID::FMD_CONTACT_VK: case PropID::FMD_CONTACT_LINE: + case PropID::FMD_LEVEL: + case PropID::FMD_OPERATOR: + case PropID::FMD_PHONE_NUMBER: + case PropID::FMD_WEBSITE: case PropID::FMD_WIKIPEDIA: case PropID::FMD_WIKIMEDIA_COMMONS: - isLink = true; break; default: + addEntry(DebugPrint(id), value, false); break; } - addEntry(DebugPrint(id), value, isLink); }); } -- 2.45.3 From 5dfc5ede128886dfb769feea40491097b666ad17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20G=C3=A9czi?= Date: Fri, 1 Mar 2024 00:00:05 +0000 Subject: [PATCH 08/12] [qt] Make the first Wikimedia Commons clickable and remove the second MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ferenc Géczi --- qt/place_page_dialog.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/qt/place_page_dialog.cpp b/qt/place_page_dialog.cpp index 8d2c965e8a..0ba785e347 100644 --- a/qt/place_page_dialog.cpp +++ b/qt/place_page_dialog.cpp @@ -242,13 +242,11 @@ PlacePageDialog::PlacePageDialog(QWidget * parent, place_page::Info const & info } if (auto wikimedia_commons = info.GetMetadata(feature::Metadata::EType::FMD_WIKIMEDIA_COMMONS); !wikimedia_commons.empty()){ - data->addWidget(new QLabel("Wikimedia Commons"), row, 0); - QLabel * value = new QLabel(QString::fromStdString("Wikimedia Commons")); value->setOpenExternalLinks(true); value->setTextInteractionFlags(Qt::TextBrowserInteraction); - data->addWidget(value, row++, 1); + data->addWidget(value, row++, 0); } // Level fragment -- 2.45.3 From 66a3d61f53e95e340c2894ae3a6479809eb12caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20G=C3=A9czi?= Date: Fri, 1 Mar 2024 00:00:03 +0000 Subject: [PATCH 09/12] [qt] Make the Wikipedia link independent from the short description MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ferenc Géczi --- qt/place_page_dialog.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/qt/place_page_dialog.cpp b/qt/place_page_dialog.cpp index 0ba785e347..c7e3cd1a17 100644 --- a/qt/place_page_dialog.cpp +++ b/qt/place_page_dialog.cpp @@ -113,22 +113,19 @@ PlacePageDialog::PlacePageDialog(QWidget * parent, place_page::Info const & info addEntry("Bookmark", "Yes"); } - // Description + // Wikipedia fragment + if (auto const & wikipedia = info.GetMetadata(feature::Metadata::EType::FMD_WIKIPEDIA); !wikipedia.empty()){ + QLabel * name = new QLabel("Wikipedia"); + name->setOpenExternalLinks(true); + name->setTextInteractionFlags(Qt::TextBrowserInteraction); + name->setText(QString::fromStdString("Wikipedia")); + data->addWidget(name, row++, 0); + } + + // Description if (auto description = info.GetWikiDescription(); !description.empty()) { - // Wikipedia fragment - - QLabel * name = new QLabel("Wikipedia"); - auto const & wikipedia = info.GetMetadata(feature::Metadata::EType::FMD_WIKIPEDIA); - if (!wikipedia.empty()){ - name->setOpenExternalLinks(true); - name->setTextInteractionFlags(Qt::TextBrowserInteraction); - name->setText(QString::fromStdString("Wikipedia")); - } - - data->addWidget(name, row++, 0); - auto descriptionShort = getShortDescription(description); QLabel * value = new QLabel(QString::fromStdString(descriptionShort)); -- 2.45.3 From 21e7eb98e485a14d4d49d7b77e762d5a5664d10f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20G=C3=A9czi?= Date: Fri, 1 Mar 2024 00:00:03 +0000 Subject: [PATCH 10/12] [qt] Drop preview and rename More to Wikipedia Description MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ferenc Géczi --- qt/place_page_dialog.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/qt/place_page_dialog.cpp b/qt/place_page_dialog.cpp index c7e3cd1a17..9d36ae976c 100644 --- a/qt/place_page_dialog.cpp +++ b/qt/place_page_dialog.cpp @@ -126,15 +126,7 @@ PlacePageDialog::PlacePageDialog(QWidget * parent, place_page::Info const & info // Description if (auto description = info.GetWikiDescription(); !description.empty()) { - auto descriptionShort = getShortDescription(description); - - QLabel * value = new QLabel(QString::fromStdString(descriptionShort)); - value->setWordWrap(true); - value->setMinimumWidth(short_description_minimum_width); - - data->addWidget(value, row++, 0, 1, 2); - - QPushButton * wikiButton = new QPushButton("More...", value); + QPushButton * wikiButton = new QPushButton("Wikipedia Description"); wikiButton->setAutoDefault(false); connect(wikiButton, &QAbstractButton::clicked, this, [this, description, title]() { -- 2.45.3 From deaa913c735848bd1f309a187924a6249780f7f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20G=C3=A9czi?= Date: Sat, 23 Mar 2024 00:00:07 +0000 Subject: [PATCH 11/12] qt: Separate developer and user mode place page dialogs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ferenc Géczi --- indexer/map_object.hpp | 21 --- qt/CMakeLists.txt | 6 +- qt/draw_widget.cpp | 13 +- qt/place_page_dialog_developer.cpp | 141 ++++++++++++++++++ qt/place_page_dialog_developer.hpp | 22 +++ ..._dialog.cpp => place_page_dialog_user.cpp} | 97 +----------- ..._dialog.hpp => place_page_dialog_user.hpp} | 4 +- 7 files changed, 185 insertions(+), 119 deletions(-) create mode 100644 qt/place_page_dialog_developer.cpp create mode 100644 qt/place_page_dialog_developer.hpp rename qt/{place_page_dialog.cpp => place_page_dialog_user.cpp} (78%) rename qt/{place_page_dialog.hpp => place_page_dialog_user.hpp} (70%) diff --git a/indexer/map_object.hpp b/indexer/map_object.hpp index 2c5ed62891..98e912c659 100644 --- a/indexer/map_object.hpp +++ b/indexer/map_object.hpp @@ -44,27 +44,6 @@ public: std::string_view GetMetadata(MetadataID type) const; - bool HasMetadataReadable() const - { - bool has = false; - m_metadata.ForEach([&has](MetadataID id, std::string const & value) - { - switch (id) - { - case MetadataID::FMD_WIKIPEDIA: - case MetadataID::FMD_WIKIMEDIA_COMMONS: - case MetadataID::FMD_DESCRIPTION: - case MetadataID::FMD_CUSTOM_IDS: - case MetadataID::FMD_PRICE_RATES: - case MetadataID::FMD_RATINGS: - has = true; - break; - default: break; - } - }); - return has; - } - template void ForEachMetadataReadable(FnT && fn) const { m_metadata.ForEach([&fn](MetadataID id, std::string const & value) diff --git a/qt/CMakeLists.txt b/qt/CMakeLists.txt index 5bc9fc6d18..f868513d7d 100644 --- a/qt/CMakeLists.txt +++ b/qt/CMakeLists.txt @@ -36,8 +36,10 @@ set(SRC mwms_borders_selection.hpp osm_auth_dialog.cpp osm_auth_dialog.hpp - place_page_dialog.cpp - place_page_dialog.hpp + place_page_dialog_developer.cpp + place_page_dialog_developer.hpp + place_page_dialog_user.cpp + place_page_dialog_user.hpp preferences_dialog.cpp preferences_dialog.hpp popup_menu_holder.cpp diff --git a/qt/draw_widget.cpp b/qt/draw_widget.cpp index bec302854b..e765f5595d 100644 --- a/qt/draw_widget.cpp +++ b/qt/draw_widget.cpp @@ -2,7 +2,8 @@ #include "qt/create_feature_dialog.hpp" #include "qt/editor_dialog.hpp" -#include "qt/place_page_dialog.hpp" +#include "qt/place_page_dialog_developer.hpp" +#include "qt/place_page_dialog_user.hpp" #include "qt/qt_common/helpers.hpp" #include "qt/routing_settings_dialog.hpp" #include "qt/screenshoter.hpp" @@ -649,8 +650,14 @@ void DrawWidget::ShowPlacePage() address = m_framework.GetAddressAtPoint(info.GetMercator()); } - PlacePageDialog dlg(this, info, address); - if (dlg.exec() == QDialog::Accepted) + std::unique_ptr placePageDialog = nullptr; + bool developerMode; + if (settings::Get(settings::kDeveloperMode, developerMode) && developerMode) + placePageDialog = std::make_unique(this, info, address); + else + placePageDialog = std::make_unique(this, info, address); + + if (placePageDialog->exec() == QDialog::Accepted) { osm::EditableMapObject emo; if (m_framework.GetEditableMapObject(info.GetID(), emo)) diff --git a/qt/place_page_dialog_developer.cpp b/qt/place_page_dialog_developer.cpp new file mode 100644 index 0000000000..7403d9ff9e --- /dev/null +++ b/qt/place_page_dialog_developer.cpp @@ -0,0 +1,141 @@ +#include "qt/place_page_dialog_developer.hpp" + +#include "qt/qt_common/text_dialog.hpp" + +#include "map/place_page_info.hpp" + +#include +#include +#include +#include +#include + +#include + +PlacePageDialogDeveloper::PlacePageDialogDeveloper(QWidget * parent, place_page::Info const & info, + search::ReverseGeocoder::Address const & address) + : QDialog(parent) +{ + QGridLayout * grid = new QGridLayout(); + int row = 0; + + auto const addEntry = [grid, &row](std::string const & key, std::string const & value, bool isLink = false) + { + grid->addWidget(new QLabel(QString::fromStdString(key)), row, 0); + QLabel * label = new QLabel(QString::fromStdString(value)); + label->setTextInteractionFlags(Qt::TextSelectableByMouse); + if (isLink) + { + label->setOpenExternalLinks(true); + label->setTextInteractionFlags(Qt::TextBrowserInteraction); + label->setText(QString::fromStdString("" + value + "")); + } + grid->addWidget(label, row++, 1); + return label; + }; + + { + ms::LatLon const ll = info.GetLatLon(); + addEntry("lat, lon", strings::to_string_dac(ll.m_lat, 7) + ", " + strings::to_string_dac(ll.m_lon, 7)); + } + + addEntry("CountryId", info.GetCountryId()); + + auto const & title = info.GetTitle(); + if (!title.empty()) + addEntry("Title", title); + + if (auto const & subTitle = info.GetSubtitle(); !subTitle.empty()) + addEntry("Subtitle", subTitle); + + addEntry("Address", address.FormatAddress()); + + if (info.IsBookmark()) + { + grid->addWidget(new QLabel("Bookmark"), row, 0); + grid->addWidget(new QLabel("Yes"), row++, 1); + } + + if (info.IsMyPosition()) + { + grid->addWidget(new QLabel("MyPosition"), row, 0); + grid->addWidget(new QLabel("Yes"), row++, 1); + } + + if (info.HasApiUrl()) + { + grid->addWidget(new QLabel("Api URL"), row, 0); + grid->addWidget(new QLabel(QString::fromStdString(info.GetApiUrl())), row++, 1); + } + + if (info.IsFeature()) + { + addEntry("Feature ID", DebugPrint(info.GetID())); + addEntry("Raw Types", DebugPrint(info.GetTypes())); + } + + auto const layer = info.GetLayer(); + if (layer != feature::LAYER_EMPTY) + addEntry("Layer", std::to_string(layer)); + + using PropID = osm::MapObject::MetadataID; + + if (auto cuisines = info.FormatCuisines(); !cuisines.empty()) + addEntry(DebugPrint(PropID::FMD_CUISINE), cuisines); + + QDialogButtonBox * dbb = new QDialogButtonBox(); + QPushButton * closeButton = new QPushButton("Close"); + closeButton->setDefault(true); + connect(closeButton, &QAbstractButton::clicked, this, &PlacePageDialogDeveloper::OnClose); + dbb->addButton(closeButton, QDialogButtonBox::RejectRole); + + if (info.ShouldShowEditPlace()) + { + QPushButton * editButton = new QPushButton("Edit Place"); + connect(editButton, &QAbstractButton::clicked, this, &PlacePageDialogDeveloper::OnEdit); + dbb->addButton(editButton, QDialogButtonBox::AcceptRole); + } + + if (auto const & descr = info.GetWikiDescription(); !descr.empty()) + { + QPushButton * wikiButton = new QPushButton("Wiki Description"); + connect(wikiButton, &QAbstractButton::clicked, this, [this, descr, title]() + { + auto textDialog = TextDialog(this, QString::fromStdString(descr), QString::fromStdString("Wikipedia: " + title)); + textDialog.exec(); + }); + dbb->addButton(wikiButton, QDialogButtonBox::ActionRole); + } + + info.ForEachMetadataReadable([&addEntry](PropID id, std::string const & value) + { + bool isLink = false; + switch (id) + { + case PropID::FMD_EMAIL: + case PropID::FMD_WEBSITE: + case PropID::FMD_CONTACT_FACEBOOK: + case PropID::FMD_CONTACT_INSTAGRAM: + case PropID::FMD_CONTACT_TWITTER: + case PropID::FMD_CONTACT_VK: + case PropID::FMD_CONTACT_LINE: + case PropID::FMD_WIKIPEDIA: + case PropID::FMD_WIKIMEDIA_COMMONS: + isLink = true; + break; + default: + break; + } + + addEntry(DebugPrint(id), value, isLink); + }); + + grid->addWidget(dbb); + setLayout(grid); + + auto const ppTitle = std::string("Place Page") + (info.IsBookmark() ? " (bookmarked)" : ""); + setWindowTitle(ppTitle.c_str()); +} + +void PlacePageDialogDeveloper::OnClose() { reject(); } +void PlacePageDialogDeveloper::OnEdit() { accept(); } diff --git a/qt/place_page_dialog_developer.hpp b/qt/place_page_dialog_developer.hpp new file mode 100644 index 0000000000..5ff05c5a56 --- /dev/null +++ b/qt/place_page_dialog_developer.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "search/reverse_geocoder.hpp" + +#include + +namespace place_page +{ +class Info; +} + +class PlacePageDialogDeveloper : public QDialog +{ + Q_OBJECT +public: + PlacePageDialogDeveloper(QWidget * parent, place_page::Info const & info, + search::ReverseGeocoder::Address const & address); + +private slots: + void OnClose(); + void OnEdit(); +}; diff --git a/qt/place_page_dialog.cpp b/qt/place_page_dialog_user.cpp similarity index 78% rename from qt/place_page_dialog.cpp rename to qt/place_page_dialog_user.cpp index 9d36ae976c..08f4368617 100644 --- a/qt/place_page_dialog.cpp +++ b/qt/place_page_dialog_user.cpp @@ -1,4 +1,4 @@ -#include "qt/place_page_dialog.hpp" +#include "qt/place_page_dialog_user.hpp" #include "qt/qt_common/text_dialog.hpp" @@ -59,7 +59,7 @@ std::string getShortDescription(std::string description) return description; } -PlacePageDialog::PlacePageDialog(QWidget * parent, place_page::Info const & info, +PlacePageDialogUser::PlacePageDialogUser(QWidget * parent, place_page::Info const & info, search::ReverseGeocoder::Address const & address) : QDialog(parent) { @@ -258,91 +258,6 @@ PlacePageDialog::PlacePageDialog(QWidget * parent, place_page::Info const & info layout->addLayout(data); } - // Advanced - bool developerMode; - if (settings::Get(settings::kDeveloperMode, developerMode) && developerMode) - { - { - QHLine * line = new QHLine(); - layout->addWidget(line); - } - - layout->addWidget(new QLabel("Advanced")); - - QGridLayout * grid = new QGridLayout(); - - int row = 0; - - auto const addEntry = [grid, &row](std::string const & key, std::string const & value, bool isLink = false) - { - grid->addWidget(new QLabel(QString::fromStdString(key)), row, 0); - QLabel * label = new QLabel(QString::fromStdString(value)); - label->setTextInteractionFlags(Qt::TextSelectableByMouse); - if (isLink) - { - label->setOpenExternalLinks(true); - label->setTextInteractionFlags(Qt::TextBrowserInteraction); - label->setText(QString::fromStdString("" + stripSchemeFromURI(value) + "")); - } - grid->addWidget(label, row++, 1); - return label; - }; - - if (info.IsMyPosition()) - { - grid->addWidget(new QLabel("MyPosition"), row, 0); - grid->addWidget(new QLabel("Yes"), row++, 1); - } - - if (info.HasApiUrl()) - { - grid->addWidget(new QLabel("Api URL"), row, 0); - grid->addWidget(new QLabel(QString::fromStdString(info.GetApiUrl())), row++, 1); - } - - addEntry("CountryId", info.GetCountryId()); - - if (info.IsFeature()) - { - addEntry("Feature ID", DebugPrint(info.GetID())); - addEntry("Raw Types", DebugPrint(info.GetTypes())); - } - - auto const layer = info.GetLayer(); - if (layer != feature::LAYER_EMPTY) - addEntry("Layer", std::to_string(layer)); - - if(info.HasMetadataReadable()){ - grid->addWidget(new QLabel("Metadata"), row++, 0, 1, 2); - - info.ForEachMetadataReadable([&addEntry](PropID id, std::string const & value) - { - switch (id) - { // SKIP those that are already listed in the non-advanced (non-developer) mode - case PropID::FMD_EMAIL: - case PropID::FMD_CONTACT_FACEBOOK: - case PropID::FMD_CONTACT_INSTAGRAM: - case PropID::FMD_CONTACT_TWITTER: - case PropID::FMD_CONTACT_VK: - case PropID::FMD_CONTACT_LINE: - case PropID::FMD_LEVEL: - case PropID::FMD_OPERATOR: - case PropID::FMD_PHONE_NUMBER: - case PropID::FMD_WEBSITE: - case PropID::FMD_WIKIPEDIA: - case PropID::FMD_WIKIMEDIA_COMMONS: - break; - default: - addEntry(DebugPrint(id), value, false); - break; - } - - }); - } - - layout->addLayout(grid); - } - { QHLine * line = new QHLine(); layout->addWidget(line); @@ -353,13 +268,13 @@ PlacePageDialog::PlacePageDialog(QWidget * parent, place_page::Info const & info QPushButton * closeButton = new QPushButton("Close"); closeButton->setDefault(true); - connect(closeButton, &QAbstractButton::clicked, this, &PlacePageDialog::OnClose); + connect(closeButton, &QAbstractButton::clicked, this, &PlacePageDialogUser::OnClose); dbb->addButton(closeButton, QDialogButtonBox::RejectRole); if (info.ShouldShowEditPlace()) { QPushButton * editButton = new QPushButton("Edit Place"); - connect(editButton, &QAbstractButton::clicked, this, &PlacePageDialog::OnEdit); + connect(editButton, &QAbstractButton::clicked, this, &PlacePageDialogUser::OnEdit); dbb->addButton(editButton, QDialogButtonBox::ActionRole); } @@ -372,5 +287,5 @@ PlacePageDialog::PlacePageDialog(QWidget * parent, place_page::Info const & info setWindowTitle(ppTitle.c_str()); } -void PlacePageDialog::OnClose() { reject(); } -void PlacePageDialog::OnEdit() { accept(); } +void PlacePageDialogUser::OnClose() { reject(); } +void PlacePageDialogUser::OnEdit() { accept(); } diff --git a/qt/place_page_dialog.hpp b/qt/place_page_dialog_user.hpp similarity index 70% rename from qt/place_page_dialog.hpp rename to qt/place_page_dialog_user.hpp index 4f2470fd5a..8dfe2f23f5 100644 --- a/qt/place_page_dialog.hpp +++ b/qt/place_page_dialog_user.hpp @@ -9,11 +9,11 @@ namespace place_page class Info; } -class PlacePageDialog : public QDialog +class PlacePageDialogUser : public QDialog { Q_OBJECT public: - PlacePageDialog(QWidget * parent, place_page::Info const & info, + PlacePageDialogUser(QWidget * parent, place_page::Info const & info, search::ReverseGeocoder::Address const & address); private slots: -- 2.45.3 From 0927451cf9874388207aa123f27493db15f12dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20G=C3=A9czi?= Date: Sat, 23 Mar 2024 00:00:04 +0000 Subject: [PATCH 12/12] [qt] Remove duplication & fix review comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ferenc Géczi --- qt/main.cpp | 9 +-- qt/place_page_dialog_user.cpp | 139 ++++++++++++---------------------- qt/preferences_dialog.cpp | 1 - 3 files changed, 51 insertions(+), 98 deletions(-) diff --git a/qt/main.cpp b/qt/main.cpp index 54d796919c..87d04d6def 100644 --- a/qt/main.cpp +++ b/qt/main.cpp @@ -150,14 +150,13 @@ int main(int argc, char * argv[]) #ifdef DEBUG - bool developerMode = true; + static bool constexpr developerMode = true; #else - bool developerMode = false; + static bool constexpr developerMode = false; #endif - if (!settings::Get(settings::kDeveloperMode, developerMode)) - { + bool outvalue; + if (!settings::Get(settings::kDeveloperMode, outvalue)) settings::Set(settings::kDeveloperMode, developerMode); - } // Display EULA if needed. char const * settingsEULA = "EulaAccepted"; diff --git a/qt/place_page_dialog_user.cpp b/qt/place_page_dialog_user.cpp index 08f4368617..2ac132d756 100644 --- a/qt/place_page_dialog_user.cpp +++ b/qt/place_page_dialog_user.cpp @@ -11,28 +11,27 @@ #include #include #include +#include +#include +#include -#include -#include -#include -#include #include #include -const int place_page_description_max_length = 500; -const int short_description_minimum_width = 390; +namespace +{ +static int constexpr kMaxLengthOfPlacePageDescription = 500; +static int constexpr kMinWidthOfShortDescription = 390; -namespace { - std::string stripSchemeFromURI(std::string const & input) { - std::string result = input; - if (size(input) > 8 && ("https://" == input.substr(0, 8))) { - result = result.substr(8, size(input)); - } else if (size(input) > 7 && ("http://" == input.substr(0, 7))) { - result = result.substr(7, size(input)); - } - return result; +std::string_view stripSchemeFromURI(std::string_view uri) { + for (std::string_view prefix : {"https://", "http://"}) + { + if (strings::StartsWith(uri, prefix)) + return uri.substr(prefix.size()); } + return uri; } +} // namespace class QHLine : public QFrame { @@ -44,27 +43,10 @@ public: } }; -std::string getShortDescription(std::string description) -{ - size_t paragraphStart = description.find("

"); - size_t paragraphEnd = description.find("

"); - if (paragraphStart == 0 && paragraphEnd != std::string::npos) - description = description.substr(3, paragraphEnd); - - if (description.length() > place_page_description_max_length) - { - description = description.substr(0, place_page_description_max_length-3) + "..."; - } - - return description; -} - PlacePageDialogUser::PlacePageDialogUser(QWidget * parent, place_page::Info const & info, - search::ReverseGeocoder::Address const & address) + search::ReverseGeocoder::Address const & address) : QDialog(parent) { - using PropID = osm::MapObject::MetadataID; - auto const & title = info.GetTitle(); QVBoxLayout * layout = new QVBoxLayout(); @@ -109,13 +91,12 @@ PlacePageDialogUser::PlacePageDialogUser(QWidget * parent, place_page::Info cons }; if (info.IsBookmark()) - { addEntry("Bookmark", "Yes"); - } // Wikipedia fragment - if (auto const & wikipedia = info.GetMetadata(feature::Metadata::EType::FMD_WIKIPEDIA); !wikipedia.empty()){ + if (auto const & wikipedia = info.GetMetadata(feature::Metadata::EType::FMD_WIKIPEDIA); !wikipedia.empty()) + { QLabel * name = new QLabel("Wikipedia"); name->setOpenExternalLinks(true); name->setTextInteractionFlags(Qt::TextBrowserInteraction); @@ -149,7 +130,8 @@ PlacePageDialogUser::PlacePageDialogUser(QWidget * parent, place_page::Info cons // TODO // Phone fragment - if (auto phoneNumber = info.GetMetadata(feature::Metadata::EType::FMD_PHONE_NUMBER); !phoneNumber.empty()){ + if (auto phoneNumber = info.GetMetadata(feature::Metadata::EType::FMD_PHONE_NUMBER); !phoneNumber.empty()) + { data->addWidget(new QLabel("Phone"), row, 0); QLabel * value = new QLabel(QString::fromStdString("" + std::string(phoneNumber) + "")); @@ -163,15 +145,15 @@ PlacePageDialogUser::PlacePageDialogUser(QWidget * parent, place_page::Info cons addEntry("Operator", std::string(operatorName)); // Wifi fragment - if (info.HasWifi()){ + if (info.HasWifi()) addEntry("Wi-Fi", "Yes"); - } // Links fragment if (auto website = info.GetMetadata(feature::Metadata::EType::FMD_WEBSITE); !website.empty()) - addEntry("Website", stripSchemeFromURI(std::string(website)), true); + addEntry("Website", std::string(stripSchemeFromURI(website)), true); - if (auto email = info.GetMetadata(feature::Metadata::EType::FMD_EMAIL); !email.empty()){ + if (auto email = info.GetMetadata(feature::Metadata::EType::FMD_EMAIL); !email.empty()) + { data->addWidget(new QLabel("Email"), row, 0); QLabel * value = new QLabel(QString::fromStdString("" + std::string(email) + "")); @@ -180,57 +162,32 @@ PlacePageDialogUser::PlacePageDialogUser(QWidget * parent, place_page::Info cons data->addWidget(value, row++, 1); } - if (auto facebook = info.GetMetadata(feature::Metadata::EType::FMD_CONTACT_FACEBOOK); !facebook.empty()){ - data->addWidget(new QLabel("Facebook"), row, 0); + // Social networks + { + auto addSocialNetworkWidget = [data, &info, &row](const std::string label, const feature::Metadata::EType eType) + { + if (auto item = info.GetMetadata(eType); !item.empty()) + { + data->addWidget(new QLabel(QString::fromStdString(label)), row, 0); - QLabel * value = new QLabel(QString::fromStdString("" + std::string(facebook) + "")); - value->setOpenExternalLinks(true); - value->setTextInteractionFlags(Qt::TextBrowserInteraction); + QLabel * value = new QLabel(QString::fromStdString("" + std::string(item) + "")); + value->setOpenExternalLinks(true); + value->setTextInteractionFlags(Qt::TextBrowserInteraction); - data->addWidget(value, row++, 1); + data->addWidget(value, row++, 1); + } + }; + + addSocialNetworkWidget("Facebook", feature::Metadata::EType::FMD_CONTACT_FACEBOOK); + addSocialNetworkWidget("Instagram", feature::Metadata::EType::FMD_CONTACT_INSTAGRAM); + addSocialNetworkWidget("Instagram", feature::Metadata::EType::FMD_CONTACT_INSTAGRAM); + addSocialNetworkWidget("Twitter", feature::Metadata::EType::FMD_CONTACT_TWITTER); + addSocialNetworkWidget("VK", feature::Metadata::EType::FMD_CONTACT_VK); + addSocialNetworkWidget("Line", feature::Metadata::EType::FMD_CONTACT_LINE); } - if (auto instagram = info.GetMetadata(feature::Metadata::EType::FMD_CONTACT_INSTAGRAM); !instagram.empty()){ - data->addWidget(new QLabel("Instagram"), row, 0); - - QLabel * value = new QLabel(QString::fromStdString("" + std::string(instagram) + "")); - value->setOpenExternalLinks(true); - value->setTextInteractionFlags(Qt::TextBrowserInteraction); - - data->addWidget(value, row++, 1); - } - - if (auto twitter = info.GetMetadata(feature::Metadata::EType::FMD_CONTACT_TWITTER); !twitter.empty()){ - data->addWidget(new QLabel("Twitter"), row, 0); - - QLabel * value = new QLabel(QString::fromStdString("" + std::string(twitter) + "")); - value->setOpenExternalLinks(true); - value->setTextInteractionFlags(Qt::TextBrowserInteraction); - - data->addWidget(value, row++, 1); - } - - if (auto vk = info.GetMetadata(feature::Metadata::EType::FMD_CONTACT_VK); !vk.empty()){ - data->addWidget(new QLabel("VK"), row, 0); - - QLabel * value = new QLabel(QString::fromStdString("" + std::string(vk) + "")); - value->setOpenExternalLinks(true); - value->setTextInteractionFlags(Qt::TextBrowserInteraction); - - data->addWidget(value, row++, 1); - } - - if (auto line = info.GetMetadata(feature::Metadata::EType::FMD_CONTACT_LINE); !line.empty()){ - data->addWidget(new QLabel("Line"), row, 0); - - QLabel * value = new QLabel(QString::fromStdString("" + std::string(line) + "")); - value->setOpenExternalLinks(true); - value->setTextInteractionFlags(Qt::TextBrowserInteraction); - - data->addWidget(value, row++, 1); - } - - if (auto wikimedia_commons = info.GetMetadata(feature::Metadata::EType::FMD_WIKIMEDIA_COMMONS); !wikimedia_commons.empty()){ + if (auto wikimedia_commons = info.GetMetadata(feature::Metadata::EType::FMD_WIKIMEDIA_COMMONS); !wikimedia_commons.empty()) + { QLabel * value = new QLabel(QString::fromStdString("Wikimedia Commons")); value->setOpenExternalLinks(true); value->setTextInteractionFlags(Qt::TextBrowserInteraction); @@ -239,14 +196,12 @@ PlacePageDialogUser::PlacePageDialogUser(QWidget * parent, place_page::Info cons } // Level fragment - if (auto level = info.GetMetadata(feature::Metadata::EType::FMD_LEVEL); !level.empty()){ + if (auto level = info.GetMetadata(feature::Metadata::EType::FMD_LEVEL); !level.empty()) addEntry("Level", std::string(level)); - } // ATM fragment - if (info.HasAtm()){ + if (info.HasAtm()) addEntry("ATM", "Yes"); - } // Latlon fragment diff --git a/qt/preferences_dialog.cpp b/qt/preferences_dialog.cpp index 2a80e88498..f887782347 100644 --- a/qt/preferences_dialog.cpp +++ b/qt/preferences_dialog.cpp @@ -88,7 +88,6 @@ namespace qt QCheckBox * developerModeCheckBox = new QCheckBox("Developer Mode"); { - bool developerMode; if (settings::Get(settings::kDeveloperMode, developerMode) && developerMode) developerModeCheckBox->setChecked(developerMode); -- 2.45.3