Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal-apps
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f77e89de117f
Choose a base ref
...
head repository: ngscopeclient/scopehal-apps
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: aeac6656259e
Choose a head ref
  • 4 commits
  • 6 files changed
  • 2 contributors

Commits on Oct 27, 2020

  1. Copy the full SHA
    1c67a27 View commit details
  2. Copy the full SHA
    b0de5ae View commit details
  3. Removed debug code

    nshcat committed Oct 27, 2020
    Copy the full SHA
    65e9ace View commit details
  4. Merge pull request #258 from azonenberg/kathi_dev

    Implemented visibility support for preferences
    azonenberg authored Oct 27, 2020
    Copy the full SHA
    aeac665 View commit details
6 changes: 6 additions & 0 deletions src/glscopeclient/Preference.cpp
Original file line number Diff line number Diff line change
@@ -54,6 +54,11 @@ PreferenceType Preference::GetType() const
return m_type;
}

bool Preference::GetIsVisible() const
{
return m_isVisible;
}

bool Preference::GetBool() const
{
if(m_type != PreferenceType::Boolean)
@@ -105,6 +110,7 @@ void Preference::MoveFrom(Preference& other)
m_identifier = move(other.m_identifier);
m_description = move(other.m_description);
m_label = move(other.m_label);
m_isVisible = move(other.m_isVisible);

switch(other.m_type)
{
18 changes: 10 additions & 8 deletions src/glscopeclient/Preference.h
Original file line number Diff line number Diff line change
@@ -63,30 +63,30 @@ class Preference

public:
// Taking string as value and then moving is intended
Preference(std::string identifier, std::string label, std::string description, bool defaultValue)
Preference(std::string identifier, std::string label, std::string description, bool defaultValue, bool isVisible = true)
: m_identifier{std::move(identifier)}, m_label{std::move(label)}, m_description{std::move(description)},
m_type{PreferenceType::Boolean}
m_type{PreferenceType::Boolean}, m_isVisible{isVisible}
{
new (&m_value) bool(defaultValue);
}

Preference(std::string identifier, std::string label, std::string description, std::string defaultValue)
Preference(std::string identifier, std::string label, std::string description, std::string defaultValue, bool isVisible = true)
: m_identifier{std::move(identifier)}, m_label{std::move(label)}, m_description{std::move(description)},
m_type{PreferenceType::String}
m_type{PreferenceType::String}, m_isVisible{isVisible}
{
new (&m_value) std::string(std::move(defaultValue));
}

Preference(std::string identifier, std::string label, std::string description, const char* defaultValue)
Preference(std::string identifier, std::string label, std::string description, const char* defaultValue, bool isVisible = true)
: m_identifier{std::move(identifier)}, m_label{std::move(label)}, m_description{std::move(description)},
m_type{PreferenceType::String}
m_type{PreferenceType::String}, m_isVisible{isVisible}
{
new (&m_value) std::string(defaultValue);
}

Preference(std::string identifier, std::string label, std::string description, double defaultValue)
Preference(std::string identifier, std::string label, std::string description, double defaultValue, bool isVisible = true)
: m_identifier{std::move(identifier)}, m_label{std::move(label)}, m_description{std::move(description)},
m_type{PreferenceType::Real}
m_type{PreferenceType::Real}, m_isVisible{isVisible}
{
new (&m_value) double(defaultValue);
}
@@ -120,6 +120,7 @@ class Preference
double GetReal() const;
const std::string& GetString() const;
std::string ToString() const;
bool GetIsVisible() const;

void SetBool(bool value);
void SetReal(double value);
@@ -155,6 +156,7 @@ class Preference
std::string m_description;
PreferenceType m_type;
PreferenceValue m_value;
bool m_isVisible;
};

#endif // Preference_h
33 changes: 21 additions & 12 deletions src/glscopeclient/PreferenceDialog.cpp
Original file line number Diff line number Diff line change
@@ -66,6 +66,9 @@ void PreferencePage::CreateWidgets()
continue;

auto& preference = node->AsPreference();

if(!preference.GetIsVisible())
continue;

switch(preference.GetType())
{
@@ -250,14 +253,17 @@ void PreferenceDialog::ProcessCategory(PreferenceCategory& category, Gtk::TreeMo
{
auto& subCategory = node->AsCategory();

unique_ptr<PreferencePage> pagePtr{ new PreferencePage(subCategory) };
if(subCategory.IsVisible())
{
unique_ptr<PreferencePage> pagePtr{ new PreferencePage(subCategory) };

Gtk::TreeModel::Row childrow = *(m_treeModel->append(parent.children()));
childrow[m_columns.m_col_category] = identifier.c_str();
childrow[m_columns.m_col_page] = pagePtr.get();
Gtk::TreeModel::Row childrow = *(m_treeModel->append(parent.children()));
childrow[m_columns.m_col_category] = identifier.c_str();
childrow[m_columns.m_col_page] = pagePtr.get();

ProcessCategory(subCategory, childrow);
m_pages.push_back(std::move(pagePtr));
ProcessCategory(subCategory, childrow);
m_pages.push_back(std::move(pagePtr));
}
}
}
}
@@ -273,13 +279,16 @@ void PreferenceDialog::ProcessRootCategories(PreferenceCategory& root)
{
auto& subCategory = node->AsCategory();

unique_ptr<PreferencePage> pagePtr{ new PreferencePage(subCategory) };
if(subCategory.IsVisible())
{
unique_ptr<PreferencePage> pagePtr{ new PreferencePage(subCategory) };

Gtk::TreeModel::Row row = *(m_treeModel->append());
row[m_columns.m_col_category] = identifier.c_str();
row[m_columns.m_col_page] = pagePtr.get();
ProcessCategory(subCategory, row);
m_pages.push_back(std::move(pagePtr));
Gtk::TreeModel::Row row = *(m_treeModel->append());
row[m_columns.m_col_category] = identifier.c_str();
row[m_columns.m_col_page] = pagePtr.get();
ProcessCategory(subCategory, row);
m_pages.push_back(std::move(pagePtr));
}
}
}
}
4 changes: 2 additions & 2 deletions src/glscopeclient/PreferenceManager.cpp
Original file line number Diff line number Diff line change
@@ -99,9 +99,9 @@ void PreferenceManager::InitializeDefaults()
auto& testSettings = debug.AddCategory("Test Settings");
testSettings.AddPreference(Preference("test_string", "Test string", "First test value", "string"));
testSettings.AddPreference(Preference("test_real", "Test real", "Second test value", 42.09));
testSettings.AddPreference(Preference("test_bool", "Test boolean", "Third test value", true));
testSettings.AddPreference(Preference("test_bool", "Test boolean", "Third test value", true, false));
auto& miscSettings = debug.AddCategory("Misc");
miscSettings.AddPreference(Preference("misc_test_1", "Misc test real", "blabla", 13.37));
miscSettings.AddPreference(Preference("misc_test_1", "Misc test real", "blabla", 13.37, false));
}

PreferenceCategory& PreferenceManager::AllPreferences()
15 changes: 15 additions & 0 deletions src/glscopeclient/PreferenceTree.cpp
Original file line number Diff line number Diff line change
@@ -132,6 +132,11 @@ namespace internal
node[this->m_identifier] = this->m_pref.ToString();
}

bool PreferenceHolder::IsVisible() const
{
return this->m_pref.GetIsVisible();
}

void PreferenceHolder::FromYAML(const YAML::Node& node)
{
if(const auto& n = node[this->m_identifier])
@@ -193,6 +198,16 @@ PreferenceCategory::map_type& PreferenceCategory::GetChildren()
return this->m_children;
}

bool PreferenceCategory::IsVisible() const
{
// Preference category is only visible if theres at least one visible entry in it
return any_of(m_children.begin(), m_children.end(),
[](const map_type::value_type& element) -> bool
{
return element.second->IsVisible();
});
}

const PreferenceCategory::seq_type& PreferenceCategory::GetOrdering() const
{
return this->m_ordering;
3 changes: 3 additions & 0 deletions src/glscopeclient/PreferenceTree.h
Original file line number Diff line number Diff line change
@@ -93,6 +93,7 @@ namespace internal
virtual void ToYAML(YAML::Node& node) const = 0;
virtual void FromYAML(const YAML::Node& node) = 0;
virtual Preference& GetLeaf(const PreferencePath& path) = 0;
virtual bool IsVisible() const = 0;

public:
const std::string& GetIdentifier() const;
@@ -120,6 +121,7 @@ namespace internal
virtual Preference& GetLeaf(const PreferencePath& path);
Preference& Get();
const Preference& Get() const;
virtual bool IsVisible() const;

protected:
Preference m_pref;
@@ -146,6 +148,7 @@ class PreferenceCategory
PreferenceCategory& AddCategory(std::string identifier);
map_type& GetChildren();
const seq_type& GetOrdering() const;
virtual bool IsVisible() const;

protected:
map_type m_children;