Skip to content

Commit

Permalink
vkconfig3: Fix preset label UI in the layer settings section
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Nov 20, 2024
1 parent 26a38e3 commit 91f2561
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 26 deletions.
12 changes: 8 additions & 4 deletions vkconfig_core/configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,12 @@ std::string Configurator::LogConfiguration(const std::string& configuration_key)
if (parameter.builtin == LAYER_BUILTIN_UNORDERED) {
log += format(" * %s: %s\n", parameter.key.c_str(), ::GetToken(parameter.control));
} else {
log += format(" * %s - %s: %s\n", parameter.key.c_str(), parameter.api_version.str().c_str(),
::GetToken(parameter.control));
if (this->layers.Find(parameter.key, parameter.api_version) == nullptr) {
log += format(" * %s - Missing: %s\n", parameter.key.c_str(), ::GetToken(parameter.control));
} else {
log += format(" * %s - %s: %s\n", parameter.key.c_str(), parameter.api_version.str().c_str(),
::GetToken(parameter.control));
}
log += format(" Layer manifest path: %s\n", parameter.manifest.AbsolutePath().c_str());
log += format(" Layer settings export: %s\n", parameter.override_settings ? "enabled" : "disabled");
}
Expand Down Expand Up @@ -612,10 +616,10 @@ std::string Configurator::Log() const {

log += format("%s Settings:\n", VKCONFIG_NAME);
log += format(" - Vulkan Loader configuration scope: %s\n", ::GetLabel(this->GetExecutableScope()));
log += format(" * Vulkan Loader settings file: %s\n", ::Get(Path::LOADER_SETTINGS).AbsolutePath().c_str());
log += format(" * Loader settings: %s\n", ::Get(Path::LOADER_SETTINGS).AbsolutePath().c_str());

if (this->GetExecutableScope() == EXECUTABLE_ANY || this->GetExecutableScope() == EXECUTABLE_ALL) {
log += format(" * Vulkan Layers settings file: %s\n", ::Get(Path::LAYERS_SETTINGS).AbsolutePath().c_str());
log += format(" * Layers settings: %s\n", ::Get(Path::LAYERS_SETTINGS).AbsolutePath().c_str());
}

if (this->GetExecutableScope() == EXECUTABLE_ANY || this->GetExecutableScope() == EXECUTABLE_ALL) {
Expand Down
8 changes: 4 additions & 4 deletions vkconfig_core/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
#include <string>
#include <algorithm>

const char* Layer::NO_PRESET = "User-Defined Settings";

bool operator<(const LayersPathInfo& a, const LayersPathInfo& b) { return a.path.RelativePath() < b.path.RelativePath(); }

bool Found(const std::vector<LayersPathInfo>& data, const Path& path) {
Expand Down Expand Up @@ -130,9 +128,11 @@ std::string Layer::GetActualControlTooltip() const {
}
}

std::string Layer::FindPresetLabel(const SettingDataSet& settings) const {
int Layer::FindPresetIndex(const SettingDataSet& settings) const {
for (std::size_t i = 0, n = this->presets.size(); i < n; ++i) {
if (HasPreset(settings, this->presets[i].settings)) return this->presets[i].label;
if (::HasPreset(settings, this->presets[i].settings)) {
return static_cast<int>(i);
}
}

return NO_PRESET;
Expand Down
4 changes: 2 additions & 2 deletions vkconfig_core/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ enum { LAYER_LOAD_COUNT = LAYER_LOAD_LAST - LAYER_LOAD_FIRST + 1 };

class Layer {
public:
static const char* NO_PRESET;
static const int NO_PRESET = -1;

Layer();
Layer(const std::string& key);
Expand All @@ -73,7 +73,7 @@ class Layer {
LayerControl GetActualControl() const;
std::string GetActualControlTooltip() const;

std::string FindPresetLabel(const SettingDataSet& settings) const;
int FindPresetIndex(const SettingDataSet& settings) const;

SettingMeta* Instantiate(SettingMetaSet& meta_set, const std::string& key, const SettingType type);

Expand Down
39 changes: 25 additions & 14 deletions vkconfig_gui/settings_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,8 @@ void SettingsTreeManager::CreateGUI() {
{
this->ui->configurations_presets->blockSignals(true);
this->ui->configurations_presets->clear();
preset_labels.clear();
if (!layer->presets.empty()) {
this->ui->configurations_presets->addItem(Layer::NO_PRESET);
preset_labels.push_back(Layer::NO_PRESET);
this->ui->configurations_presets->addItem("User-Defined Settings");

for (std::size_t i = 0, n = layer->presets.size(); i < n; ++i) {
const LayerPreset &layer_preset = layer->presets[i];
Expand All @@ -116,11 +114,12 @@ void SettingsTreeManager::CreateGUI() {
}

this->ui->configurations_presets->addItem((layer_preset.label + " Preset").c_str());
preset_labels.push_back(layer_preset.label);
}

this->connect(this->ui->configurations_presets, SIGNAL(currentIndexChanged(int)), this, SLOT(OnPresetChanged(int)));
this->ui->configurations_presets->setVisible(true);

this->RefreshPresetLabel();
} else {
this->ui->configurations_presets->setVisible(false);
}
Expand Down Expand Up @@ -388,27 +387,39 @@ void SettingsTreeManager::OnLayerVersionChanged() {
}

void SettingsTreeManager::OnPresetChanged(int combox_preset_index) {
assert(combox_preset_index >= 0 && static_cast<std::size_t>(combox_preset_index) < preset_labels.size());
const std::string &preset_label = preset_labels[combox_preset_index];

if (preset_label == Layer::NO_PRESET) {
return;
}
const int preset_index = combox_preset_index - 1;

Configurator &configurator = Configurator::Get();
Parameter *parameter = configurator.GetActiveParameter();
assert(parameter != nullptr);

if (preset_index == Layer::NO_PRESET) {
return;
}

const Layer *layer = configurator.layers.Find(parameter->key.c_str(), parameter->api_version);

const LayerPreset *preset = GetPreset(layer->presets, preset_label.c_str());
assert(preset != nullptr);
parameter->ApplyPresetSettings(*preset);
assert(preset_index >= 0 && static_cast<std::size_t>(preset_index) < layer->presets.size());

const LayerPreset &preset = layer->presets[preset_index];
parameter->ApplyPresetSettings(preset);

this->Refresh(REFRESH_ENABLE_AND_STATE);
}

void SettingsTreeManager::OnSettingChanged() { this->Refresh(REFRESH_ENABLE_ONLY); }
void SettingsTreeManager::OnSettingChanged() {
this->RefreshPresetLabel();
this->Refresh(REFRESH_ENABLE_ONLY);
}

void SettingsTreeManager::RefreshPresetLabel() {
Configurator &configurator = Configurator::Get();
const Parameter *parameter = configurator.GetActiveParameter();
const Layer *layer = configurator.layers.FindFromManifest(parameter->manifest);

const int preset_index = layer->FindPresetIndex(parameter->settings) + 1;
this->ui->configurations_presets->setCurrentIndex(preset_index);
}

void SettingsTreeManager::RefreshVersion() {
if (this->layer_version != nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion vkconfig_gui/settings_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class SettingsTreeManager : public QObject {
void GetTreeState(QByteArray &byte_array, QTreeWidgetItem *top_item);
int SetTreeState(QByteArray &byte_array, int index, QTreeWidgetItem *top_item);

void RefreshPresetLabel();
void RefreshVersion();
void Refresh(RefreshAreas refresh_areas);

Expand All @@ -70,5 +71,4 @@ class SettingsTreeManager : public QObject {

std::shared_ptr<Ui::MainWindow> ui;
LayerVersionComboBox *layer_version = nullptr;
std::vector<std::string> preset_labels; // The preset in the combobox
};
2 changes: 1 addition & 1 deletion vkconfig_gui/widget_tab_configurations_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ConfigurationLayerWidget::ConfigurationLayerWidget(TabConfigurations *tab, const
decorated_name += format(" (%s)", GetToken(layer->status));
}
} else if (!layer_found) {
decorated_name += " (Missing)";
decorated_name += " - Missing";
}
/*
if (layer_versions.empty()) {
Expand Down

0 comments on commit 91f2561

Please sign in to comment.