aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/result
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2018-03-18 17:43:27 +0100
committerRenaud G <renaud@rolisteam.org>2018-03-18 17:43:27 +0100
commit8edc89703e5e0be26471432bc0e953d694bc92a5 (patch)
tree1b5598828986b747dbed9a1b77a9a0494f014779 /result
parent86bd8dbc2bba4023ef4d7e3ba9c21a4396c9ccd1 (diff)
downloadOneRoll-8edc89703e5e0be26471432bc0e953d694bc92a5.tar.gz
OneRoll-8edc89703e5e0be26471432bc0e953d694bc92a5.zip
-Get copy for result
Diffstat (limited to 'result')
-rw-r--r--result/diceresult.cpp17
-rw-r--r--result/diceresult.h2
-rw-r--r--result/result.h1
-rw-r--r--result/scalarresult.cpp7
-rw-r--r--result/scalarresult.h2
-rw-r--r--result/stringresult.cpp7
-rw-r--r--result/stringresult.h1
7 files changed, 34 insertions, 3 deletions
diff --git a/result/diceresult.cpp b/result/diceresult.cpp
index b3d5e54..b8ed8d5 100644
--- a/result/diceresult.cpp
+++ b/result/diceresult.cpp
@@ -150,7 +150,7 @@ void DiceResult::setOperator(const Die::ArithmeticOperator& dieOperator)
QString DiceResult::toString(bool wl)
{
QStringList scalarSum;
- for(Die* die:m_diceValues)
+ for(auto die : m_diceValues)
{
scalarSum << QString::number(die->getValue());
}
@@ -163,3 +163,18 @@ QString DiceResult::toString(bool wl)
return m_id;
}
}
+Result* DiceResult::getCopy() const
+{
+ auto copy = new DiceResult();
+ copy->setHomogeneous(m_homogeneous);
+ copy->setOperator(m_operator);
+ QList<Die*> list;
+ for(auto die : m_diceValues)
+ {
+ auto newdie = new Die(*die);
+ die->displayed();
+ list.append(newdie);
+ }
+ copy->setResultList(list);
+ return copy;
+}
diff --git a/result/diceresult.h b/result/diceresult.h
index ae16daf..3dac826 100644
--- a/result/diceresult.h
+++ b/result/diceresult.h
@@ -78,6 +78,8 @@ public:
Die::ArithmeticOperator getOperator() const;
void setOperator(const Die::ArithmeticOperator & dieOperator);
bool contains(Die *die, const std::function<bool (const Die *, const Die *)> equal);
+
+ virtual Result* getCopy() const;
private:
qreal getScalarResult();
private:
diff --git a/result/result.h b/result/result.h
index e905475..5de3572 100644
--- a/result/result.h
+++ b/result/result.h
@@ -83,6 +83,7 @@ public:
* @return
*/
virtual QString toString(bool wl) = 0;
+ virtual Result* getCopy() const = 0;
protected:
int m_resultTypes;/// @brief
QString m_id;
diff --git a/result/scalarresult.cpp b/result/scalarresult.cpp
index 1722cd2..138caf5 100644
--- a/result/scalarresult.cpp
+++ b/result/scalarresult.cpp
@@ -40,7 +40,12 @@ QVariant ScalarResult::getResult(Result::RESULT_TYPE type)
else
return {};
}
-
+Result* ScalarResult::getCopy() const
+{
+ auto copy = new ScalarResult();
+ copy->setValue(m_value);
+ return copy;
+}
QString ScalarResult::toString(bool wl)
{
if(wl)
diff --git a/result/scalarresult.h b/result/scalarresult.h
index 6c02dd6..31da7f4 100644
--- a/result/scalarresult.h
+++ b/result/scalarresult.h
@@ -50,7 +50,7 @@ public:
* @return
*/
virtual QString toString(bool);
-
+ virtual Result* getCopy() const;
private:
qreal m_value;
};
diff --git a/result/stringresult.cpp b/result/stringresult.cpp
index 2d9214d..f0ff699 100644
--- a/result/stringresult.cpp
+++ b/result/stringresult.cpp
@@ -67,3 +67,10 @@ bool StringResult::hasHighLight() const
{
return m_highlight;
}
+Result* StringResult::getCopy() const
+{
+ auto copy = new StringResult();
+ copy->setHighLight(m_highlight);
+ copy->setText(m_value);
+ return copy;
+}
diff --git a/result/stringresult.h b/result/stringresult.h
index 2effea7..a8b859a 100644
--- a/result/stringresult.h
+++ b/result/stringresult.h
@@ -41,6 +41,7 @@ public:
virtual void setHighLight(bool );
virtual bool hasHighLight() const;
virtual bool hasResultOfType(RESULT_TYPE resultType) const;
+ virtual Result* getCopy() const;
private:
QString m_value;
bool m_highlight;