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 703d55b60f..411b024735 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 @@ -62,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())); @@ -84,13 +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('.'); - if (pos != std::string::npos) - { - name = name.substr(0,pos); - } - setText(name.c_str()); + auto saname = shortAssetName(handle->getName()); + setText(saname); Asset asset = handle->getAsset(); AssetDisplayHelper a(asset->type, asset->subtype); @@ -179,9 +171,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()); } @@ -249,8 +240,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; @@ -315,9 +307,8 @@ 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()); + auto saname = shortAssetName(assetItem->getAssetHandle()->getName()); + nameEdit->setText(saname); gstAssetHandle asset_handle = assetItem->getAssetHandle(); Asset asset = asset_handle->getAsset(); type_ = asset->type; @@ -502,9 +493,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/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 69511a91ee..ed41f00802 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; } } } @@ -1016,7 +1016,10 @@ 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())); + + std::string shortName = shortAssetName(asset_handle->getName()); + + menu.insertItem(a.GetPixmap(), shortName.c_str()); menu.insertSeparator(); menu.insertSeparator(); @@ -1194,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); @@ -1235,14 +1237,14 @@ 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; - 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; } @@ -1327,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); } @@ -1370,14 +1371,14 @@ 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; - 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; } @@ -1621,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()); } } @@ -1810,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()); } 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 9e11dd7031..251d259af0 100644 --- a/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp +++ b/earth_enterprise/src/fusion/gst/gstAssetGroup.cpp @@ -18,26 +18,52 @@ #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; - } + + static const std::vector suffixes = + { + kVectorAssetSuffix, kImageryAssetSuffix, kMercatorImageryAssetSuffix, + kTerrainAssetSuffix, kVectorProjectSuffix, kImageryProjectSuffix, + kMercatorImageryProjectSuffix, kTerrainProjectSuffix, + kDatabaseSuffix, kMapLayerSuffix, kMapProjectSuffix, + kMapDatabaseSuffix, kMercatorMapDatabaseSuffix, kVectorLayerSuffix + }; + + 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); + if (pos != std::string::npos) + { + saname = saname.substr(0,pos); + break; + } } - return sname.toUtf8().constData(); + + 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) { @@ -70,7 +96,7 @@ bool gstAssetHandleImpl::isValid() const { } Asset gstAssetHandleImpl::getAsset() const { - std::string rpath { relativePath().toUtf8().constData() }; + std::string rpath { relativePath().toStdString() }; return Asset(rpath); } @@ -142,7 +168,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()); } } @@ -156,7 +182,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))); } 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&); // -----------------------------------------------------------------------------