From ac3bf4eabaf1afd89a2a1643431fae73b3847264 Mon Sep 17 00:00:00 2001 From: tst-basilhuffman Date: Thu, 1 Apr 2021 18:22:29 +0000 Subject: [PATCH 1/9] initial commit, we need to look at de-coupling qstrings --- earth_enterprise/src/fusion/fusionui/AssetManager.cpp | 9 ++++++++- earth_enterprise/src/fusion/gst/gstAssetGroup.cpp | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/earth_enterprise/src/fusion/fusionui/AssetManager.cpp b/earth_enterprise/src/fusion/fusionui/AssetManager.cpp index 69511a91ee..65930adbf1 100644 --- a/earth_enterprise/src/fusion/fusionui/AssetManager.cpp +++ b/earth_enterprise/src/fusion/fusionui/AssetManager.cpp @@ -1003,6 +1003,8 @@ void AssetManager::iconAssetMenu(QIconViewItem* item, const QPoint& mouse_pos) { ShowAssetMenu(icon->getAssetHandle(), mouse_pos); } +#include + void AssetManager::ShowAssetMenu(const gstAssetHandle& asset_handle, const QPoint& mouse_pos) { enum { BUILD_ASSET, CANCEL_ASSET, MODIFY_ASSET, @@ -1016,7 +1018,12 @@ void AssetManager::ShowAssetMenu(const gstAssetHandle& asset_handle, // first item in menu should be the asset name since the table // might get redrawn after the menu has popped-up AssetDisplayHelper a(current_asset->type, current_asset->subtype); - menu.insertItem(a.GetPixmap(), shortAssetName(asset_handle->getName().toUtf8().constData())); + //menu.insertItem(a.GetPixmap(), shortAssetName(asset_handle->getName().toUtf8().constData())); + //auto prettyName = AssetPrettyName().toStdString(); + std::string temp = "US_Population"; + std::string shortName = shortAssetName(asset_handle->getName().toStdString().c_str()); + notify(NFY_WARN, "shortName %s", shortName.c_str()); + menu.insertItem(a.GetPixmap(), shortName.c_str()); menu.insertSeparator(); menu.insertSeparator(); diff --git a/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp b/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp index 9e11dd7031..4fb447e5ac 100644 --- a/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp +++ b/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp @@ -37,7 +37,7 @@ const char* shortAssetName(const char* n) { break; } } - return sname.toUtf8().constData(); + return sname.toStdString().c_str(); } bool isAssetPath(const QString& str) { From 19ed7dcda19a84eaab734147b8c07129c38d58c6 Mon Sep 17 00:00:00 2001 From: tst-basilhuffman Date: Fri, 2 Apr 2021 17:34:53 +0000 Subject: [PATCH 2/9] refactor to remove overdependence on qt --- .../src/fusion/fusionui/AssetManager.cpp | 8 +-- .../src/fusion/gst/gstAssetGroup.cpp | 55 +++++++++++++------ 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/earth_enterprise/src/fusion/fusionui/AssetManager.cpp b/earth_enterprise/src/fusion/fusionui/AssetManager.cpp index 65930adbf1..e673c890bf 100644 --- a/earth_enterprise/src/fusion/fusionui/AssetManager.cpp +++ b/earth_enterprise/src/fusion/fusionui/AssetManager.cpp @@ -1003,8 +1003,6 @@ void AssetManager::iconAssetMenu(QIconViewItem* item, const QPoint& mouse_pos) { ShowAssetMenu(icon->getAssetHandle(), mouse_pos); } -#include - void AssetManager::ShowAssetMenu(const gstAssetHandle& asset_handle, const QPoint& mouse_pos) { enum { BUILD_ASSET, CANCEL_ASSET, MODIFY_ASSET, @@ -1018,11 +1016,9 @@ void AssetManager::ShowAssetMenu(const gstAssetHandle& asset_handle, // first item in menu should be the asset name since the table // might get redrawn after the menu has popped-up AssetDisplayHelper a(current_asset->type, current_asset->subtype); - //menu.insertItem(a.GetPixmap(), shortAssetName(asset_handle->getName().toUtf8().constData())); - //auto prettyName = AssetPrettyName().toStdString(); - std::string temp = "US_Population"; + std::string shortName = shortAssetName(asset_handle->getName().toStdString().c_str()); - notify(NFY_WARN, "shortName %s", shortName.c_str()); + menu.insertItem(a.GetPixmap(), shortName.c_str()); menu.insertSeparator(); diff --git a/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp b/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp index 4fb447e5ac..b00f67c6b2 100644 --- a/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp +++ b/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp @@ -18,26 +18,49 @@ #include #include #include - +#include +#include #include "gstAssetGroup.h" -const char* shortAssetName(const char* n) { - QString sname(n); - QStringList suffix; - suffix << kVectorAssetSuffix.c_str() << kImageryAssetSuffix.c_str() - << kMercatorImageryAssetSuffix.c_str() << kTerrainAssetSuffix.c_str() - << kVectorProjectSuffix.c_str() << kImageryProjectSuffix.c_str() - << kMercatorImageryProjectSuffix.c_str() << kTerrainProjectSuffix.c_str() - << kDatabaseSuffix.c_str() << kMapLayerSuffix.c_str() << kMapProjectSuffix.c_str() - << kMapDatabaseSuffix.c_str() << kMercatorMapDatabaseSuffix.c_str() - << kVectorLayerSuffix.c_str(); - for (QStringList::Iterator it = suffix.begin(); it != suffix.end(); ++it) { - if (sname.endsWith(*it)) { - sname.truncate(sname.length() - it->length()); - break; +class SuffixNotFound : public std::exception +{ +private: + std::string aname; + +public: + SuffixNotFound(const std::string& _aname) : aname(_aname) {} + + const char* what() const noexcept + { + std::string ret { "No suffix found for " }; + ret += aname; + return ret.c_str(); } +}; + +const char* shortAssetName(const char* n) { + + static const std::vector suffixes = + { + kVectorAssetSuffix, kImageryAssetSuffix, kMercatorImageryAssetSuffix, + kTerrainAssetSuffix, kVectorProjectSuffix, kImageryProjectSuffix, + kMercatorImageryProjectSuffix, kTerrainProjectSuffix, + kDatabaseSuffix, kMapLayerSuffix, kMapProjectSuffix, + kMapDatabaseSuffix, kMercatorMapDatabaseSuffix, kVectorLayerSuffix + }; + + std::string saname { n }; + + for (const auto& elem : suffixes) + { + auto pos = saname.rfind(elem); + if (pos != std::string::npos) + { + return saname.substr(0,pos).c_str(); + } } - return sname.toStdString().c_str(); + + throw SuffixNotFound(saname); } bool isAssetPath(const QString& str) { From 36d79a2cffb810fad12da935f8b12728930859a4 Mon Sep 17 00:00:00 2001 From: tst-basilhuffman Date: Fri, 2 Apr 2021 19:56:07 +0000 Subject: [PATCH 3/9] refactored to use std::string, looking into previous jumbled text issues to see if this fixes that as well --- earth_enterprise/src/fusion/gst/gstAssetGroup.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp b/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp index b00f67c6b2..e5997d3188 100644 --- a/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp +++ b/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include "gstAssetGroup.h" @@ -93,7 +92,7 @@ bool gstAssetHandleImpl::isValid() const { } Asset gstAssetHandleImpl::getAsset() const { - std::string rpath { relativePath().toUtf8().constData() }; + std::string rpath { relativePath().toStdString() }; return Asset(rpath); } From 8b57e4a65bb6c18944d5d95d07b9ca70b0a27a05 Mon Sep 17 00:00:00 2001 From: tst-basilhuffman Date: Sat, 3 Apr 2021 21:39:39 +0000 Subject: [PATCH 4/9] fixed exception bug --- .../src/fusion/fusionui/AssetChooser.cpp | 3 --- .../src/fusion/gst/gstAssetGroup.cpp | 25 ++++--------------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp b/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp index 703d55b60f..8f99e0f201 100644 --- a/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp +++ b/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp @@ -15,15 +15,12 @@ #include "fusion/fusionui/AssetChooser.h" -#include - #include #include #include #include #include #include -//#include #include #include #include diff --git a/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp b/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp index e5997d3188..d24cef3c10 100644 --- a/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp +++ b/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp @@ -18,24 +18,8 @@ #include #include #include -#include #include "gstAssetGroup.h" -class SuffixNotFound : public std::exception -{ -private: - std::string aname; - -public: - SuffixNotFound(const std::string& _aname) : aname(_aname) {} - - const char* what() const noexcept - { - std::string ret { "No suffix found for " }; - ret += aname; - return ret.c_str(); - } -}; const char* shortAssetName(const char* n) { @@ -55,11 +39,12 @@ const char* shortAssetName(const char* n) { auto pos = saname.rfind(elem); if (pos != std::string::npos) { - return saname.substr(0,pos).c_str(); + saname = saname.substr(0,pos); + break; } } - throw SuffixNotFound(saname); + return saname.c_str(); } bool isAssetPath(const QString& str) { @@ -164,7 +149,7 @@ std::vector gstAssetFolder::getAssetHandles() const { list.push_back(handle); } else { notify(NFY_DEBUG, "Invalid asset found! dirname=%s file=%s", - dir_name_.latin1(), (*it).latin1()); + dir_name_.latin1(), it->latin1()); } } @@ -178,7 +163,7 @@ std::vector gstAssetFolder::getAssetFolders() const { QStringList files = dir.entryList(QDir::Dirs, QDir::Name | QDir::IgnoreCase); for (QStringList::Iterator it = files.begin(); it != files.end(); ++it) { // do not add if this is an asset, or if it starts with a dot ('.') - if (!isAssetPath(*it) && !(*it).startsWith(".")) + if (!isAssetPath(*it) && !it->startsWith(".")) list.push_back(gstAssetFolder(dir.filePath(*it))); } From f9cd8542a7bb90ff8a12abf2d82433bd5d1b6187 Mon Sep 17 00:00:00 2001 From: tst-basilhuffman Date: Sun, 4 Apr 2021 17:49:48 +0000 Subject: [PATCH 5/9] doing some code cleanup --- .../src/fusion/fusionui/AssetChooser.cpp | 19 +++---- .../src/fusion/fusionui/AssetManager.cpp | 54 +++++++++---------- 2 files changed, 36 insertions(+), 37 deletions(-) diff --git a/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp b/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp index 8f99e0f201..1497ea64de 100644 --- a/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp +++ b/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp @@ -83,11 +83,12 @@ AssetItem::AssetItem(QIconView* parent, gstAssetHandle handle) auto name = handle->getName().toStdString(); auto pos = name.rfind('.'); + auto test = shortAssetName(name.c_str()); if (pos != std::string::npos) { name = name.substr(0,pos); } - setText(name.c_str()); + setText(test); Asset asset = handle->getAsset(); AssetDisplayHelper a(asset->type, asset->subtype); @@ -176,9 +177,8 @@ AssetChooser::AssetChooser( } // Insert compatible asset items in view filter combobox of OpenDialog. - for (size_t i = 0; i < compatible_asset_defs.size(); ++i) { - const AssetCategoryDef& asset_category_def = compatible_asset_defs[i]; - AssetDisplayHelper adh(asset_category_def.type, asset_category_def.subtype); + for (const auto& i : compatible_asset_defs) { + AssetDisplayHelper adh(i.type, i.subtype); compatible_asset_types_.push_back(adh); filterCombo->insertItem(adh.GetPixmap(), adh.PrettyName()); } @@ -246,8 +246,9 @@ bool AssetChooser::matchFilter(const gstAssetHandle handle) const { if (match_string_ == all_compatible_assets_filter_text_) { assert(!all_compatible_assets_filter_text_.empty()); - for (size_t i = 0; i < compatible_asset_types_.size(); ++i) { - if (a.PrettyName() == compatible_asset_types_[i].PrettyName()) + + for (const auto& i : compatible_asset_types_) { + if (a.PrettyName() == i.PrettyName()) return true; } return false; @@ -499,9 +500,9 @@ void AssetChooser::updateView(const gstAssetFolder& folder) { // first add all folders // std::vector folders = folder.getAssetFolders(); - for (std::vector::iterator it = folders.begin(); - it != folders.end(); ++it) { - (void)new FolderItem(iconView, *it); + + for (const auto& it : folders) { + (void)new FolderItem(iconView, it); } // diff --git a/earth_enterprise/src/fusion/fusionui/AssetManager.cpp b/earth_enterprise/src/fusion/fusionui/AssetManager.cpp index e673c890bf..deaf54fda5 100644 --- a/earth_enterprise/src/fusion/fusionui/AssetManager.cpp +++ b/earth_enterprise/src/fusion/fusionui/AssetManager.cpp @@ -223,9 +223,9 @@ void AssetFolder::setOpen(bool o) { void AssetFolder::populate() { std::vector folders = folder.getAssetFolders(); - std::vector::iterator it = folders.begin(); - for (; it != folders.end(); ++it) { - (void)new AssetFolder(this, *it); + + for (const auto& it : folders) { + (void)new AssetFolder(this, it); } } @@ -267,9 +267,9 @@ static QPixmap uic_load_pixmap_AssetManager(const QString& name) { } bool DatabaseHasValidVersion(const Asset &asset) { - AssetStorage::VersionList::const_iterator version = asset->versions.begin(); - for (; version != asset->versions.end(); ++version) { - AssetVersion asset_version(*version); + + for (const auto& version : asset->versions) { + AssetVersion asset_version(version); if (asset_version->state != AssetDefs::Succeeded) continue; if (asset_version->subtype == kMapDatabaseSubtype) { @@ -519,8 +519,8 @@ AssetManager::AssetManager(QWidget* parent) { gstProviderSet providers; if (providers.Load()) { - for (unsigned int i = 0; i < providers.items.size(); ++i) { - provider_map_[providers.items[i].id] = providers.items[i].key; + for (const auto& it : providers.items) { + provider_map_[it.id] = it.key; } } } @@ -1197,10 +1197,9 @@ void AssetManager::PushDatabase(const gstAssetHandle& handle) { } std::vector nicknames; - std::vector::const_iterator it = - sc_set.combinations.begin(); - for (; it != sc_set.combinations.end(); ++it) { - nicknames.push_back(it->nickname); + + for (const auto& it : sc_set.combinations) { + nicknames.push_back(it.nickname); } PushDatabaseDialog push_db_dlg(this, asset, nicknames); @@ -1242,10 +1241,10 @@ void AssetManager::PushDatabase(const gstAssetHandle& handle) { Preferences::UpdatePublishServerDbMap(database_name, nickname.toUtf8().constData()); ServerConfig stream_server, search_server; - for (it = sc_set.combinations.begin(); - it != sc_set.combinations.end(); ++it) { - if (nickname == it->nickname) { - stream_server = it->stream; + + for (const auto& it : sc_set.combinations) { + if (nickname == it.nickname) { + stream_server = it.stream; search_server = stream_server; break; } @@ -1330,10 +1329,9 @@ void AssetManager::PublishDatabase(const gstAssetHandle& handle) { } std::vector nicknames; - std::vector::const_iterator it = - sc_set.combinations.begin(); - for (; it != sc_set.combinations.end(); ++it) { - nicknames.push_back(it->nickname); + + for (const auto& it : sc_set.combinations) { + nicknames.push_back(it.nickname); } @@ -1377,10 +1375,10 @@ void AssetManager::PublishDatabase(const gstAssetHandle& handle) { Preferences::UpdatePublishServerDbMap(database_name, nickname.toUtf8().constData()); ServerConfig stream_server, search_server; - for (it = sc_set.combinations.begin(); - it != sc_set.combinations.end(); ++it) { - if (nickname == it->nickname) { - stream_server = it->stream; + + for (const auto& it : sc_set.combinations) { + if (nickname == it.nickname) { + stream_server = it.stream; search_server = stream_server; break; } @@ -1624,10 +1622,10 @@ void AssetManager::assetsChanged(const AssetChanges& changes) { // check to see if any of the changes are in this directory std::set changedHere; - for (AssetChanges::CIterator i = changes.items.begin(); - i != changes.items.end(); ++i) { - if (khDirname(i->ref) == curr) { - changedHere.insert(AssetVersionRef(i->ref).AssetRef()); + + for(const auto& i : changes.items) { + if (khDirname(i.ref) == curr) { + changedHere.insert(AssetVersionRef(i.ref).AssetRef()); } } From 5933db3e687f1183e8f3701fe2349d13fddaadd7 Mon Sep 17 00:00:00 2001 From: tst-basilhuffman Date: Mon, 5 Apr 2021 19:02:23 +0000 Subject: [PATCH 6/9] overloaded shortAssetName --- earth_enterprise/src/fusion/fusionui/AssetBase.cpp | 2 +- .../src/fusion/fusionui/AssetChooser.cpp | 4 ++-- .../src/fusion/fusionui/AssetIconView.cpp | 4 ++-- .../src/fusion/fusionui/AssetManager.cpp | 6 +++--- .../src/fusion/fusionui/AssetProperties.cpp | 2 +- .../src/fusion/fusionui/AssetTableView.cpp | 2 +- .../src/fusion/fusionui/DatabaseWidget.cpp | 12 ++++++------ .../src/fusion/fusionui/LayerProperties.cpp | 2 +- .../src/fusion/fusionui/MapDatabaseWidget.cpp | 8 ++++---- earth_enterprise/src/fusion/fusionui/MapProject.cpp | 4 ++-- .../fusion/fusionui/MercatorMapDatabaseWidget.cpp | 6 +++--- .../src/fusion/fusionui/ProjectManager.cpp | 6 +++--- .../src/fusion/fusionui/PushDatabaseDialog.cpp | 2 +- .../src/fusion/fusionui/RasterProjectWidget.cpp | 2 +- earth_enterprise/src/fusion/fusionui/VectorLayer.cpp | 4 ++-- .../src/fusion/fusionui/VectorProject.cpp | 2 +- earth_enterprise/src/fusion/gst/gstAssetGroup.cpp | 10 ++++++++++ earth_enterprise/src/fusion/gst/gstAssetGroup.h | 2 ++ 18 files changed, 46 insertions(+), 34 deletions(-) diff --git a/earth_enterprise/src/fusion/fusionui/AssetBase.cpp b/earth_enterprise/src/fusion/fusionui/AssetBase.cpp index f9bf760093..3ef6bbe348 100644 --- a/earth_enterprise/src/fusion/fusionui/AssetBase.cpp +++ b/earth_enterprise/src/fusion/fusionui/AssetBase.cpp @@ -292,7 +292,7 @@ void AssetBase::InstallMainWidget() { void AssetBase::SetName(const QString& text) { asset_path_ = text; std::string pretty_name { AssetPrettyName().toStdString() }; - std::string short_name { shortAssetName(text.toUtf8().constData()) }; + std::string short_name { shortAssetName(text) }; setCaption(QString(pretty_name.c_str()) + " : " + short_name.c_str()); emit NameChanged(text); diff --git a/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp b/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp index 1497ea64de..ed0bca8a7f 100644 --- a/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp +++ b/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp @@ -59,7 +59,7 @@ class FolderItem : public QIconViewItem { FolderItem::FolderItem(QIconView* parent, const gstAssetFolder& f) : QIconViewItem(parent), folder(f) { - setText(shortAssetName(f.name().toUtf8().constData())); + setText(shortAssetName(f.name())); AssetDisplayHelper a(AssetDefs::Invalid, std::string()); setPixmap(a.GetPixmap()); setKey(QString("0" + text())); @@ -83,7 +83,7 @@ AssetItem::AssetItem(QIconView* parent, gstAssetHandle handle) auto name = handle->getName().toStdString(); auto pos = name.rfind('.'); - auto test = shortAssetName(name.c_str()); + auto test = shortAssetName(name); if (pos != std::string::npos) { name = name.substr(0,pos); diff --git a/earth_enterprise/src/fusion/fusionui/AssetIconView.cpp b/earth_enterprise/src/fusion/fusionui/AssetIconView.cpp index e380f77a5f..1ea7c69046 100644 --- a/earth_enterprise/src/fusion/fusionui/AssetIconView.cpp +++ b/earth_enterprise/src/fusion/fusionui/AssetIconView.cpp @@ -46,8 +46,8 @@ AssetIcon::AssetIcon(QIconView* parent, gstAssetHandle handle, int initsz) if (defaultImage == NULL) defaultImage = new QImage(uic_load_pixmap("preview_default.png"). convertToImage()); - - setText(shortAssetName(handle->getName().toUtf8().constData())); + auto name = shortAssetName(handle->getName()); + setText(name); QImage img; AssetVersion ver(handle->getAsset()->CurrVersionRef()); diff --git a/earth_enterprise/src/fusion/fusionui/AssetManager.cpp b/earth_enterprise/src/fusion/fusionui/AssetManager.cpp index deaf54fda5..a8b12ff98b 100644 --- a/earth_enterprise/src/fusion/fusionui/AssetManager.cpp +++ b/earth_enterprise/src/fusion/fusionui/AssetManager.cpp @@ -1017,7 +1017,7 @@ void AssetManager::ShowAssetMenu(const gstAssetHandle& asset_handle, // might get redrawn after the menu has popped-up AssetDisplayHelper a(current_asset->type, current_asset->subtype); - std::string shortName = shortAssetName(asset_handle->getName().toStdString().c_str()); + std::string shortName = shortAssetName(asset_handle->getName()); menu.insertItem(a.GetPixmap(), shortName.c_str()); @@ -1237,7 +1237,7 @@ void AssetManager::PushDatabase(const gstAssetHandle& handle) { // Update the preferences with the user's choice. We want to remember these // choices so that we can automatically select this server next time they // push/publish. - std::string database_name = shortAssetName(asset->GetRef().toString().c_str()); + std::string database_name = shortAssetName(asset->GetRef().toString()); Preferences::UpdatePublishServerDbMap(database_name, nickname.toUtf8().constData()); ServerConfig stream_server, search_server; @@ -1371,7 +1371,7 @@ void AssetManager::PublishDatabase(const gstAssetHandle& handle) { // Update the preferences with the user's choice. We want to remember these // choices so that we can automatically select this server next time they // push/publish. - std::string database_name = shortAssetName(asset->GetRef().toString().c_str()); + std::string database_name = shortAssetName(asset->GetRef().toString()); Preferences::UpdatePublishServerDbMap(database_name, nickname.toUtf8().constData()); ServerConfig stream_server, search_server; diff --git a/earth_enterprise/src/fusion/fusionui/AssetProperties.cpp b/earth_enterprise/src/fusion/fusionui/AssetProperties.cpp index 7f1025d0c1..8651b38e36 100644 --- a/earth_enterprise/src/fusion/fusionui/AssetProperties.cpp +++ b/earth_enterprise/src/fusion/fusionui/AssetProperties.cpp @@ -70,7 +70,7 @@ AssetProperties::AssetProperties( QWidget* parent, const gstAssetHandle &handle versionsList->setSorting( 0, false ); Asset asset = handle->getAsset(); - nameLabel->setText( shortAssetName( handle->getName().toUtf8().constData() ) ); + nameLabel->setText( shortAssetName( handle->getName()) ); typeLabel->setText( ToString( asset->type ).c_str() ); subTypeLabel->setText( asset->PrettySubtype().c_str() ); diff --git a/earth_enterprise/src/fusion/fusionui/AssetTableView.cpp b/earth_enterprise/src/fusion/fusionui/AssetTableView.cpp index f3bd5734d0..74483ef32b 100644 --- a/earth_enterprise/src/fusion/fusionui/AssetTableView.cpp +++ b/earth_enterprise/src/fusion/fusionui/AssetTableView.cpp @@ -45,7 +45,7 @@ AssetTableItem::AssetTableItem(QTable* table, gstAssetHandle handle) Asset asset = handle->getAsset(); AssetDisplayHelper a(asset->type, asset->PrettySubtype()); setPixmap(a.GetPixmap()); - setText(shortAssetName(handle->getName().toUtf8().constData())); + setText(shortAssetName(handle->getName())); } AssetTableItem::~AssetTableItem() { diff --git a/earth_enterprise/src/fusion/fusionui/DatabaseWidget.cpp b/earth_enterprise/src/fusion/fusionui/DatabaseWidget.cpp index e1fce30a2a..5af7e2ef9e 100644 --- a/earth_enterprise/src/fusion/fusionui/DatabaseWidget.cpp +++ b/earth_enterprise/src/fusion/fusionui/DatabaseWidget.cpp @@ -37,7 +37,7 @@ void DatabaseWidget::Prefill(const DatabaseEditRequest& request) { if (request.config.vectorProject.size() != 0) { projects.push_back(request.config.vectorProject); - vector_project_label->setText(shortAssetName(request.config.vectorProject.c_str())); + vector_project_label->setText(shortAssetName(request.config.vectorProject)); } else { vector_project_label->setText(empty_text); } @@ -49,14 +49,14 @@ void DatabaseWidget::Prefill(const DatabaseEditRequest& request) { } else { if (request.config.imageryProject.size() != 0) { projects.push_back(request.config.imageryProject); - imagery_project_label->setText(shortAssetName(request.config.imageryProject.c_str())); + imagery_project_label->setText(shortAssetName(request.config.imageryProject)); } else { imagery_project_label->setText(empty_text); } if (request.config.terrainProject.size() != 0) { projects.push_back(request.config.terrainProject); - terrain_project_label->setText(shortAssetName(request.config.terrainProject.c_str())); + terrain_project_label->setText(shortAssetName(request.config.terrainProject)); } else { terrain_project_label->setText(empty_text); } @@ -97,7 +97,7 @@ void DatabaseWidget::ChooseVectorProject() { if (!chooser.getFullPath(newpath)) return; - vector_project_label->setText(shortAssetName(newpath.toUtf8().constData())); + vector_project_label->setText(shortAssetName(newpath)); } void DatabaseWidget::ChooseImageryProject() { @@ -110,7 +110,7 @@ void DatabaseWidget::ChooseImageryProject() { if (!chooser.getFullPath(newpath)) return; - imagery_project_label->setText(shortAssetName(newpath.toUtf8().constData())); + imagery_project_label->setText(shortAssetName(newpath)); } void DatabaseWidget::ChooseTerrainProject() { @@ -123,7 +123,7 @@ void DatabaseWidget::ChooseTerrainProject() { if (!chooser.getFullPath(newpath)) return; - terrain_project_label->setText(shortAssetName(newpath.toUtf8().constData())); + terrain_project_label->setText(shortAssetName(newpath)); } void DatabaseWidget::ClearVectorProject() { diff --git a/earth_enterprise/src/fusion/fusionui/LayerProperties.cpp b/earth_enterprise/src/fusion/fusionui/LayerProperties.cpp index 9d94a4faf8..b548e78f29 100644 --- a/earth_enterprise/src/fusion/fusionui/LayerProperties.cpp +++ b/earth_enterprise/src/fusion/fusionui/LayerProperties.cpp @@ -54,7 +54,7 @@ LayerProperties::LayerProperties(QWidget* parent, const LayerConfig& config, layer_config_.AssignUuidIfEmpty(); uuidEdit->setText(layer_config_.asset_uuid_.c_str()); - assetNameLabel->setText(shortAssetName(layer_config_.assetRef.c_str())); + assetNameLabel->setText(shortAssetName(layer_config_.assetRef)); preserveTextSpin->setValue(layer_config_.preserveTextLevel); isVisibleCheck->setChecked(layer_config_.isVisible); diff --git a/earth_enterprise/src/fusion/fusionui/MapDatabaseWidget.cpp b/earth_enterprise/src/fusion/fusionui/MapDatabaseWidget.cpp index c7282c501d..b2fbdae861 100644 --- a/earth_enterprise/src/fusion/fusionui/MapDatabaseWidget.cpp +++ b/earth_enterprise/src/fusion/fusionui/MapDatabaseWidget.cpp @@ -42,7 +42,7 @@ void MapDatabaseWidget::Prefill(const MapDatabaseEditRequest& request) { if (request.config.mapProject.size() != 0) { projects.push_back(request.config.mapProject); - map_project_label->setText(shortAssetName(request.config.mapProject.c_str())); + map_project_label->setText(shortAssetName(request.config.mapProject)); } else { map_project_label->setText(empty_text); } @@ -53,7 +53,7 @@ void MapDatabaseWidget::Prefill(const MapDatabaseEditRequest& request) { if (request.config.imageryProject.size() != 0) { projects.push_back(request.config.imageryProject); imagery_project_label->setText( - shortAssetName(request.config.imageryProject.c_str())); + shortAssetName(request.config.imageryProject)); } else { imagery_project_label->setText(empty_text); } @@ -107,7 +107,7 @@ void MapDatabaseWidget::ChooseMapProject() { if (!chooser.getFullPath(newpath)) return; - map_project_label->setText(shortAssetName(newpath.toUtf8().constData())); + map_project_label->setText(shortAssetName(newpath)); } void MapDatabaseWidget::ChooseImageryProject() { @@ -120,7 +120,7 @@ void MapDatabaseWidget::ChooseImageryProject() { if (!chooser.getFullPath(newpath)) return; - imagery_project_label->setText(shortAssetName(newpath.toUtf8().constData())); + imagery_project_label->setText(shortAssetName(newpath)); } void MapDatabaseWidget::ClearMapProject() { diff --git a/earth_enterprise/src/fusion/fusionui/MapProject.cpp b/earth_enterprise/src/fusion/fusionui/MapProject.cpp index 53201e70fe..0878ac32da 100644 --- a/earth_enterprise/src/fusion/fusionui/MapProject.cpp +++ b/earth_enterprise/src/fusion/fusionui/MapProject.cpp @@ -84,12 +84,12 @@ void MapLayerItem::Init() { setText(0, layer_item_config_.legend.GetValue().defaultLocale.name); } - setText(1, shortAssetName(layer_item_config_.assetRef.c_str())); + setText(1, shortAssetName(layer_item_config_.assetRef)); AssetDisplayHelper a(layer_asset->type, layer_asset->subtype); setPixmap(1, a.GetPixmap()); } else { setText(0, ""); - setText(1, shortAssetName(layer_item_config_.assetRef.c_str())); + setText(1, shortAssetName(layer_item_config_.assetRef)); setPixmap(1, AssetDisplayHelper::Pixmap(AssetDisplayHelper::Key_Unknown)); } } diff --git a/earth_enterprise/src/fusion/fusionui/MercatorMapDatabaseWidget.cpp b/earth_enterprise/src/fusion/fusionui/MercatorMapDatabaseWidget.cpp index 0f2bb5d35f..c7c79d65e9 100644 --- a/earth_enterprise/src/fusion/fusionui/MercatorMapDatabaseWidget.cpp +++ b/earth_enterprise/src/fusion/fusionui/MercatorMapDatabaseWidget.cpp @@ -45,7 +45,7 @@ void MercatorMapDatabaseWidget::Prefill(const MapDatabaseEditRequest& request) { if (request.config.mapProject.size() != 0) { projects.push_back(request.config.mapProject); - map_project_label->setText(shortAssetName(request.config.mapProject.c_str())); + map_project_label->setText(shortAssetName(request.config.mapProject)); } else { map_project_label->setText(empty_text); } @@ -113,7 +113,7 @@ void MercatorMapDatabaseWidget::ChooseMapProject() { if (!chooser.getFullPath(newpath)) return; - map_project_label->setText(shortAssetName(newpath.toUtf8().constData())); + map_project_label->setText(shortAssetName(newpath)); } void MercatorMapDatabaseWidget::ChooseImageryProject() { @@ -153,6 +153,6 @@ void MercatorMapDatabaseWidget::SetImageryProject(const QString& path) { ClearImageryProject(); } else { imagery_project_path_ = path; - imagery_project_label->setText(shortAssetName(imagery_project_path_.toUtf8().constData())); + imagery_project_label->setText(shortAssetName(imagery_project_path_)); } } diff --git a/earth_enterprise/src/fusion/fusionui/ProjectManager.cpp b/earth_enterprise/src/fusion/fusionui/ProjectManager.cpp index 7e49a4d153..aea911d081 100644 --- a/earth_enterprise/src/fusion/fusionui/ProjectManager.cpp +++ b/earth_enterprise/src/fusion/fusionui/ProjectManager.cpp @@ -1567,7 +1567,7 @@ void ProjectManager::AddAssetLayer(const char* assetname) { isasset); if (newsource) { std::string basename = khBasename(asset->GetRef().toString()); - QString layername = shortAssetName(basename.c_str()); + QString layername = shortAssetName(basename); gstLayer* layer = CreateNewLayer(layername, newsource, 0 /* src layer num */, asset->GetRef()); @@ -2279,10 +2279,10 @@ void ProjectManager::contentsDropEvent(QDropEvent* e) { Asset asset(AssetDefs::FilenameToAssetPath(it->toUtf8().constData())); AssetVersion ver(asset->GetLastGoodVersionRef()); if (ver) { - AddAssetLayer((*it).latin1()); + AddAssetLayer(it->latin1()); } else { nogoodversions += QString(" " ) - + QString(shortAssetName(it->toUtf8().constData())) + + QString(shortAssetName(*it)) + QString("\n"); } } diff --git a/earth_enterprise/src/fusion/fusionui/PushDatabaseDialog.cpp b/earth_enterprise/src/fusion/fusionui/PushDatabaseDialog.cpp index b931f3d713..c523cf9bbc 100644 --- a/earth_enterprise/src/fusion/fusionui/PushDatabaseDialog.cpp +++ b/earth_enterprise/src/fusion/fusionui/PushDatabaseDialog.cpp @@ -30,7 +30,7 @@ PushDatabaseDialog::PushDatabaseDialog( const std::vector& nicknames) : PushDatabaseDialogBase(parent, 0, false, 0) { - std::string database_name = shortAssetName(asset->GetRef().toString().c_str()); + std::string database_name = shortAssetName(asset->GetRef()); db_name_label->setText(database_name.c_str()); std::vector::const_iterator nickname = nicknames.begin(); diff --git a/earth_enterprise/src/fusion/fusionui/RasterProjectWidget.cpp b/earth_enterprise/src/fusion/fusionui/RasterProjectWidget.cpp index 53af481b72..411928d6a9 100644 --- a/earth_enterprise/src/fusion/fusionui/RasterProjectWidget.cpp +++ b/earth_enterprise/src/fusion/fusionui/RasterProjectWidget.cpp @@ -223,7 +223,7 @@ QString RasterLayerItem::text(int col) const { config_.overridemax)); } - return QString(shortAssetName(config_.dataAsset.c_str())) + level; + return QString(shortAssetName(config_.dataAsset)) + level; } else { return QString(); } diff --git a/earth_enterprise/src/fusion/fusionui/VectorLayer.cpp b/earth_enterprise/src/fusion/fusionui/VectorLayer.cpp index a44e1e823d..95958f89a6 100644 --- a/earth_enterprise/src/fusion/fusionui/VectorLayer.cpp +++ b/earth_enterprise/src/fusion/fusionui/VectorLayer.cpp @@ -42,7 +42,7 @@ void VectorLayerWidget::Prefill(const VectorLayerXEditRequest& req) { if (req.config.vectorResource.empty()) { vector_resource_label->setText(empty_text); } else { - vector_resource_label->setText(shortAssetName(req.config.vectorResource.c_str())); + vector_resource_label->setText(shortAssetName(req.config.vectorResource)); } } @@ -66,7 +66,7 @@ void VectorLayerWidget::chooseVectorResource() { if (!chooser.getFullPath(newpath)) return; - vector_resource_label->setText(shortAssetName(newpath.toUtf8().constData())); + vector_resource_label->setText(shortAssetName(newpath)); } // **************************************************************************** diff --git a/earth_enterprise/src/fusion/fusionui/VectorProject.cpp b/earth_enterprise/src/fusion/fusionui/VectorProject.cpp index c7895fb1ae..2279a8a9a7 100644 --- a/earth_enterprise/src/fusion/fusionui/VectorProject.cpp +++ b/earth_enterprise/src/fusion/fusionui/VectorProject.cpp @@ -109,7 +109,7 @@ void VectorLayerItem::Init() { setText(0, layer_config_.defaultLocale.name_); - setText(1, shortAssetName(layer_config_.assetRef.c_str())); + setText(1, shortAssetName(layer_config_.assetRef)); std::vector< unsigned int> fill_rgba, outline_rgba; for (std::vector::iterator rule = layer_config_.displayRules.begin(); diff --git a/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp b/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp index d24cef3c10..42c3ef3a16 100644 --- a/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp +++ b/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp @@ -47,6 +47,16 @@ const char* shortAssetName(const char* n) { return saname.c_str(); } +const char* shortAssetName(const std::string& str) +{ + return shortAssetName(str.c_str()); +} + +const char* shortAssetName(const QString& str) +{ + return shortAssetName(str.toStdString().c_str()); +} + bool isAssetPath(const QString& str) { static QRegExp rx(".*\\.k[vit](asset|project)$|" ".*\\.k[i](masset|mproject)$|" diff --git a/earth_enterprise/src/fusion/gst/gstAssetGroup.h b/earth_enterprise/src/fusion/gst/gstAssetGroup.h index cb852b822f..f15e454877 100644 --- a/earth_enterprise/src/fusion/gst/gstAssetGroup.h +++ b/earth_enterprise/src/fusion/gst/gstAssetGroup.h @@ -32,6 +32,8 @@ class gstAssetHandleImpl; typedef khRefGuard gstAssetHandle; const char* shortAssetName(const char*); +const char* shortAssetName(const std::string&); +const char* shortAssetName(const QString&); bool isAssetPath(const QString&); // ----------------------------------------------------------------------------- From 7e091d16e49b4c301118eb63f770ab73a9da25fa Mon Sep 17 00:00:00 2001 From: tst-basilhuffman Date: Mon, 5 Apr 2021 19:29:20 +0000 Subject: [PATCH 7/9] assetchooser works --- earth_enterprise/src/fusion/fusionui/AssetChooser.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp b/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp index ed0bca8a7f..a67bd6351e 100644 --- a/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp +++ b/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp @@ -81,14 +81,8 @@ class AssetItem : public QIconViewItem { AssetItem::AssetItem(QIconView* parent, gstAssetHandle handle) : QIconViewItem(parent), assetHandle(handle) { - auto name = handle->getName().toStdString(); - auto pos = name.rfind('.'); - auto test = shortAssetName(name); - if (pos != std::string::npos) - { - name = name.substr(0,pos); - } - setText(test); + auto saname = shortAssetName(handle->getName()); + setText(saname); Asset asset = handle->getAsset(); AssetDisplayHelper a(asset->type, asset->subtype); From b296ff2afbaab4425f3176d3ac85972823d4320c Mon Sep 17 00:00:00 2001 From: tst-basilhuffman Date: Mon, 5 Apr 2021 22:05:52 +0000 Subject: [PATCH 8/9] refactored again --- earth_enterprise/src/fusion/fusionui/AssetChooser.cpp | 7 ++++--- earth_enterprise/src/fusion/fusionui/AssetManager.cpp | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp b/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp index a67bd6351e..f18439594a 100644 --- a/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp +++ b/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp @@ -307,9 +307,10 @@ void AssetChooser::accept() { // here AssetItem* assetItem = dynamic_cast(item); if (assetItem != NULL) { - std::string temp { shortAssetName(assetItem->getAssetHandle()->getName() - .toStdString().c_str()) }; - nameEdit->setText(temp.c_str()); + // std::string temp { shortAssetName(assetItem->getAssetHandle()->getName() + // .toStdString().c_str()) }; + auto saname = shortAssetName(assetItem->getAssetHandle()->getName()); + nameEdit->setText(saname); gstAssetHandle asset_handle = assetItem->getAssetHandle(); Asset asset = asset_handle->getAsset(); type_ = asset->type; diff --git a/earth_enterprise/src/fusion/fusionui/AssetManager.cpp b/earth_enterprise/src/fusion/fusionui/AssetManager.cpp index a8b12ff98b..ed41f00802 100644 --- a/earth_enterprise/src/fusion/fusionui/AssetManager.cpp +++ b/earth_enterprise/src/fusion/fusionui/AssetManager.cpp @@ -1811,7 +1811,7 @@ void AssetManager::UpdateTableItem(int row, gstAssetHandle handle, int bpos = aname.rfind('/') + 1, epos = aname.rfind('.'); aname = aname.substr(bpos,epos-bpos); - if (aname != std::string(assetTableView->GetItem(i)->text().toUtf8().constData())) + if (aname != assetTableView->GetItem(i)->text().toStdString()) { assetTableView->GetItem(i)->setText(aname.c_str()); } From be9fea28747ef86061d496a38d1608502d87b136 Mon Sep 17 00:00:00 2001 From: tst-basilhuffman Date: Wed, 7 Apr 2021 16:03:50 +0000 Subject: [PATCH 9/9] addressing comments --- earth_enterprise/src/fusion/fusionui/AssetChooser.cpp | 2 -- earth_enterprise/src/fusion/gst/gstAssetGroup.cpp | 9 +++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp b/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp index f18439594a..411b024735 100644 --- a/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp +++ b/earth_enterprise/src/fusion/fusionui/AssetChooser.cpp @@ -307,8 +307,6 @@ void AssetChooser::accept() { // here AssetItem* assetItem = dynamic_cast(item); if (assetItem != NULL) { - // std::string temp { shortAssetName(assetItem->getAssetHandle()->getName() - // .toStdString().c_str()) }; auto saname = shortAssetName(assetItem->getAssetHandle()->getName()); nameEdit->setText(saname); gstAssetHandle asset_handle = assetItem->getAssetHandle(); diff --git a/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp b/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp index 42c3ef3a16..251d259af0 100644 --- a/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp +++ b/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp @@ -34,6 +34,15 @@ const char* shortAssetName(const char* n) { std::string saname { n }; + /* + code takes in a long asset name, checks to see if it has one + of the appropriate suffixes (e.g. .kiasset, kmmdatabase, .kmlayer, etc) + if it is found, it strils off the suffix and returns the short name, + if a known suffix is not found, the long asset name will be returned + + i.e. shortAssetName("AnAssetName.kiasset") will return "AnAssetName", + shortAssetName("AnAssetName.notvalid") will return "AnAssetName.notvalid" + */ for (const auto& elem : suffixes) { auto pos = saname.rfind(elem);