COPASI API  4.16.103
Public Member Functions | Protected Slots | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
CQNotes Class Reference

#include <CQNotes.h>

Inheritance diagram for CQNotes:
Inheritance graph
[legend]
Collaboration diagram for CQNotes:
Collaboration graph
[legend]

Public Member Functions

 CQNotes (QWidget *parent=0, const char *name=0)
 
virtual bool leave ()
 
virtual bool update (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
 
 ~CQNotes ()
 
- Public Member Functions inherited from CopasiWidget
 CopasiWidget (QWidget *parent=0, const char *name=0, Qt::WFlags f=0)
 
bool enter (const std::string &key)
 
CCopasiDataModelgetDataModel ()
 
bool getIgnoreUpdates ()
 
virtual void setFramework (int framework)
 
void setIgnoreUpdates (bool v)
 

Protected Slots

void slotBtnCopy ()
 
void slotOpenUrl (const QUrl &url)
 
void slotToggleMode ()
 
void slotValidateXML ()
 
- Protected Slots inherited from CopasiWidget
virtual bool protectedNotify (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
 

Protected Member Functions

virtual bool enterProtected ()
 

Private Member Functions

void load ()
 
void save ()
 

Private Attributes

bool mChanged
 
bool mEditMode
 
std::string mKeyToCopy
 
CQValidatorXMLmpValidatorXML
 
QValidator::State mValidity
 

Additional Inherited Members

- Protected Attributes inherited from CopasiWidget
int mFramework
 
bool mIgnoreUpdates
 
std::string mKey
 
CCopasiDataModelmpDataModel
 
ListViewsmpListView
 
CCopasiObjectmpObject
 

Detailed Description

Definition at line 67 of file CQNotes.h.

Constructor & Destructor Documentation

CQNotes::CQNotes ( QWidget *  parent = 0,
const char *  name = 0 
)

Definition at line 132 of file CQNotes.cpp.

References CQIconResource::edit, CQIconResource::icon(), mEditMode, and mpValidatorXML.

132  :
133  CopasiWidget(parent, name),
134  mEditMode(false),
135  mChanged(false),
136  mpValidatorXML(NULL),
137  mValidity(QValidator::Acceptable),
138  mKeyToCopy("")
139 
140 {
141  setupUi(this);
142 
143  mpValidatorXML = new CQValidatorXML(mpEdit);
144 
145  mEditMode = false;
146  mpEdit->hide();
147  mpWebView->show();
148  mpBtnToggleEdit->setIcon(CQIconResource::icon(CQIconResource::edit));
149 
150  mpWebView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
151 }
bool mChanged
Definition: CQNotes.h:92
CQValidatorXML * mpValidatorXML
Definition: CQNotes.h:93
bool mEditMode
Definition: CQNotes.h:91
CopasiWidget(QWidget *parent=0, const char *name=0, Qt::WFlags f=0)
static const QIcon & icon(const IconID &id)
std::string mKeyToCopy
Definition: CQNotes.h:96
QValidator::State mValidity
Definition: CQNotes.h:94
CQNotes::~CQNotes ( )

Definition at line 153 of file CQNotes.cpp.

154 {}

Member Function Documentation

bool CQNotes::enterProtected ( )
protectedvirtual

Reimplemented from CopasiWidget.

Definition at line 219 of file CQNotes.cpp.

References CKeyFactory::get(), CCopasiRootContainer::getKeyFactory(), load(), CopasiWidget::mKey, mKeyToCopy, CopasiWidget::mpObject, and save().

220 {
221  if (mKeyToCopy == "")
222  {
223  load();
224  }
225  else
226  {
228  load();
230  save();
231  mKeyToCopy = "";
232  }
233 
234  return true;
235 }
CCopasiObject * get(const std::string &key)
CCopasiObject * mpObject
Definition: copasiWidget.h:64
void save()
Definition: CQNotes.cpp:327
static CKeyFactory * getKeyFactory()
void load()
Definition: CQNotes.cpp:289
std::string mKeyToCopy
Definition: CQNotes.h:96
std::string mKey
Definition: copasiWidget.h:63
bool CQNotes::leave ( )
virtual

Reimplemented from CopasiWidget.

Definition at line 199 of file CQNotes.cpp.

References CKeyFactory::get(), CCopasiRootContainer::getKeyFactory(), CopasiWidget::mKey, CopasiWidget::mpDataModel, CopasiWidget::mpObject, and save().

200 {
201  mpBtnToggleEdit->setFocus();
202 
204 
205  if (mpObject != NULL)
206  {
207  save();
208  }
209  else
210  {
211  mKey = "";
212  mpDataModel = NULL;
213  }
214 
215  return true;
216 }
CCopasiObject * get(const std::string &key)
CCopasiObject * mpObject
Definition: copasiWidget.h:64
void save()
Definition: CQNotes.cpp:327
CCopasiDataModel * mpDataModel
Definition: copasiWidget.h:65
static CKeyFactory * getKeyFactory()
std::string mKey
Definition: copasiWidget.h:63
void CQNotes::load ( )
private

Definition at line 289 of file CQNotes.cpp.

References CAnnotation::castObject(), FROM_UTF8, CReportDefinition::getComment(), CAnnotation::getNotes(), CQValidatorXML::isFreeText(), mChanged, mEditMode, CopasiWidget::mpObject, mpValidatorXML, mValidity, CQValidator< Type >::saved(), slotToggleMode(), and slotValidateXML().

Referenced by enterProtected(), slotToggleMode(), and update().

290 {
291  if (mpObject != NULL)
292  {
293  QString Notes;
294 
296  CReportDefinition * pReportDefinition = static_cast< CReportDefinition * >(mpObject);
297 
298  if (pAnnotation != NULL)
299  {
300  Notes = FROM_UTF8(pAnnotation->getNotes());
301  }
302  else if (pReportDefinition != NULL)
303  {
304  Notes = FROM_UTF8(pReportDefinition->getComment());
305  }
306 
307  // The notes are UTF8 encoded however the html does not specify an encoding
308  // thus Qt uses locale settings.
309  mpWebView->setHtml(Notes);
310  mpEdit->setPlainText(Notes);
312  slotValidateXML();
313 
315  {
316  slotToggleMode();
317  }
318 
319  mValidity = QValidator::Acceptable;
320  }
321 
322  mChanged = false;
323 
324  return;
325 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const bool & isFreeText() const
Definition: CQNotes.cpp:63
CCopasiObject * mpObject
Definition: copasiWidget.h:64
bool mChanged
Definition: CQNotes.h:92
const std::string & getComment() const
CQValidatorXML * mpValidatorXML
Definition: CQNotes.h:93
static CAnnotation * castObject(CCopasiObject *pObject)
Definition: CAnnotation.cpp:32
bool mEditMode
Definition: CQNotes.h:91
virtual void saved() const
Definition: CQValidator.h:71
const std::string & getNotes() const
void slotToggleMode()
Definition: CQNotes.cpp:237
void slotValidateXML()
Definition: CQNotes.cpp:258
QValidator::State mValidity
Definition: CQNotes.h:94
void CQNotes::save ( )
private

Definition at line 327 of file CQNotes.cpp.

References CAnnotation::castObject(), ListViews::CHANGE, CCopasiDataModel::changed(), FROM_UTF8, CReportDefinition::getComment(), CAnnotation::getNotes(), mChanged, CopasiWidget::mKey, ListViews::MODEL, CopasiWidget::mpDataModel, CopasiWidget::mpObject, mpValidatorXML, mValidity, CQValidatorXML::needsWrap(), CopasiWidget::protectedNotify(), CReportDefinition::setComment(), CAnnotation::setNotes(), and TO_UTF8.

Referenced by enterProtected(), leave(), and slotToggleMode().

328 {
329  if (mpObject != NULL &&
330  mValidity == QValidator::Acceptable)
331  {
332  QString Notes;
333 
335  CReportDefinition * pReportDefinition = static_cast< CReportDefinition * >(mpObject);
336 
337  if (pAnnotation != NULL)
338  {
339  Notes = FROM_UTF8(pAnnotation->getNotes());
340  }
341  else if (pReportDefinition != NULL)
342  {
343  Notes = FROM_UTF8(pReportDefinition->getComment());
344  }
345 
346  if (mpEdit->toPlainText() != Notes)
347  {
348  std::string PlainText = TO_UTF8(mpEdit->toPlainText());
349 
350  if (mpValidatorXML->needsWrap())
351  {
352  // We wrap the HTML in a body element if it does not contain a top level html or body element.
353  PlainText = "<body xmlns=\"http://www.w3.org/1999/xhtml\">" + PlainText + "</body>";
354  }
355 
356  if (pAnnotation != NULL)
357  {
358  pAnnotation->setNotes(PlainText);
359  }
360  else if (pReportDefinition != NULL)
361  {
362  pReportDefinition->setComment(PlainText);
363  }
364 
365  mChanged = true;
366  }
367  }
368 
369  if (mChanged)
370  {
371  if (mpDataModel != NULL)
372  {
373  mpDataModel->changed();
374  }
375 
377  mChanged = false;
378  }
379 
380  return;
381 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
void setNotes(const std::string &notes)
CCopasiObject * mpObject
Definition: copasiWidget.h:64
bool mChanged
Definition: CQNotes.h:92
void changed(const bool &changed=true)
const std::string & getComment() const
CQValidatorXML * mpValidatorXML
Definition: CQNotes.h:93
static CAnnotation * castObject(CCopasiObject *pObject)
Definition: CAnnotation.cpp:32
const bool & needsWrap() const
Definition: CQNotes.cpp:68
void setComment(const std::string &comment)
const std::string & getNotes() const
virtual bool protectedNotify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
CCopasiDataModel * mpDataModel
Definition: copasiWidget.h:65
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
std::string mKey
Definition: copasiWidget.h:63
QValidator::State mValidity
Definition: CQNotes.h:94
void CQNotes::slotBtnCopy ( )
protectedslot

Definition at line 156 of file CQNotes.cpp.

References CopasiWidget::mKey, and mKeyToCopy.

157 {
158  mKeyToCopy = mKey;
159 }
std::string mKeyToCopy
Definition: CQNotes.h:96
std::string mKey
Definition: copasiWidget.h:63
void CQNotes::slotOpenUrl ( const QUrl &  url)
protectedslot

Definition at line 383 of file CQNotes.cpp.

384 {
385  QDesktopServices::openUrl(url);
386  return;
387 }
void CQNotes::slotToggleMode ( )
protectedslot

Definition at line 237 of file CQNotes.cpp.

References CQIconResource::edit, CQIconResource::icon(), load(), mEditMode, CQIconResource::renderMarkup, and save().

Referenced by load().

238 {
239  mEditMode = !mEditMode;
240 
241  if (mEditMode)
242  {
243  mpWebView->hide();
244  mpEdit->show();
245  mpBtnToggleEdit->setIcon(CQIconResource::icon(CQIconResource::renderMarkup));
246  }
247  else
248  {
249  save();
250  load();
251 
252  mpEdit->hide();
253  mpWebView->show();
254  mpBtnToggleEdit->setIcon(CQIconResource::icon(CQIconResource::edit));
255  }
256 }
void save()
Definition: CQNotes.cpp:327
bool mEditMode
Definition: CQNotes.h:91
static const QIcon & icon(const IconID &id)
void load()
Definition: CQNotes.cpp:289
void CQNotes::slotValidateXML ( )
protectedslot

Definition at line 258 of file CQNotes.cpp.

References CQIconResource::edit, CQIconResource::icon(), CQValidatorXML::isFreeText(), mEditMode, mpValidatorXML, mValidity, CQIconResource::renderMarkup, and CQValidatorXML::validate().

Referenced by load().

259 {
260  QString Input = mpEdit->toPlainText();
261  int pos = 0;
262 
263  mValidity = mpValidatorXML->validate(Input, pos);
264 
265  if (mpValidatorXML->isFreeText())
266  {
267  mEditMode = true;
268  mpBtnToggleEdit->hide();
269  }
270  else
271  {
272  mpBtnToggleEdit->show();
273  }
274 
275  if (mEditMode)
276  {
277  mpWebView->hide();
278  mpEdit->show();
279  mpBtnToggleEdit->setIcon(CQIconResource::icon(CQIconResource::renderMarkup));
280  }
281  else
282  {
283  mpEdit->hide();
284  mpWebView->show();
285  mpBtnToggleEdit->setIcon(CQIconResource::icon(CQIconResource::edit));
286  }
287 }
const bool & isFreeText() const
Definition: CQNotes.cpp:63
CQValidatorXML * mpValidatorXML
Definition: CQNotes.h:93
bool mEditMode
Definition: CQNotes.h:91
static const QIcon & icon(const IconID &id)
virtual State validate(QString &input, int &pos) const
Definition: CQNotes.cpp:39
QValidator::State mValidity
Definition: CQNotes.h:94
bool CQNotes::update ( ListViews::ObjectType  objectType,
ListViews::Action  action,
const std::string &  key 
)
virtual

Reimplemented from CopasiWidget.

Definition at line 162 of file CQNotes.cpp.

References ListViews::CHANGE, ListViews::DELETE, load(), mEditMode, CopasiWidget::mKey, ListViews::MODEL, and CopasiWidget::mpObject.

163 {
164  switch (action)
165  {
166  case ListViews::CHANGE:
167 
168  if (key == mKey)
169  {
170  load();
171  }
172 
173  break;
174 
175  case ListViews::DELETE:
176 
177  if (key == mKey || objectType == ListViews::MODEL)
178  {
179  mpObject = NULL;
180  mKey = "";
181  }
182 
183  break;
184 
185  default:
186  break;
187  }
188 
189  if (objectType == ListViews::MODEL &&
190  action == ListViews::DELETE)
191  {
192  mEditMode = false;
193  }
194 
195  return true;
196 }
objectType
CCopasiObject * mpObject
Definition: copasiWidget.h:64
bool mEditMode
Definition: CQNotes.h:91
void load()
Definition: CQNotes.cpp:289
std::string mKey
Definition: copasiWidget.h:63

Member Data Documentation

bool CQNotes::mChanged
private

Definition at line 92 of file CQNotes.h.

Referenced by load(), and save().

bool CQNotes::mEditMode
private

Definition at line 91 of file CQNotes.h.

Referenced by CQNotes(), load(), slotToggleMode(), slotValidateXML(), and update().

std::string CQNotes::mKeyToCopy
private

Definition at line 96 of file CQNotes.h.

Referenced by enterProtected(), and slotBtnCopy().

CQValidatorXML* CQNotes::mpValidatorXML
private

Definition at line 93 of file CQNotes.h.

Referenced by CQNotes(), load(), save(), and slotValidateXML().

QValidator::State CQNotes::mValidity
private

Definition at line 94 of file CQNotes.h.

Referenced by load(), save(), and slotValidateXML().


The documentation for this class was generated from the following files: