VPTissue Reference Manual
CopyAttributesDialog.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "CopyAttributesDialog.h"
21 
22 #include "ptree/PTreeUtils.h"
23 
24 #include <QDialogButtonBox>
25 #include <QHeaderView>
26 #include <QStandardItemModel>
27 #include <QVBoxLayout>
28 
29 class QWidget;
30 
31 namespace SimPT_Editor {
32 
33 using boost::property_tree::ptree;
34 
36  : QDialog(parent), m_table_view(new QTableView()), m_model(new QStandardItemModel(m_table_view))
37 {
38  m_model->setHorizontalHeaderLabels(QStringList() << "Key" << "Data");
39 
40  InitializeModel(pt);
41  SetupGui();
42 }
43 
45 {
46  delete m_table_view;
47 }
48 
50 {
51  ptree pt;
52 
53  for (int i = 0; i < m_model->rowCount(); i++) {
54  QStandardItem* key = m_model->item(i, 0);
55  QStandardItem* data = m_model->item(i, 1);
56 
57  if (key->checkState() == Qt::Checked) {
58  pt.add(key->text().toStdString(), data->text().toStdString());
59  }
60  else {
61  pt.add(key->text().toStdString(), "");
62  }
63  }
64 
65  return pt;
66 }
67 
68 void CopyAttributesDialog::InitializeModel(const ptree& pt)
69 {
70  std::list<std::pair<std::string, std::string>> entries = SimPT_Sim::Util::PTreeUtils::Flatten(pt);
71  for (auto pair : entries) {
72  QStandardItem* key = new QStandardItem();
73  key->setData(QString::fromStdString(pair.first), Qt::DisplayRole);
74  key->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
75  key->setCheckable(true);
76  key->setEditable(false);
77 
78  QStandardItem* data = new QStandardItem();
79  data->setData(QString::fromStdString(pair.second), Qt::DisplayRole);
80  data->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
81  data->setEditable(false);
82 
83  m_model->appendRow(QList<QStandardItem*>() << key << data);
84  }
85 }
86 
87 void CopyAttributesDialog::SetupGui()
88 {
89  setWindowTitle("Choose cell attributes");
90  setMinimumWidth(400);
91 
92  QVBoxLayout* layout = new QVBoxLayout();
93 
94  m_table_view = new QTableView();
95  m_table_view->setModel(m_model);
96  m_table_view->setHorizontalScrollMode(QTableView::ScrollPerPixel);
97  m_table_view->setSelectionBehavior(QAbstractItemView::SelectRows);
98  m_table_view->setShowGrid(false);
99  m_table_view->horizontalHeader()->setStretchLastSection(true);
100  m_table_view->horizontalHeader()->setHighlightSections(false);
101 #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
102  m_table_view->horizontalHeader()->setSectionsClickable(false);
103 #else
104  m_table_view->horizontalHeader()->setClickable(false);
105 #endif
106  m_table_view->verticalHeader()->setHidden(true);
107  m_table_view->resizeColumnsToContents();
108  layout->addWidget(m_table_view);
109 
110  QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
111  connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
112  connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
113  layout->addWidget(buttonBox);
114 
115  setLayout(layout);
116 }
117 
118 } // namespace
Namespace for SimPT tissue editor package.
Definition: Cell.h:32
Interface for CopyAttributesDialog.
PTreeUtils interface.
boost::property_tree::ptree SelectedAttributes()
Get the selected attributes.
static std::list< std::pair< std::string, std::string > > Flatten(const boost::property_tree::ptree &pt, bool indexedArray=false, const std::string &path="")
Flattens a ptree from a given path.
Definition: PTreeUtils.cpp:130
see the online Qt documentation
CopyAttributesDialog(const boost::property_tree::ptree &pt, QWidget *parent=nullptr)
Constructor.
see the online Qt documentation