Skip to content

Commit

Permalink
refactor: Optimize common library module[612311]
Browse files Browse the repository at this point in the history
  • Loading branch information
Greedysky committed Jan 27, 2023
1 parent ed03f2b commit 9d61510
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 35 deletions.
23 changes: 4 additions & 19 deletions TTKCommon/TTKLibrary/ttktime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ int TTKObject::random(int value)


TTKTime::TTKTime()
: m_greedyMode(false),
m_defaultType(Entity::Millisecond)
: m_defaultType(Entity::Millisecond)
{
initialize();
}
Expand Down Expand Up @@ -112,29 +111,16 @@ qint64 TTKTime::timestamp(bool ms)
return ms ? t : t / 1000;
}

qint64 TTKTime::labelJustifiedToMsecTime(const QString &time)
qint64 TTKTime::formatDuration(const QString &time)
{
const TTKTime t = TTKTime::fromString(time, "mm:ss");
return t.timestamp(Entity::Millisecond);
}

QString TTKTime::msecTimeToLabelJustified()
{
if(!m_greedyMode)
{
return toString("mm:ss");
}
else
{
const int min = m_day * MT_H2S + m_hour * MT_H + m_min;
return QString::number(min).rightJustified(2, '0') + ":" + QString::number(m_sec).rightJustified(2, '0');
}
}

QString TTKTime::msecTimeToLabelJustified(qint64 time, bool greedy)
QString TTKTime::formatDuration(qint64 time/*, bool greedy*/)
{
const TTKTime t(time, Entity::Millisecond);
if(!greedy || time < MT_H2S * MT_S2MS)
if(/*!greedy || */time < MT_H2S * MT_S2MS)
{
return t.toString("mm:ss");
}
Expand Down Expand Up @@ -250,7 +236,6 @@ void TTKTime::initialize()

void TTKTime::copyToThis(const TTKTime &other)
{
m_greedyMode = other.m_greedyMode;
m_defaultType = other.m_defaultType;
m_day = other.m_day;
m_hour = other.m_hour;
Expand Down
18 changes: 2 additions & 16 deletions TTKCommon/TTKLibrary/ttktime.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,6 @@ class TTK_MODULE_EXPORT TTKTime
*/
inline Entity type() const { return m_defaultType; }

/*!
* Set current greedy mode.
*/
inline void setGreedyMode(bool mode) { m_greedyMode = mode; }
/*!
* Get current greedy mode.
*/
inline bool greedyMode() const { return m_greedyMode; }

/*!
* Set current day.
*/
Expand Down Expand Up @@ -165,15 +156,11 @@ class TTK_MODULE_EXPORT TTKTime
/*!
* Transform string format(mm:ss) to msec time.
*/
static qint64 labelJustifiedToMsecTime(const QString &time);
/*!
* Transform msec time to string format(mm:ss).
*/
QString msecTimeToLabelJustified();
static qint64 formatDuration(const QString &time);
/*!
* Transform msec time to string format(mm:ss).
*/
static QString msecTimeToLabelJustified(qint64 time, bool greedy = true);
static QString formatDuration(qint64 time/*, bool greedy = true*/);

TTKTime& operator = (const TTKTime &other);
TTKTime& operator+= (const TTKTime &other);
Expand Down Expand Up @@ -222,7 +209,6 @@ class TTK_MODULE_EXPORT TTKTime
*/
void fromTimeStamp(qint64 value, int delta);

bool m_greedyMode;
Entity m_defaultType;
int m_day, m_hour;
int m_min, m_sec, m_msec;
Expand Down

0 comments on commit 9d61510

Please sign in to comment.