23 : QAbstractItemModel(parent)
25 QStringList root_keys;
26 QList<QVariant> root_data = {QVariant(
"Title"), QVariant(
"Description")};
27 root_item_ =
new TreeItem(TreeItem::ItemType::Base, root_keys, root_data, 0);
32 : QAbstractItemModel(parent)
34 QStringList root_keys;
35 QList<QVariant> root_data = {QVariant(
"Title"), QVariant(
"Description")};
36 root_item_ =
new TreeItem(TreeItem::ItemType::Base, root_keys, root_data, 0);
39 for (
auto dataset_key: dataset_keys){
40 QStringList dataset_item_keys = {dataset_key};
41 QList<QVariant> dataset_item_data = {QVariant(dataset_key),
44 dataset_item_keys, dataset_item_data,
46 QSharedPointer<VespucciDataset> dataset = data_model->
GetDataset(dataset_key);
47 QList<QStringList> corekeys = {
48 {dataset_key,
"Spectra"},
49 {dataset_key,
"Spectral Abscissa"},
54 QList<QList<QVariant> > coredata = {
55 {
"Spectra", DescribeSpectra(dataset->spectra_ref())},
56 {
"Spectral Abscissa", DescribeAbscissa(dataset->abscissa_ref())},
57 {
"x", DescribeMatrix(dataset->x_ref())},
58 {
"y", DescribeMatrix(dataset->y_ref())}
61 for (
int i = 0; i < coredata.size(); ++i){
69 for (
auto matrix_key: dataset->AuxiliaryMatrixKeys()){
70 QStringList item_keys = {dataset_key, matrix_key};
71 QList<QVariant> item_data =
72 {QVariant(matrix_key),
73 QVariant(DescribeMatrix(dataset->GetAuxiliaryMatrix(matrix_key)))
81 for (
auto results_key: dataset->AnalysisResultsKeys()){
82 QSharedPointer<AnalysisResults> results =
83 dataset->GetAnalysisResult(results_key);
84 QStringList results_item_keys = {dataset_key, results_key};
85 QList<QVariant> results_item_data = {QVariant(results_key),
86 QVariant(results->type())};
88 new TreeItem(TreeItem::ItemType::AnalysisResult,
93 for (
auto matrix_key: results->KeyList()){
94 QStringList matrix_item_keys = {dataset_key, results_key, matrix_key};
95 QList<QVariant> matrix_item_data = {QVariant(matrix_key),
96 QVariant(DescribeMatrix(results->GetMatrix(matrix_key)))
103 results_tree_item->appendChild(matrix_tree_item);
108 for (
auto map_key: dataset->MapKeys()){
109 QSharedPointer<MapData> mapdata = dataset->GetMapData(map_key);
110 QStringList map_item_keys = {dataset_key, map_key};
111 QList<QVariant> map_item_data = {QVariant(map_key),
112 QVariant(mapdata->type())};
131 for (
auto dataset_key: dataset_keys){
132 QSharedPointer<VespucciDataset> dataset = data_model->
GetDataset(dataset_key);
133 TreeItem *dataset_tree_item = SetupDatasetTreeItem(dataset);
146 if (!index.isValid())
148 if(role != Qt::DisplayRole)
151 return item->
data(index.column());
156 if (!index.isValid())
158 return QAbstractItemModel::flags(index);
163 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
164 return root_item_->
data(section);
170 if(!hasIndex(row, column, parent))
171 return QModelIndex();
173 if (!parent.isValid())
174 parent_item = root_item_;
176 parent_item =
static_cast<TreeItem*
>(parent.internalPointer());
180 return createIndex(row, column, child_item);
182 return QModelIndex();
187 if (!index.isValid())
188 return QModelIndex();
193 if (parent_item == root_item_)
194 return QModelIndex();
195 return createIndex(parent_item->
row(), 0, parent_item);
213 beginRemoveRows(parent, row, count + row - 1);
220 QList<TreeItem*> items = root_item_->
child_items();
223 for (
auto item: items)
224 if (!data_model->
DatasetNames().contains(item->data(0).toString()))
228 QStringList dataset_names = root_item_->
ChildNames();
230 if (!dataset_names.contains(dataset_key)){
231 TreeItem *dataset_tree_item = SetupDatasetTreeItem(data_model->
GetDataset(dataset_key));
238 QString dataset_name = item->data(0).toString();
240 QStringList core_matrix_names = {
"Spectra",
"Spectral Abscissa",
"x",
"y"};
243 QStringList child_names = item->ChildNames();
245 for (
auto results_name: analysis_results_names){
246 if (!child_names.contains(results_name)
247 && data_model->
GetResults(dataset_name, results_name)->KeyList().size()){
249 SetupAnalysisResultTreeItem(data_model->
GetDataset(dataset_name),
250 data_model->
GetResults(dataset_name, results_name),
257 for (
auto child_item: item->child_items()){
258 QString child_name = child_item->data(0).toString();
259 if (!analysis_results_names.contains(child_name)
260 && !core_matrix_names.contains(child_name)){
261 item->removeChild(child_item);
272 TreeItem *dataset_tree_item = SetupDatasetTreeItem(dataset);
280 beginRemoveRows(
index(0,0), 0, row_count - 1);
287 beginRemoveRows(index, index.row(), index.row());
294 if (index.isValid()){
296 if (item){
return item;}
311 TreeItem *DatasetTreeModel::SetupDatasetTreeItem(QSharedPointer<VespucciDataset> dataset)
313 QList<QVariant> dataset_data = {QVariant(dataset->name()), QVariant(
"Dataset")};
314 QStringList dataset_key_list = {dataset->name()};
319 QList<QStringList> corekeys = {
320 {dataset->name(),
"Spectra"},
321 {dataset->name(),
"Spectral Abscissa"},
322 {dataset->name(),
"x"},
323 {dataset->name(),
"y"}
326 QList<QList<QVariant> > coredata = {
327 {
"Spectra", DescribeSpectra(dataset->spectra_ref())},
328 {
"Spectral Abscissa", DescribeAbscissa(dataset->abscissa_ref())},
329 {
"x", DescribeMatrix(dataset->x_ref())},
330 {
"y", DescribeMatrix(dataset->y_ref())}
333 for (
int i = 0; i < coredata.size(); ++i){
341 for (
auto results_key: dataset->AnalysisResultsKeys()){
342 QSharedPointer<AnalysisResults> results = dataset->GetAnalysisResult(results_key);
344 SetupAnalysisResultTreeItem(dataset,
347 dataset_tree_item->
appendChild(analysis_results_item);
350 for (
auto matrix_key: dataset->AuxiliaryMatrixKeys()){
351 const mat& matrix = dataset->GetAuxiliaryMatrix(matrix_key);
352 TreeItem *matrix_item = SetupMatrixTreeItem(dataset->name(),
359 for (
auto map_key: dataset->MapKeys()){
360 QSharedPointer<MapData> map = dataset->GetMapData(map_key);
361 TreeItem *map_item = SetupMapTreeItem(dataset->name(),
368 return dataset_tree_item;
377 TreeItem *DatasetTreeModel::SetupAnalysisResultTreeItem(QSharedPointer<VespucciDataset> dataset,
378 QSharedPointer<AnalysisResults> results,
381 QStringList analysis_results_key_list = {dataset->name(), results->name()};
383 QList<QVariant> analysis_results_item_data =
384 {results->name(), results->
type()};
388 analysis_results_key_list,
389 analysis_results_item_data,
392 for (
auto matrix_key: results->KeyList()){
394 SetupMatrixTreeItem(dataset->name(),
396 results->GetMatrix(matrix_key),
401 return results_tree_item;
413 TreeItem *DatasetTreeModel::SetupMatrixTreeItem(
const QString &dataset_key,
414 const QString &results_key,
415 const QString &matrix_key,
419 QStringList matrix_key_list = {dataset_key, results_key, matrix_key};
420 QList<QVariant> matrix_data = {matrix_key, DescribeMatrix(matrix)};
432 TreeItem *DatasetTreeModel::SetupMatrixTreeItem(
const QString &dataset_key,
433 const QString &matrix_key,
437 QStringList matrix_key_list = {dataset_key, matrix_key};
438 QList<QVariant> matrix_data = {matrix_key, DescribeMatrix(matrix)};
450 TreeItem *DatasetTreeModel::SetupMapTreeItem(
const QString &dataset_key,
451 const QString &map_key,
452 QSharedPointer<MapData>
data,
455 QStringList map_key_list = {dataset_key, map_key};
456 QList<QVariant> map_data = {map_key,
data->type()};
461 QString DatasetTreeModel::DescribeMatrix(
const mat & matrix)
const 463 return QString::number(matrix.n_rows)
465 + QString::number(matrix.n_cols)
469 QString DatasetTreeModel::DescribeSpectra(
const mat & spectra_matrix)
const 471 return QString::number(spectra_matrix.n_cols) +
" spectra";
474 QString DatasetTreeModel::DescribeAbscissa(
const vec &abscissa)
const 476 return QString::number(abscissa.n_rows)
477 +
" points (" + QString::number(abscissa.min())
478 +
"–" + QString::number(abscissa.max()) +
")";
TreeItem * child(int row)
void AddDataset(QSharedPointer< VespucciDataset > dataset)
QStringList DatasetNames() const
DataModel::DatasetNames.
Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE
void removeChild(TreeItem *child)
TreeItem::ItemType type() const
void UpdateData(const DataModel *data_model)
QSharedPointer< AnalysisResults > GetResults(const QString &dataset_key, const QString &results_key) const
DataModel::GetResults Get the AnalysisResults object named results_key from the dataset named dataset...
void appendChild(TreeItem *child)
QSharedPointer< VespucciDataset > GetDataset(const QString &key) const
DataModel::GetDataset Get the VespucciDataset named key.
QStringList ChildNames() const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const Q_DECL_OVERRIDE
TreeItem * getItem(const QModelIndex &index) const
QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE
int columnCount(const QModelIndex &parent) const Q_DECL_OVERRIDE
DatasetTreeModel(QObject *parent)
QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE
void removeRow(const QModelIndex &index)
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) Q_DECL_OVERRIDE
int rowCount(const QModelIndex &parent) const Q_DECL_OVERRIDE
QVariant data(int column) const
void SetupModelData(const DataModel *data_model)
DatasetTreeModel::SetupModelData.
QList< TreeItem * > child_items()
QStringList AnalysisResultsNames(const QString &dataset_key) const
DataModel::AnalysisResultsNames.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const Q_DECL_OVERRIDE