24 #include <QDialogButtonBox>
25 #include <QHeaderView>
26 #include <QStandardItemModel>
27 #include <QVBoxLayout>
33 using boost::property_tree::ptree;
36 :
QDialog(parent), m_table_view(new QTableView()), m_model(new QStandardItemModel(m_table_view))
38 m_model->setHorizontalHeaderLabels(QStringList() <<
"Key" <<
"Data");
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);
57 if (key->checkState() == Qt::Checked) {
58 pt.add(key->text().toStdString(), data->text().toStdString());
61 pt.add(key->text().toStdString(),
"");
68 void CopyAttributesDialog::InitializeModel(
const ptree& 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);
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);
83 m_model->appendRow(QList<QStandardItem*>() << key << data);
87 void CopyAttributesDialog::SetupGui()
89 setWindowTitle(
"Choose cell attributes");
92 QVBoxLayout* layout =
new QVBoxLayout();
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);
104 m_table_view->horizontalHeader()->setClickable(
false);
106 m_table_view->verticalHeader()->setHidden(
true);
107 m_table_view->resizeColumnsToContents();
108 layout->addWidget(m_table_view);
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);
Namespace for SimPT tissue editor package.
Interface for CopyAttributesDialog.
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.
virtual ~CopyAttributesDialog()
Destructor.
see the online Qt documentation
CopyAttributesDialog(const boost::property_tree::ptree &pt, QWidget *parent=nullptr)
Constructor.
see the online Qt documentation