mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#1156 Added tristate class and checkbox editor with tristate support
This commit is contained in:
@@ -41,6 +41,9 @@ set( PROJECT_FILES
|
||||
|
||||
cafNotificationCenter.cpp
|
||||
cafNotificationCenter.h
|
||||
|
||||
cafTristate.cpp
|
||||
cafTristate.h
|
||||
)
|
||||
|
||||
|
||||
|
||||
158
Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafTristate.cpp
Normal file
158
Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafTristate.cpp
Normal file
@@ -0,0 +1,158 @@
|
||||
#include "cafTristate.h"
|
||||
|
||||
#include <QTextStream>
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::Tristate::Tristate()
|
||||
: m_state(State::False)
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void caf::Tristate::operator=(const Tristate& other)
|
||||
{
|
||||
m_state = other.m_state;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void caf::Tristate::operator=(const State& state)
|
||||
{
|
||||
m_state = state;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool caf::Tristate::operator==(const Tristate& other) const
|
||||
{
|
||||
return m_state == other.m_state;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool caf::Tristate::operator==(State state) const
|
||||
{
|
||||
return m_state == state;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool caf::Tristate::operator!=(const Tristate& other) const
|
||||
{
|
||||
return !(m_state == other.m_state);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::Tristate::State caf::Tristate::state() const
|
||||
{
|
||||
return m_state;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool caf::Tristate::isTrue() const
|
||||
{
|
||||
return m_state == State::True;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool caf::Tristate::isPartiallyTrue() const
|
||||
{
|
||||
return m_state == State::PartiallyTrue;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool caf::Tristate::isFalse() const
|
||||
{
|
||||
return m_state == State::False;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString caf::Tristate::text() const
|
||||
{
|
||||
QString txt;
|
||||
|
||||
switch (m_state)
|
||||
{
|
||||
case Tristate::State::False:
|
||||
txt = "False";
|
||||
break;
|
||||
case Tristate::State::PartiallyTrue:
|
||||
txt = "PartiallyTrue";
|
||||
break;
|
||||
case Tristate::State::True:
|
||||
txt = "True";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return txt;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void caf::Tristate::setFromText(const QString& valueText)
|
||||
{
|
||||
QString lowerCase = valueText.toLower();
|
||||
|
||||
if (lowerCase == "false")
|
||||
{
|
||||
m_state = State::False;
|
||||
}
|
||||
else if (lowerCase == "partiallytrue")
|
||||
{
|
||||
m_state = State::PartiallyTrue;
|
||||
}
|
||||
else if (lowerCase == "true")
|
||||
{
|
||||
m_state = State::True;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void operator >> (QTextStream& str, caf::Tristate& triplet)
|
||||
{
|
||||
QString text;
|
||||
str >> text;
|
||||
triplet.setFromText(text);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void operator << (QTextStream& str, const caf::Tristate& triplet)
|
||||
{
|
||||
str << triplet.text();
|
||||
}
|
||||
53
Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafTristate.h
Normal file
53
Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafTristate.h
Normal file
@@ -0,0 +1,53 @@
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QMetaType>
|
||||
|
||||
class QTextStream;
|
||||
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
//==================================================================================================
|
||||
//==================================================================================================
|
||||
class Tristate
|
||||
{
|
||||
public:
|
||||
enum class State {False, PartiallyTrue, True};
|
||||
|
||||
public:
|
||||
Tristate();
|
||||
|
||||
void operator=(const Tristate& other);
|
||||
void operator=(const State& state);
|
||||
|
||||
bool operator==(const Tristate& other) const;
|
||||
bool operator==(State state) const;
|
||||
bool operator!=(const Tristate& other) const;
|
||||
|
||||
State state() const;
|
||||
|
||||
bool isTrue() const;
|
||||
bool isPartiallyTrue() const;
|
||||
bool isFalse() const;
|
||||
|
||||
QString text() const;
|
||||
void setFromText(const QString& valueText);
|
||||
|
||||
protected:
|
||||
State m_state;
|
||||
};
|
||||
|
||||
|
||||
} // end namespace caf
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
// Overload of QTextStream for caf::Triplet
|
||||
//==================================================================================================
|
||||
void operator >> (QTextStream& str, caf::Tristate& triplet);
|
||||
void operator << (QTextStream& str, const caf::Tristate& triplet);
|
||||
|
||||
Q_DECLARE_METATYPE(caf::Tristate);
|
||||
Reference in New Issue
Block a user