Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
berryMultiStatus.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 BlueBerry Platform
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "berryMultiStatus.h"
18 
19 #include <QTextStream>
20 
21 namespace berry
22 {
23 
24 IStatus::Severity MultiStatus::GetMaxSeverity(const QList<IStatus::Pointer>& children) const
25 {
26  Severity maxSeverity = this->GetSeverity();
27  for (int i = 0; i < children.size(); i++)
28  {
29  Q_ASSERT(children[i]);
30  Severity severity = children[i]->GetSeverity();
31  if (severity > maxSeverity)
32  maxSeverity = severity;
33  }
34  return maxSeverity;
35 }
36 
37 MultiStatus::MultiStatus(const QString& pluginId, int code,
38  const QList<IStatus::Pointer>& newChildren,
39  const QString& message, const SourceLocation& sl)
40  : Status(OK_TYPE, pluginId, code, message, sl), children(newChildren)
41 {
42  this->SetSeverity(GetMaxSeverity(children));
43 }
44 
45 MultiStatus::MultiStatus(const QString& pluginId, int code,
46  const QList<IStatus::Pointer>& newChildren,
47  const QString& message, const ctkException& exception,
48  const SourceLocation& sl)
49  : Status(OK_TYPE, pluginId, code, message, exception, sl), children(newChildren)
50 {
51  this->SetSeverity(GetMaxSeverity(children));
52 }
53 
54 MultiStatus::MultiStatus(const QString& pluginId, int code, const QString& message,
55  const SourceLocation& sl)
56 : Status(OK_TYPE, pluginId, code, message, sl)
57 {
58 }
59 
60 MultiStatus::MultiStatus(const QString& pluginId, int code,
61  const QString& message, const ctkException& exception,
62  const SourceLocation& sl)
63 : Status(OK_TYPE, pluginId, code, message, exception, sl)
64 {
65 }
66 
68 {
69  poco_assert(status);
70  children.push_back(status);
71  Severity newSev = status->GetSeverity();
72  if (newSev > this->GetSeverity())
73  {
74  this->SetSeverity(newSev);
75  }
76 }
77 
79 {
80  Q_ASSERT(status);
81  QList<IStatus::Pointer> statuses(status->GetChildren());
82  for (int i = 0; i < statuses.size(); i++)
83  {
84  this->Add(statuses[i]);
85  }
86 }
87 
88 QList<IStatus::Pointer> MultiStatus::GetChildren() const
89 {
90  return children;
91 }
92 
94 {
95  return true;
96 }
97 
99 {
100  poco_assert(status);
101  if (!status->IsMultiStatus())
102  {
103  this->Add(status);
104  }
105  else
106  {
107  this->AddAll(status);
108  }
109 }
110 
111 QString MultiStatus::ToString() const
112 {
113  QString str;
114  QTextStream buf(&str);
115  buf << Status::ToString() << " children=[";
116  for (int i = 0; i < children.size(); i++)
117  {
118  if (i != 0)
119  {
120  buf << " ";
121  }
122  buf << children[i]->ToString();
123  }
124  buf << "]";
125  return str;
126 }
127 
128 }
bool IsMultiStatus() const override
QString ToString() const override
QString ToString() const override
virtual void SetSeverity(const Severity &severity)
Severity GetSeverity() const override
void AddAll(IStatus::Pointer status)
MultiStatus(const QString &pluginId, int code, const QList< IStatus::Pointer > &newChildren, const QString &message, const SourceLocation &sl)
void Add(IStatus::Pointer status)
QList< IStatus::Pointer > GetChildren() const override
void Merge(const IStatus::Pointer &status)