Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
berryMultiStatus.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "berryMultiStatus.h"
14 
15 #include <QTextStream>
16 
17 namespace berry
18 {
19 
20 IStatus::Severity MultiStatus::GetMaxSeverity(const QList<IStatus::Pointer>& children) const
21 {
22  Severity maxSeverity = this->GetSeverity();
23  for (int i = 0; i < children.size(); i++)
24  {
25  Q_ASSERT(children[i]);
26  Severity severity = children[i]->GetSeverity();
27  if (severity > maxSeverity)
28  maxSeverity = severity;
29  }
30  return maxSeverity;
31 }
32 
33 MultiStatus::MultiStatus(const QString& pluginId, int code,
34  const QList<IStatus::Pointer>& newChildren,
35  const QString& message, const SourceLocation& sl)
36  : Status(OK_TYPE, pluginId, code, message, sl), children(newChildren)
37 {
38  this->SetSeverity(GetMaxSeverity(children));
39 }
40 
41 MultiStatus::MultiStatus(const QString& pluginId, int code,
42  const QList<IStatus::Pointer>& newChildren,
43  const QString& message, const ctkException& exception,
44  const SourceLocation& sl)
45  : Status(OK_TYPE, pluginId, code, message, exception, sl), children(newChildren)
46 {
47  this->SetSeverity(GetMaxSeverity(children));
48 }
49 
50 MultiStatus::MultiStatus(const QString& pluginId, int code, const QString& message,
51  const SourceLocation& sl)
52 : Status(OK_TYPE, pluginId, code, message, sl)
53 {
54 }
55 
56 MultiStatus::MultiStatus(const QString& pluginId, int code,
57  const QString& message, const ctkException& exception,
58  const SourceLocation& sl)
59 : Status(OK_TYPE, pluginId, code, message, exception, sl)
60 {
61 }
62 
64 {
65  poco_assert(status);
66  children.push_back(status);
67  Severity newSev = status->GetSeverity();
68  if (newSev > this->GetSeverity())
69  {
70  this->SetSeverity(newSev);
71  }
72 }
73 
75 {
76  Q_ASSERT(status);
77  QList<IStatus::Pointer> statuses(status->GetChildren());
78  for (int i = 0; i < statuses.size(); i++)
79  {
80  this->Add(statuses[i]);
81  }
82 }
83 
84 QList<IStatus::Pointer> MultiStatus::GetChildren() const
85 {
86  return children;
87 }
88 
90 {
91  return true;
92 }
93 
95 {
96  poco_assert(status);
97  if (!status->IsMultiStatus())
98  {
99  this->Add(status);
100  }
101  else
102  {
103  this->AddAll(status);
104  }
105 }
106 
107 QString MultiStatus::ToString() const
108 {
109  QString str;
110  QTextStream buf(&str);
111  buf << Status::ToString() << " children=[";
112  for (int i = 0; i < children.size(); i++)
113  {
114  if (i != 0)
115  {
116  buf << " ";
117  }
118  buf << children[i]->ToString();
119  }
120  buf << "]";
121  return str;
122 }
123 
124 }
bool IsMultiStatus() const override
QString ToString() const override
Implements transparent reference counting.
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)