File indexing completed on 2025-03-23 06:54:31
0001 /* 0002 SPDX-FileCopyrightText: 2008 Sascha Peilicke <sasch.pe@gmx.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "score.h" 0008 0009 namespace Kigo { 0010 0011 Score::Score(const QString &score) 0012 : m_color(QLatin1Char('?')), m_score(0), m_lowerBound(0), m_upperBound(0) 0013 { 0014 if (score.size() >= 2) { 0015 if (score[0] == QLatin1Char('W')) { 0016 m_color = QLatin1Char('W'); 0017 } else if (score[0] == QLatin1Char('B')) { 0018 m_color = QLatin1Char('B'); 0019 } 0020 int i = score.indexOf(QLatin1Char(' ')); 0021 m_score = score.mid(2, i - 1).toFloat(); 0022 QString newUpperBound = score.section(QLatin1Char(' '), 3, 3); 0023 newUpperBound.chop(1); 0024 m_upperBound = newUpperBound.toFloat(); 0025 QString newLowerBound = score.section(QLatin1Char(' '), 5, 5); 0026 newLowerBound.chop(1); 0027 m_lowerBound = newLowerBound.toFloat(); 0028 } 0029 } 0030 0031 Score::Score(const Score &other) 0032 : QObject(), m_color(other.m_color), m_score(other.m_score) 0033 , m_lowerBound(other.m_lowerBound), m_upperBound(other.m_upperBound) 0034 { 0035 } 0036 0037 Score &Score::operator=(const Score &other) 0038 { 0039 m_color = other.m_color; 0040 m_score = other.m_score; 0041 m_lowerBound = other.m_lowerBound; 0042 m_upperBound = other.m_upperBound; 0043 return *this; 0044 } 0045 0046 bool Score::isValid() const 0047 { 0048 return m_score >= 0 && (m_color == QLatin1Char('W') || m_color == QLatin1Char('B')); 0049 } 0050 0051 QString Score::toString() const 0052 { 0053 const QString ret = m_color + QLatin1Char('+') + 0054 QString::number(m_score) + QLatin1String(" (") + QString::number(m_lowerBound) + QLatin1String(" - ") + QString::number(m_upperBound) + QLatin1Char(')'); 0055 return ret; 0056 } 0057 0058 } // End of namespace Kigo 0059 0060 #include "moc_score.cpp"