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: 3752d10fc8a2
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: c8541f2d2748
Choose a head ref
  • 4 commits
  • 8 files changed
  • 2 contributors

Commits on Oct 31, 2020

  1. Refactored preference dialog

    nshcat committed Oct 31, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    83111e5 View commit details
  2. Copy the full SHA
    a3d83e0 View commit details
  3. Leaking memory isnt very nice

    nshcat committed Oct 31, 2020
    Copy the full SHA
    2b3d39a View commit details
  4. Merge pull request #268 from azonenberg/kathi_dev

    Refactored preference dialog internals and implemented font support
    azonenberg authored Oct 31, 2020
    Copy the full SHA
    c8541f2 View commit details
40 changes: 39 additions & 1 deletion src/glscopeclient/Preference.cpp
Original file line number Diff line number Diff line change
@@ -217,7 +217,7 @@ const std::string& Preference::GetString() const

void Preference::CleanUp()
{
if(m_hasValue && m_type == PreferenceType::String)
if(m_hasValue && (m_type == PreferenceType::String || m_type == PreferenceType::Font))
(reinterpret_cast<string*>(&m_value))->~basic_string();
}

@@ -227,6 +227,8 @@ string Preference::ToString() const
{
case PreferenceType::String:
return GetString();
case PreferenceType::Font:
return GetFontRaw();
case PreferenceType::Boolean:
return GetBool() ? "true" : "false";
case PreferenceType::Real:
@@ -268,6 +270,7 @@ void Preference::MoveFrom(Preference& other)
break;

case PreferenceType::String:
case PreferenceType::Font:
Construct<string>(move(other.GetValueRaw<string>()));
break;

@@ -293,6 +296,33 @@ const std::string& Preference::GetLabel() const
return m_label;
}

const ::std::string& Preference::GetFontRaw() const
{
if(m_type != PreferenceType::Font)
throw runtime_error("Preference type mismatch");

return GetValueRaw<std::string>();
}

Pango::FontDescription Preference::GetFont() const
{
const auto str = this->GetFontRaw();

return Pango::FontDescription(str.c_str());
}

void Preference::SetFontRaw(const std::string& fontRaw)
{
CleanUp();
Construct<string>(fontRaw);
}

void Preference::SetFont(const Pango::FontDescription& font)
{
string str = font.to_string();
this->SetFontRaw(str);
}

void Preference::SetBool(bool value)
{
CleanUp();
@@ -382,3 +412,11 @@ impl::PreferenceBuilder Preference::EnumRaw(std::string identifier, std::int64_t
return impl::PreferenceBuilder{ std::move(pref) };
}

impl::PreferenceBuilder Preference::Font(std::string identifier, std::string defaultValue)
{
Preference pref(PreferenceType::Font, std::move(identifier));
pref.Construct<string>(std::move(defaultValue));

return impl::PreferenceBuilder{ std::move(pref) };
}

7 changes: 7 additions & 0 deletions src/glscopeclient/Preference.h
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@

#include <giomm.h>
#include <gtkmm.h>
#include <pangomm/fontdescription.h>

#include "Unit.h"

@@ -59,6 +60,7 @@ enum class PreferenceType
Real,
Color,
Enum,
Font,
None // Only for moved-from values
};

@@ -157,6 +159,10 @@ class Preference
const std::string& GetIdentifier() const;
const std::string& GetLabel() const;
const std::string& GetDescription() const;
const std::string& GetFontRaw() const;
void SetFontRaw(const std::string& fontRaw);
void SetFont(const Pango::FontDescription& font);
Pango::FontDescription GetFont() const;
std::int64_t GetEnumRaw() const;
void SetEnumRaw(std::int64_t value);
PreferenceType GetType() const;
@@ -196,6 +202,7 @@ class Preference
static impl::PreferenceBuilder String(std::string identifier, std::string defaultValue);
static impl::PreferenceBuilder Color(std::string identifier, const Gdk::Color& defaultValue);
static impl::PreferenceBuilder EnumRaw(std::string identifier, std::int64_t defaultValue);
static impl::PreferenceBuilder Font(std::string identifier, std::string defaultValue);

template< typename E >
static impl::PreferenceBuilder Enum(std::string identifier, E defaultValue);
Loading