Commit d2b78c1d authored by Corey Wetterer-Nelson's avatar Corey Wetterer-Nelson
Browse files

Add prototype Resource table

parent d1682035
......@@ -16,6 +16,7 @@ set(client_headers
pqACE3PAnalysisPanel.h
pqACE3PAnalysisModel.h
pqACE3PNewAnalysisReaction.h
pqACE3PResourceModel.h
)
set(client_sources
......@@ -36,6 +37,7 @@ set(client_sources
pqACE3PAnalysisPanel.cxx
pqACE3PAnalysisModel.cxx
pqACE3PNewAnalysisReaction.cxx
pqACE3PResourceModel.cxx
)
set(CMAKE_AUTOMOC 1)
......
......@@ -9,6 +9,7 @@
//=========================================================================
#include "pqACE3PAnalysisPanel.h"
#include "pqACE3PAnalysisModel.h"
#include "pqACE3PResourceModel.h"
#include "pqACE3PNewAnalysisReaction.h"
#include "pqApplicationCore.h"
......@@ -101,6 +102,20 @@ pqACE3PAnalysisPanel::pqACE3PAnalysisPanel(QWidget* parent)
connect(m_analysistable, SIGNAL(doubleClicked(const QModelIndex&)),
m_analysistable, SLOT(edit(const QModelIndex&)));
m_mainlayout->addWidget(m_analysistable);
// add resource table and model
m_resourcetable = new QTableView;
m_resourcemodel = new pqACE3PResourceModel(parent);
m_resourcetable->setModel(m_resourcemodel);
m_resourcetable->setSelectionBehavior(QAbstractItemView::SelectRows);
m_resourcetable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
m_resourcetable->setEditTriggers( QAbstractItemView::DoubleClicked );
m_resourcetable->setWordWrap(true);
m_resourcetable->resizeColumnsToContents();
connect(m_resourcetable, SIGNAL(doubleClicked(const QModelIndex&)),
m_resourcetable, SLOT(edit(const QModelIndex&)));
m_mainlayout->addWidget(m_resourcetable);
}
pqACE3PAnalysisPanel::~pqACE3PAnalysisPanel()
......
......@@ -22,6 +22,7 @@ class pqSMTKWrapper;
class pqServer;
class pqACE3PAnalysisModel;
class pqACE3PResourceModel;
class QTableView;
class pqACE3PAnalysisPanel : public QDockWidget
......@@ -56,6 +57,8 @@ private:
QPushButton* m_copyanalysis;
pqACE3PAnalysisModel* m_analysismodel;
QTableView* m_analysistable;
QTableView* m_resourcetable;
pqACE3PResourceModel* m_resourcemodel;
};
......
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#include "pqACE3PResourceModel.h"
#include "pqACE3PLoader.h"
#include "pqActiveObjects.h"
#include "smtk/project/Project.h"
#include "smtk/attribute/Resource.h"
#include "smtk/attribute/StringItem.h"
#include "smtk/simulation/ace3p/utility/AttributeUtils.h"
#include <QDebug>
#include <QString>
pqACE3PResourceModel::pqACE3PResourceModel(QWidget* parent) :
m_project(nullptr)
{
// hook up a project loader to populate the analysis menu with
auto loader = pqACE3PLoader::instance();
QObject::connect(
loader, &pqACE3PLoader::projectOpened,
this, &pqACE3PResourceModel::populateResources
);
// auto activeObjecs = &pqActiveObjects::instance();
// QObject::connect(
// activeObjecs, &pqActiveObjects::dataUpdated,
// this, &pqACE3PResourceModel::updateResources);
}
QVariant pqACE3PResourceModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Horizontal && section < m_nCols)
return m_headers[section];
else
return QStringLiteral("%1").arg(section);
}
int pqACE3PResourceModel::rowCount(const QModelIndex &parent) const
{
if(parent.isValid())
{
return 0;
}
return m_nRows;
}
int pqACE3PResourceModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return m_nCols;
}
QVariant pqACE3PResourceModel::data(const QModelIndex &index, int role) const
{
// default return value
QVariant ret = QVariant();
const int row = index.row();
const int col = index.column();
// check if we are on an analysis
if(row >= m_resources.size())
{
return ret;
}
// get the data out of the Attribute Resource
if(role == Qt::DisplayRole || role == Qt::EditRole)
{
switch(col)
{
case 0: // resource type
ret = QVariant(tr(m_resources[row]->typeName().c_str()));
break;
case 1: // resource name
ret = QVariant(tr(m_resources[row]->name().c_str()));
break;
case 2: // description
ret = QVariant(tr(m_descriptions[row].c_str()));
break;
case 3: // uuid
ret = QVariant(tr(m_resources[row]->id().toString().c_str()));
break;
}
}
if(role == Qt::TextAlignmentRole)
{
ret = QVariant(m_textAlignmentRoles[col]);
}
return ret;
}
bool pqACE3PResourceModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
const int row = index.row();
const int col = index.column();
if(role == Qt::EditRole)
{
std::string str = value.toString().toStdString();
if(col == 2)
{
m_descriptions[row] = str;
emit dataChanged(index, index);
return true;
}
if(col == 0)
{
m_resources[row]->setName(str);
emit dataChanged(index, index);
return true;
}
}
return false;
}
Qt::ItemFlags pqACE3PResourceModel::flags(const QModelIndex & index) const
{
const int col = index.column();
Qt::ItemFlags defaultFlags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
if(col == 0 || col == 2)
{
defaultFlags |= Qt::ItemIsEditable;
}
return defaultFlags;
}
////////////////////////////////////////////////////////////////////////////////
void pqACE3PResourceModel::populateResources(smtk::project::ProjectPtr project)
{
if(!m_project)
{
m_project = project;
}
updateResources(nullptr); // show all resources when project is opened
}
void pqACE3PResourceModel::updateResources(smtk::attribute::ResourcePtr att)
{
auto resources = m_project->resources().find<smtk::resource::Resource>();
m_resources.resize(resources.size());
m_resources.assign(resources.begin(), resources.end());
m_descriptions.resize(resources.size(), m_defaultDescp);
int nRowsOld = m_nRows;
m_nRows = m_resources.size();
if(m_nRows != nRowsOld)
{
QModelIndex topLeft = this->createIndex(0,0);
emit beginInsertRows(topLeft, nRowsOld, m_nRows-1);
emit endInsertRows();
emit layoutAboutToBeChanged();
emit layoutChanged();
}
}
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#ifndef __pqACE3PResourceModel_h
#define __pqACE3PResourceModel_h
// Qt includes
#include <QAbstractTableModel>
// local includes
#include "smtk/project/Project.h"
class QStringList;
class pqACE3PResourceModel : public QAbstractTableModel
{
Q_OBJECT
using Superclass = QAbstractTableModel;
public:
pqACE3PResourceModel(QWidget* parent);
virtual ~pqACE3PResourceModel() = default;
// reimplemented QtAbstractTableModel member functions
int rowCount(const QModelIndex &parent = QModelIndex())const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
Qt::ItemFlags flags(const QModelIndex & index) const override;
signals:
public slots:
void populateResources(const smtk::project::ProjectPtr project);
void updateResources(smtk::attribute::ResourcePtr att = nullptr);
protected:
private:
// column headers on the table
const QStringList m_headers = {"Type", "Name", "Description", "UUID"};
const std::string m_defaultDescp = "Write your description of this resource.";
const int m_textAlignmentRoles[4] = {
Qt::AlignCenter,
Qt::AlignCenter,
Qt::AlignVCenter | Qt::AlignJustify,
Qt::AlignCenter
};
// number of columns in the table
const int m_nCols = 4;
// number of rows in the table
int m_nRows = 0;
// @brief list of analyses tracked by model
std::vector<smtk::resource::ResourcePtr> m_resources;
// @brief placeholder text description strings
// @note (CURRENTLY VOLITILE, TO DO: serialize into Attribute resource)
std::vector<std::string> m_descriptions;
// @brief pointer to the current project
smtk::project::ProjectPtr m_project;
};
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment