Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
JsonEditorMain Class Reference

#include <jsoneditormain.h>

Inheritance diagram for JsonEditorMain:
Collaboration diagram for JsonEditorMain:

Public Member Functions

 JsonEditorMain (QWidget *parent=0)
 
 ~JsonEditorMain ()
 

Protected Member Functions

void changeEvent (QEvent *e)
 
void closeEvent (QCloseEvent *event)
 

Private Slots

void toggleFileToolbar (bool checked)
 
void toggleEditToolbar (bool checked)
 
void toggleFindToolbar (bool checked)
 
void toggleCodeToolbar (bool checked)
 
void refreshJsonTree ()
 
void insertTreeNode ()
 
void deleteTreeNode ()
 
void insertTreeChild ()
 
void updateActions ()
 
void treeViewDataChanged ()
 
void formatCode ()
 
void showHelp ()
 
void dataEdit (QModelIndex editIndex)
 
void open ()
 
bool save ()
 
bool saveAs ()
 
void documentWasModified ()
 
void on_Send_clicked ()
 

Private Member Functions

QString treeFormat (JsonTreeItem *treeItem=NULL, QString indent="", bool noHeader=false)
 
void readSettings ()
 
void writeSettings ()
 
bool maybeSave ()
 
void loadFile (const QString &fileName)
 
bool saveFile (const QString &fileName)
 
void setCurrentFile (const QString &fileName)
 
QString strippedName (const QString &fullFileName)
 

Private Attributes

Ui::JsonEditorMain * ui
 
nlohmann::json jsonValue
 
const QString newInsertText
 
const QString treeViewColumnKey
 
const QString treeViewColumnValue
 
const QString treeViewColumnType
 
QString curFile
 
QTextEdit * textEdit
 
QString lastFilePath
 
std::shared_ptr< std::map< std::string, std::vector< rclcpp::Parameter > > > m_parameterMap
 

Detailed Description

Definition at line 25 of file jsoneditormain.h.

Constructor & Destructor Documentation

◆ JsonEditorMain()

JsonEditorMain::JsonEditorMain ( QWidget *  parent = 0)

Definition at line 20 of file jsoneditormain.cpp.

20  :
21  QMainWindow(parent),
22  ui(new Ui::JsonEditorMain),
23  newInsertText(tr("Insert new data")),
24  treeViewColumnKey(tr("Node")),
25  treeViewColumnValue(tr("Value")),
26  treeViewColumnType(tr("Type"))
27 {
28  ui->setupUi(this);
29  connect(ui->menuCodeTools, SIGNAL(toggled(bool)), this, SLOT(toggleCodeToolbar(bool)));
30  connect(ui->menuFindTools, SIGNAL(toggled(bool)), this, SLOT(toggleFindToolbar(bool)));
31  connect(ui->menuFileTools, SIGNAL(toggled(bool)), this, SLOT(toggleFileToolbar(bool)));
32  connect(ui->menuEditTools, SIGNAL(toggled(bool)), this, SLOT(toggleEditToolbar(bool)));
33  connect(ui->menuRefresh, SIGNAL(triggered()), this, SLOT(refreshJsonTree()));
34  connect(ui->menuInsertNode, SIGNAL(triggered()), this, SLOT(insertTreeNode()));
35  connect(ui->menuInsertChild, SIGNAL(triggered()), this, SLOT(insertTreeChild()));
36  connect(ui->menuDeleteNode, SIGNAL(triggered()), this, SLOT(deleteTreeNode()));
37  connect(ui->jsonTree, SIGNAL(clicked(QModelIndex)), this, SLOT(updateActions()));
38  connect(ui->menuFormat, SIGNAL(triggered()), this, SLOT(formatCode()));
39  connect(ui->menuHelp, SIGNAL(triggered()), this, SLOT(showHelp()));
40  connect(ui->jsonTree, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(dataEdit(QModelIndex)));
41 
42 
43 // connect(ui->menuNewFile, SIGNAL(triggered()), this, SLOT(newFile()));
44  connect(ui->menuOpenFile, SIGNAL(triggered()), this, SLOT(open()));
45  connect(ui->menuSaveFile, SIGNAL(triggered()), this, SLOT(save()));
46  connect(ui->menuSaveAs, SIGNAL(triggered()), this, SLOT(saveAs()));
47 
48  JSHighlighter * highlight = new JSHighlighter(ui->jsonCode->document());
49 
50  setCurrentFile("");
51 
52  textEdit = ui->jsonCode;
53  connect(textEdit->document(), SIGNAL(contentsChanged()),
54  this, SLOT(documentWasModified()));
55  setUnifiedTitleAndToolBarOnMac(true);
56 /*
57  m_findDialog = new FindDialog(this);
58  m_findDialog->setModal(false);
59  m_findDialog->setTextEdit(textEdit);
60 
61  m_findReplaceDialog = new FindReplaceDialog(this);
62  m_findReplaceDialog->setModal(false);
63  m_findReplaceDialog->setTextEdit(textEdit);
64 
65  connect(ui->menuFind, SIGNAL(triggered()), m_findDialog, SLOT(show()));
66  connect(ui->menuReplace, SIGNAL(triggered()), m_findReplaceDialog, SLOT(show()));
67 */
68 // connect(ui->actionFindNext, SIGNAL(triggered()), m_findDialog, SLOT(findNext()));
69 // connect(ui->actionFindPrevious, SIGNAL(triggered()), m_findDialog, SLOT(findPrev()));
70 
71  readSettings();
72 }

References dataEdit(), deleteTreeNode(), documentWasModified(), formatCode(), insertTreeChild(), insertTreeNode(), open(), readSettings(), refreshJsonTree(), save(), saveAs(), setCurrentFile(), showHelp(), textEdit, toggleCodeToolbar(), toggleEditToolbar(), toggleFileToolbar(), toggleFindToolbar(), ui, and updateActions().

Here is the call graph for this function:

◆ ~JsonEditorMain()

JsonEditorMain::~JsonEditorMain ( )

Definition at line 74 of file jsoneditormain.cpp.

75 {
76  delete ui;
77 }

References ui.

Member Function Documentation

◆ changeEvent()

void JsonEditorMain::changeEvent ( QEvent *  e)
protected

Definition at line 79 of file jsoneditormain.cpp.

80 {
81  QMainWindow::changeEvent(e);
82  switch (e->type()) {
83  case QEvent::LanguageChange:
84  ui->retranslateUi(this);
85  break;
86  default:
87  break;
88  }
89 }

References ui.

◆ closeEvent()

void JsonEditorMain::closeEvent ( QCloseEvent *  event)
protected

Definition at line 363 of file jsoneditormain.cpp.

364 {
365  if (maybeSave()) {
366  writeSettings();
367  event->accept();
368  } else {
369  event->ignore();
370  }
371 }

References maybeSave(), and writeSettings().

Here is the call graph for this function:

◆ dataEdit

void JsonEditorMain::dataEdit ( QModelIndex  editIndex)
privateslot

Definition at line 338 of file jsoneditormain.cpp.

339 {
340  QString vType = editIndex.sibling(editIndex.row(), 2).data(Qt::EditRole).toString();
341 
342  if (vType.compare(tr("object")) != 0
343  && vType.compare(tr("array")) != 0)
344  {
345  if (editIndex.column() >= 2)
346  {
347  QModelIndex newIndex = editIndex.sibling(editIndex.row(), 1);
348  ui->jsonTree->edit(newIndex);
349  }
350  }
351  else
352  {
353  QModelIndex newIndex = editIndex.sibling(editIndex.row(), 0);
354  ui->jsonTree->edit(newIndex);
355  }
356 }

References ui.

Referenced by JsonEditorMain().

Here is the caller graph for this function:

◆ deleteTreeNode

void JsonEditorMain::deleteTreeNode ( )
privateslot

Definition at line 229 of file jsoneditormain.cpp.

230 {
231  QModelIndex index = ui->jsonTree->selectionModel()->currentIndex();
232  QAbstractItemModel *model = ui->jsonTree->model();
233  if (model->removeRow(index.row(), index.parent()))
234  updateActions();
235 }

References ui, and updateActions().

Referenced by JsonEditorMain().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ documentWasModified

void JsonEditorMain::documentWasModified ( )
privateslot

Definition at line 358 of file jsoneditormain.cpp.

359 {
360  setWindowModified(textEdit->document()->isModified());
361 }

References textEdit.

Referenced by JsonEditorMain().

Here is the caller graph for this function:

◆ formatCode

void JsonEditorMain::formatCode ( )
privateslot

Definition at line 256 of file jsoneditormain.cpp.

257 {
258  if (ui->jsonTree->model() != NULL)
259  {
260  ui->jsonCode->clear();
261 
262  QString codeText = "";
263  JsonTreeModel *model;
264  model = (JsonTreeModel*)ui->jsonTree->model();
265  codeText += treeFormat(model->getRootItem(), "", true);
266 
267  ui->jsonCode->setPlainText(codeText);
268  }
269 }

References JsonTreeModel::getRootItem(), treeFormat(), and ui.

Referenced by JsonEditorMain().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ insertTreeChild

void JsonEditorMain::insertTreeChild ( )
privateslot

Definition at line 184 of file jsoneditormain.cpp.

185 {
186  AddNodeDlg dlg;
187  if (dlg.exec() == QDialog::Accepted)
188  {
189  QModelIndex index = ui->jsonTree->selectionModel()->currentIndex();
190  JsonTreeModel *model = (JsonTreeModel*)ui->jsonTree->model();
191 
192  if (index.column() != 0)
193  {
194  index = index.sibling(index.row(), 0);
195  }
196 
197  if (model->columnCount(index) == 0)
198  {
199  if (!model->insertColumn(0, index))
200  return;
201  }
202 
203  if (!model->insertRow(0, index))
204  return;
205 
206  /*
207  for (int column = 0; column < model->columnCount(index); column++)
208  {
209  QModelIndex child = model->index(0, column, index);
210  model->setData(child, QVariant(newInsertText), Qt::EditRole);
211  }
212  */
213 
214  QModelIndex child = model->index(0, 0, index);
215  model->setData(child, QVariant(dlg.getName()), Qt::EditRole);
216 
217  child = model->index(0, 1, index);
218  model->setData(child, QVariant(dlg.getValue()), Qt::EditRole);
219 
220  child = model->index(0, 2, index);
221  model->setData(child, QVariant(dlg.getType()), Qt::EditRole);
222 
223  ui->jsonTree->selectionModel()->setCurrentIndex(model->index(0, 0, index),
224  QItemSelectionModel::ClearAndSelect);
225  updateActions();
226  }
227 }

References JsonTreeModel::columnCount(), AddNodeDlg::getName(), AddNodeDlg::getType(), AddNodeDlg::getValue(), JsonTreeModel::index(), JsonTreeModel::setData(), ui, and updateActions().

Referenced by JsonEditorMain().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ insertTreeNode

void JsonEditorMain::insertTreeNode ( )
privateslot

Definition at line 147 of file jsoneditormain.cpp.

148 {
149  AddNodeDlg dlg;
150  if (dlg.exec() == QDialog::Accepted)
151  {
152  if(ui->jsonTree->selectionModel() == 0)
153  {
154  QMessageBox::warning(this,this->windowTitle(),"Adding a node to an empty tree is not supported.");
155  return;
156  }
157 
158  QModelIndex index = ui->jsonTree->selectionModel()->currentIndex();
159  QAbstractItemModel *model = ui->jsonTree->model();
160 
161  if (!model->insertRow(index.row()+1, index.parent()))
162  return;
163 
164  updateActions();
165 
166  /*
167  for (int column = 0; column < model->columnCount(index.parent()); ++column)
168  {
169  QModelIndex child = model->index(index.row()+1, column, index.parent());
170  model->setData(child, QVariant(newInsertText), Qt::EditRole);
171  }
172  */
173  QModelIndex child = model->index(index.row()+1, 0, index.parent());
174  model->setData(child, QVariant(dlg.getName()), Qt::EditRole);
175 
176  child = model->index(index.row()+1, 1, index.parent());
177  model->setData(child, QVariant(dlg.getValue()), Qt::EditRole);
178 
179  child = model->index(index.row()+1, 2, index.parent());
180  model->setData(child, QVariant(dlg.getType()), Qt::EditRole);
181  }
182 }

References AddNodeDlg::getName(), AddNodeDlg::getType(), AddNodeDlg::getValue(), ui, and updateActions().

Referenced by JsonEditorMain().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadFile()

void JsonEditorMain::loadFile ( const QString &  fileName)
private

Definition at line 454 of file jsoneditormain.cpp.

455 {
456  QFile file(fileName);
457  if (!file.open(QFile::ReadOnly | QFile::Text)) {
458  QMessageBox::warning(this, this->windowTitle(),
459  tr("Cannot read file %1:\n%2.")
460  .arg(fileName)
461  .arg(file.errorString()));
462  return;
463  }
464 
465  QTextStream in(&file);
466 #ifndef QT_NO_CURSOR
467  QApplication::setOverrideCursor(Qt::WaitCursor);
468 #endif
469  textEdit->setPlainText(in.readAll());
470 #ifndef QT_NO_CURSOR
471  QApplication::restoreOverrideCursor();
472 #endif
473 
474  setCurrentFile(fileName);
475  statusBar()->showMessage(tr("File loaded"), 2000);
476 }

References setCurrentFile(), and textEdit.

Referenced by open(), and readSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ maybeSave()

bool JsonEditorMain::maybeSave ( )
private

Definition at line 438 of file jsoneditormain.cpp.

439 {
440  if (ui->jsonCode->document()->isModified()) {
441  QMessageBox::StandardButton ret;
442  ret = QMessageBox::warning(this, this->windowTitle(),
443  tr("The document has been modified.\n"
444  "Do you want to save your changes?"),
445  QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
446  if (ret == QMessageBox::Save)
447  return save();
448  else if (ret == QMessageBox::Cancel)
449  return false;
450  }
451  return true;
452 }

References save(), and ui.

Referenced by closeEvent(), and open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_Send_clicked

void JsonEditorMain::on_Send_clicked ( )
privateslot

Definition at line 538 of file jsoneditormain.cpp.

539 {
540  std::shared_ptr<std::map<std::string, std::vector<rclcpp::Parameter>>> parameterMap = std::make_shared<std::map<std::string, std::vector<rclcpp::Parameter>>>();
541 
542  JsonTreeModel *model;
543  model = (JsonTreeModel*)ui->jsonTree->model();
544  if(model == nullptr) {
545  std::cout << "No file loaded. Abort sending." << std::endl;
546  return;
547  }
548 
549  JsonTreeItem *rootItem = model->getRootItem();
550  if(rootItem == nullptr) {
551  std::cout << "No file loaded. Abort sending." << std::endl;
552  return;
553  }
554 
555  QString objectType = rootItem->data(2).toString();
556 
557  if (objectType.compare(tr("object"), Qt::CaseInsensitive) == 0
558  || objectType.compare(treeViewColumnType, Qt::CaseInsensitive) == 0)
559  {
560  JsonTreeItem *nodeObjectItem;
561  JsonTreeItem *subsectionObjectItem;
562  JsonTreeItem *parameterObjectItem;
563 
564  for (int node_i = 0; node_i < rootItem->childCount(); node_i++)
565  {
566  nodeObjectItem = rootItem->child(node_i);
567  QString node_objectKey = nodeObjectItem->data(0).toString();
568  std::string node_objectKey_str = node_objectKey.toStdString().c_str();
569 
570  parameterMap->insert(std::make_pair(node_objectKey_str, std::vector<rclcpp::Parameter>()));
571 
572  for (int subsection_i = 0; subsection_i < nodeObjectItem->childCount(); subsection_i++)
573  {
574  subsectionObjectItem = nodeObjectItem->child(subsection_i);
575  QString subsection_objectKey = subsectionObjectItem->data(0).toString();
576  std::string subsection_objectKey_str = subsection_objectKey.toStdString().c_str();
577 
578  for (int parameter_i = 0; parameter_i < subsectionObjectItem->childCount(); parameter_i++)
579  {
580  parameterObjectItem = subsectionObjectItem->child(parameter_i);
581  QString parameter_objectKey = parameterObjectItem->data(0).toString();
582  std::string parameter_objectKey_str = parameter_objectKey.toStdString().c_str();
583 
584  QString parameter_objectType = parameterObjectItem->data(2).toString();
585  if(parameter_objectType == "unsigned integer") {
586  int parameter_objectValue_int = parameterObjectItem->data(1).toInt();
587  (*parameterMap)[node_objectKey_str].push_back(rclcpp::Parameter(subsection_objectKey_str + "." + parameter_objectKey_str, parameter_objectValue_int));
588  }
589  else if(parameter_objectType == "double") {
590  double parameter_objectValue_double = parameterObjectItem->data(1).toDouble();
591  (*parameterMap)[node_objectKey_str].push_back(rclcpp::Parameter(subsection_objectKey_str + "." + parameter_objectKey_str, parameter_objectValue_double));
592  }
593  else {
594  RCLCPP_ERROR(m_nodeSPtr->get_logger(), "[SYSTEM SETTINGS] Type of parameter %s %s.%s %s", node_objectKey.toLocal8Bit().data(), subsection_objectKey.toLocal8Bit().data(), parameter_objectKey.toLocal8Bit().data(), " is NOT valid (INT or FLOAT/DOUBLE). Skipping.");
595  }
596  }
597  }
598  }
599  }
600 
601  // send parameters to node
602  m_parameterMap = parameterMap;
603  std::thread(std::bind(&testSetupNode::send_settings_, m_nodeSPtr, m_parameterMap)).detach();
604 }

References JsonTreeItem::child(), JsonTreeItem::childCount(), JsonTreeItem::data(), m_parameterMap, testSetupNode::send_settings_(), treeViewColumnType, and ui.

Here is the call graph for this function:

◆ open

void JsonEditorMain::open ( )
privateslot

Definition at line 373 of file jsoneditormain.cpp.

374 {
375  if (maybeSave()) {
376  QString fileName = QFileDialog::getOpenFileName(this,"Open Json File",lastFilePath);
377  if (!fileName.isEmpty())
378  {
379  QFileInfo info(fileName);
380  lastFilePath = info.absoluteDir().absolutePath();
381  loadFile(fileName);
382  }
383  }
384 
385  ui->menuRefresh->trigger();
386 }

References lastFilePath, loadFile(), maybeSave(), and ui.

Referenced by JsonEditorMain().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readSettings()

void JsonEditorMain::readSettings ( )
private

Definition at line 411 of file jsoneditormain.cpp.

412 {
413  QSettings settings;
414 // QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
415 // QSize size = settings.value("size", QSize(400, 400)).toSize();
416 // resize(size);
417 // move(pos);
418  this->restoreGeometry(settings.value("geometry").toByteArray());
419  lastFilePath = (settings.value("file_path").toString());
420  curFile = settings.value("last_opened_file").toString();
421  if(this->curFile.length() != 0)
422  {
423  loadFile(curFile);
424  ui->menuRefresh->trigger();
425  }
426 }

References curFile, lastFilePath, loadFile(), and ui.

Referenced by JsonEditorMain().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ refreshJsonTree

void JsonEditorMain::refreshJsonTree ( )
privateslot

Definition at line 111 of file jsoneditormain.cpp.

112 {
113  if (!ui->jsonCode->document()->isEmpty())
114  {
115  // QByteArray ss = ui->jsonCode->toPlainText().toLocal8Bit();
116  std::string json = ui->jsonCode->toPlainText().toStdString();
117 
118  jsonValue.clear();
119  jsonValue = nlohmann::json::parse(json);
120 
121 
122  QStringList headers;
124 
125 
126 
127  QAbstractItemModel *oldModel = ui->jsonTree->model();
128  if (oldModel != NULL)
129  oldModel->disconnect(SIGNAL(dataChanged(QModelIndex,QModelIndex)));
130 
131  JsonTreeModel *model = new JsonTreeModel(headers, jsonValue);
132  QItemSelectionModel *selectionModel = ui->jsonTree->selectionModel();
133  connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(treeViewDataChanged()));
134  ui->jsonTree->setModel(model);
135  ui->jsonTree->reset();
136  delete selectionModel;
137  delete oldModel;
138 
139 
140  ui->jsonTree->expandAll();
141 
142  for (int i = 0; i < ui->jsonTree->model()->columnCount(); i++)
143  ui->jsonTree->resizeColumnToContents(i);
144  }
145 }

References jsonValue, treeViewColumnKey, treeViewColumnType, treeViewColumnValue, treeViewDataChanged(), and ui.

Referenced by JsonEditorMain().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save

bool JsonEditorMain::save ( )
privateslot

Definition at line 388 of file jsoneditormain.cpp.

389 {
390  if (curFile.isEmpty()) {
391  return saveAs();
392  } else {
393  return saveFile(curFile);
394  }
395 }

References curFile, saveAs(), and saveFile().

Referenced by JsonEditorMain(), and maybeSave().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveAs

bool JsonEditorMain::saveAs ( )
privateslot

Definition at line 397 of file jsoneditormain.cpp.

398 {
399  QFileDialog dialog(this);
400  dialog.setWindowModality(Qt::WindowModal);
401  dialog.setAcceptMode(QFileDialog::AcceptSave);
402  dialog.exec();
403  QStringList files = dialog.selectedFiles();
404 
405  if (files.isEmpty())
406  return false;
407 
408  return saveFile(files.at(0));
409 }

References saveFile().

Referenced by JsonEditorMain(), and save().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveFile()

bool JsonEditorMain::saveFile ( const QString &  fileName)
private

Definition at line 478 of file jsoneditormain.cpp.

479 {
480  ui->menuFormat->trigger();
481 
482  QFile file(fileName);
483  QFileInfo info(fileName);
484  lastFilePath = info.absoluteDir().absolutePath();
485  if (!file.open(QFile::WriteOnly | QFile::Text)) {
486  QMessageBox::warning(this, this->windowTitle(),
487  tr("Cannot write file %1:\n%2.")
488  .arg(fileName)
489  .arg(file.errorString()));
490  return false;
491  }
492 
493  QTextStream out(&file);
494 #ifndef QT_NO_CURSOR
495  QApplication::setOverrideCursor(Qt::WaitCursor);
496 #endif
497  // hacky schmacky workaround because ',' is added at file ending!
498  auto content = textEdit->toPlainText();
499  content.remove(content.length() - 2, 2);
500  out << content;
501 #ifndef QT_NO_CURSOR
502  QApplication::restoreOverrideCursor();
503 #endif
504 
505  setCurrentFile(fileName);
506  statusBar()->showMessage(tr("File saved"), 2000);
507  return true;
508 }

References lastFilePath, setCurrentFile(), textEdit, and ui.

Referenced by save(), and saveAs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setCurrentFile()

void JsonEditorMain::setCurrentFile ( const QString &  fileName)
private

Definition at line 510 of file jsoneditormain.cpp.

511 {
512  curFile = fileName;
513  ui->jsonCode->document()->setModified(false);
514  setWindowModified(false);
515 
516  QString shownName = curFile;
517  if (curFile.isEmpty())
518  shownName = "untitled.json";
519  setWindowFilePath(shownName);
520 }

References curFile, and ui.

Referenced by JsonEditorMain(), loadFile(), and saveFile().

Here is the caller graph for this function:

◆ showHelp

void JsonEditorMain::showHelp ( )
privateslot

Definition at line 330 of file jsoneditormain.cpp.

331 {
332  QMessageBox::information(this, tr("Using Help"), tr(
333  "1 On the left side of the main interface to fill the JSON code \n"
334  "2 Click on the menu \" Generate code tree \", the right of the main interface will spanning tree \n"
335  "3 To insert or delete after the tree node or modify the value, click on the menu \" Generate Code \", will generate JSON code from the tree." ));
336 }

Referenced by JsonEditorMain().

Here is the caller graph for this function:

◆ strippedName()

QString JsonEditorMain::strippedName ( const QString &  fullFileName)
private

Definition at line 522 of file jsoneditormain.cpp.

523 {
524  return QFileInfo(fullFileName).fileName();
525 }

◆ toggleCodeToolbar

void JsonEditorMain::toggleCodeToolbar ( bool  checked)
privateslot

Definition at line 91 of file jsoneditormain.cpp.

92 {
93  checked ? ui->codeToolBar->show() : ui->codeToolBar->hide();
94 }

References ui.

Referenced by JsonEditorMain().

Here is the caller graph for this function:

◆ toggleEditToolbar

void JsonEditorMain::toggleEditToolbar ( bool  checked)
privateslot

Definition at line 96 of file jsoneditormain.cpp.

97 {
98  checked ? ui->editToolBar->show() : ui->editToolBar->hide();
99 }

References ui.

Referenced by JsonEditorMain().

Here is the caller graph for this function:

◆ toggleFileToolbar

void JsonEditorMain::toggleFileToolbar ( bool  checked)
privateslot

Definition at line 101 of file jsoneditormain.cpp.

102 {
103  checked ? ui->fileToolBar->show() : ui->fileToolBar->hide();
104 }

References ui.

Referenced by JsonEditorMain().

Here is the caller graph for this function:

◆ toggleFindToolbar

void JsonEditorMain::toggleFindToolbar ( bool  checked)
privateslot

Definition at line 106 of file jsoneditormain.cpp.

107 {
108  checked ? ui->findToolBar->show() : ui->findToolBar->hide();
109 }

References ui.

Referenced by JsonEditorMain().

Here is the caller graph for this function:

◆ treeFormat()

QString JsonEditorMain::treeFormat ( JsonTreeItem *  treeItem = NULL,
QString  indent = "",
bool  noHeader = false 
)
private

Definition at line 271 of file jsoneditormain.cpp.

272 {
273  QString resultStr;
274  QString objectKey = treeItem->data(0).toString();
275  QString objectValue = treeItem->data(1).toString();
276  QString objectType = treeItem->data(2).toString();
277 
278  if (noHeader)
279  {
280  resultStr = indent;
281  }
282  else
283  {
284  resultStr = indent + QString("\"") + objectKey + "\": ";
285  }
286 
287  if (objectType.compare(tr("object"), Qt::CaseInsensitive) == 0
288  || objectType.compare(treeViewColumnType, Qt::CaseInsensitive) == 0)
289  {
290  resultStr += "{\n";
291  JsonTreeItem *subObjectItem;
292  for (int i = 0; i < treeItem->childCount(); i++)
293  {
294  subObjectItem = treeItem->child(i);
295  resultStr += treeFormat(subObjectItem, indent + " ");
296  }
297  if(treeItem->childCount() > 0)
298  resultStr.remove(resultStr.length() - 2, 1);// remove trailing comma
299  resultStr += indent + "},\n";
300  }
301  else if (objectType.compare(tr("array"), Qt::CaseInsensitive) == 0)
302  {
303  resultStr += "[\n";
304  JsonTreeItem *subObjectItem;
305  for (int i = 0; i < treeItem->childCount(); i++)
306  {
307  subObjectItem = treeItem->child(i);
308  resultStr += treeFormat(subObjectItem, indent + " ", true);
309  }
310  if(treeItem->childCount() > 0)
311  resultStr.remove(resultStr.length() - 2, 1);// remove trailing comma
312  resultStr += indent + "],\n";
313  }
314  else
315  {
316  if (objectType.compare(tr("string"), Qt::CaseInsensitive) == 0 ||
317  objectType.compare(newInsertText, Qt::CaseInsensitive) == 0)
318  {
319  resultStr += "\"" + objectValue + "\",\n";
320  }
321  else
322  {
323  resultStr += objectValue + ",\n";
324  }
325  }
326 
327  return resultStr;
328 }

References JsonTreeItem::child(), JsonTreeItem::childCount(), JsonTreeItem::data(), newInsertText, and treeViewColumnType.

Referenced by formatCode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ treeViewDataChanged

void JsonEditorMain::treeViewDataChanged ( )
privateslot

Definition at line 247 of file jsoneditormain.cpp.

248 {
249  for (int i = 0; i < ui->jsonTree->model()->columnCount(); i++)
250  {
251  ui->jsonTree->resizeColumnToContents(i);
252  ui->jsonTree->setColumnWidth(i, ui->jsonTree->columnWidth(i) + 20);
253  }
254 }

References ui.

Referenced by refreshJsonTree().

Here is the caller graph for this function:

◆ updateActions

void JsonEditorMain::updateActions ( )
privateslot

Definition at line 237 of file jsoneditormain.cpp.

238  {
239  bool hasSelection = !ui->jsonTree->selectionModel()->selection().isEmpty();
240  ui->menuDeleteNode->setEnabled(hasSelection);
241 
242  bool hasCurrent = ui->jsonTree->selectionModel()->currentIndex().isValid();
243  ui->menuInsertNode->setEnabled(hasCurrent);
244  ui->menuInsertChild->setEnabled(hasCurrent);
245  }

References ui.

Referenced by deleteTreeNode(), insertTreeChild(), insertTreeNode(), and JsonEditorMain().

Here is the caller graph for this function:

◆ writeSettings()

void JsonEditorMain::writeSettings ( )
private

Definition at line 428 of file jsoneditormain.cpp.

429 {
430  QSettings settings;
431 // settings.setValue("pos", pos());
432 // settings.setValue("size", size());
433  settings.setValue("geometry", this->saveGeometry());
434  settings.setValue("file_path", lastFilePath);
435  settings.setValue("last_opened_file", this->curFile);
436 }

References curFile, and lastFilePath.

Referenced by closeEvent().

Here is the caller graph for this function:

Member Data Documentation

◆ curFile

QString JsonEditorMain::curFile
private

Definition at line 62 of file jsoneditormain.h.

Referenced by readSettings(), save(), setCurrentFile(), and writeSettings().

◆ jsonValue

nlohmann::json JsonEditorMain::jsonValue
private

Definition at line 47 of file jsoneditormain.h.

Referenced by refreshJsonTree().

◆ lastFilePath

QString JsonEditorMain::lastFilePath
private

Definition at line 64 of file jsoneditormain.h.

Referenced by open(), readSettings(), saveFile(), and writeSettings().

◆ m_parameterMap

std::shared_ptr<std::map<std::string, std::vector<rclcpp::Parameter> > > JsonEditorMain::m_parameterMap
private

Definition at line 66 of file jsoneditormain.h.

Referenced by on_Send_clicked().

◆ newInsertText

const QString JsonEditorMain::newInsertText
private

Definition at line 49 of file jsoneditormain.h.

Referenced by treeFormat().

◆ textEdit

QTextEdit* JsonEditorMain::textEdit
private

Definition at line 63 of file jsoneditormain.h.

Referenced by documentWasModified(), JsonEditorMain(), loadFile(), and saveFile().

◆ treeViewColumnKey

const QString JsonEditorMain::treeViewColumnKey
private

Definition at line 50 of file jsoneditormain.h.

Referenced by refreshJsonTree().

◆ treeViewColumnType

const QString JsonEditorMain::treeViewColumnType
private

Definition at line 52 of file jsoneditormain.h.

Referenced by on_Send_clicked(), refreshJsonTree(), and treeFormat().

◆ treeViewColumnValue

const QString JsonEditorMain::treeViewColumnValue
private

Definition at line 51 of file jsoneditormain.h.

Referenced by refreshJsonTree().

◆ ui


The documentation for this class was generated from the following files:
JsonEditorMain::treeFormat
QString treeFormat(JsonTreeItem *treeItem=NULL, QString indent="", bool noHeader=false)
Definition: jsoneditormain.cpp:271
JsonEditorMain::insertTreeChild
void insertTreeChild()
Definition: jsoneditormain.cpp:184
testSetupNode::send_settings_
bool send_settings_(std::shared_ptr< std::map< std::string, std::vector< rclcpp::Parameter >>> p_settingsGUIParameterMap)
Definition: testSetupNode.cpp:20
JsonEditorMain::insertTreeNode
void insertTreeNode()
Definition: jsoneditormain.cpp:147
AddNodeDlg::getType
QString getType()
Definition: addnodedlg.cpp:51
JsonEditorMain::lastFilePath
QString lastFilePath
Definition: jsoneditormain.h:64
AddNodeDlg::getName
QString getName()
Definition: addnodedlg.cpp:46
JsonEditorMain::refreshJsonTree
void refreshJsonTree()
Definition: jsoneditormain.cpp:111
JsonTreeModel::setData
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Definition: jsontreemodel.cpp:153
JsonEditorMain::updateActions
void updateActions()
Definition: jsoneditormain.cpp:237
JSHighlighter
Definition: jsedit.h:121
json
nlohmann::json json
Definition: AutoPilotNode.hpp:21
AddNodeDlg::getValue
QString getValue()
Definition: addnodedlg.cpp:41
JsonEditorMain::documentWasModified
void documentWasModified()
Definition: jsoneditormain.cpp:358
JsonEditorMain::readSettings
void readSettings()
Definition: jsoneditormain.cpp:411
JsonEditorMain::dataEdit
void dataEdit(QModelIndex editIndex)
Definition: jsoneditormain.cpp:338
JsonEditorMain::deleteTreeNode
void deleteTreeNode()
Definition: jsoneditormain.cpp:229
JsonTreeItem::childCount
int childCount() const
Definition: jsontreeitem.cpp:21
JsonEditorMain::formatCode
void formatCode()
Definition: jsoneditormain.cpp:256
JsonEditorMain::saveFile
bool saveFile(const QString &fileName)
Definition: jsoneditormain.cpp:478
JsonEditorMain::treeViewColumnType
const QString treeViewColumnType
Definition: jsoneditormain.h:52
JsonEditorMain::toggleFindToolbar
void toggleFindToolbar(bool checked)
Definition: jsoneditormain.cpp:106
JsonTreeItem::child
JsonTreeItem * child(int number)
Definition: jsontreeitem.cpp:16
JsonEditorMain::showHelp
void showHelp()
Definition: jsoneditormain.cpp:330
JsonEditorMain::setCurrentFile
void setCurrentFile(const QString &fileName)
Definition: jsoneditormain.cpp:510
JsonEditorMain::saveAs
bool saveAs()
Definition: jsoneditormain.cpp:397
JsonEditorMain::open
void open()
Definition: jsoneditormain.cpp:373
JsonEditorMain::treeViewDataChanged
void treeViewDataChanged()
Definition: jsoneditormain.cpp:247
JsonEditorMain::maybeSave
bool maybeSave()
Definition: jsoneditormain.cpp:438
JsonEditorMain::save
bool save()
Definition: jsoneditormain.cpp:388
JsonEditorMain::toggleEditToolbar
void toggleEditToolbar(bool checked)
Definition: jsoneditormain.cpp:96
JsonEditorMain::toggleCodeToolbar
void toggleCodeToolbar(bool checked)
Definition: jsoneditormain.cpp:91
JsonEditorMain::ui
Ui::JsonEditorMain * ui
Definition: jsoneditormain.h:46
JsonTreeModel
Definition: jsontreemodel.h:13
JsonEditorMain::textEdit
QTextEdit * textEdit
Definition: jsoneditormain.h:63
JsonEditorMain::m_parameterMap
std::shared_ptr< std::map< std::string, std::vector< rclcpp::Parameter > > > m_parameterMap
Definition: jsoneditormain.h:66
AddNodeDlg
Definition: addnodedlg.h:10
JsonEditorMain::treeViewColumnKey
const QString treeViewColumnKey
Definition: jsoneditormain.h:50
JsonTreeModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: jsontreemodel.cpp:25
JsonTreeModel::getRootItem
JsonTreeItem * getRootItem()
Definition: jsontreemodel.cpp:260
JsonEditorMain::loadFile
void loadFile(const QString &fileName)
Definition: jsoneditormain.cpp:454
JsonTreeItem::data
QVariant data(int column) const
Definition: jsontreeitem.cpp:39
JsonEditorMain::curFile
QString curFile
Definition: jsoneditormain.h:62
JsonTreeModel::index
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: jsontreemodel.cpp:69
JsonEditorMain::jsonValue
nlohmann::json jsonValue
Definition: jsoneditormain.h:47
JsonEditorMain::writeSettings
void writeSettings()
Definition: jsoneditormain.cpp:428
JsonEditorMain::toggleFileToolbar
void toggleFileToolbar(bool checked)
Definition: jsoneditormain.cpp:101
JsonTreeItem
Definition: jsontreeitem.h:8
JsonEditorMain::treeViewColumnValue
const QString treeViewColumnValue
Definition: jsoneditormain.h:51
JsonEditorMain::newInsertText
const QString newInsertText
Definition: jsoneditormain.h:49