Commit 6960612d authored by David Thompson's avatar David Thompson

Hackish... but editing with the new delegate.

parent 13553540
......@@ -4,6 +4,7 @@ set(QAttrLibSrcs
qtAttribute.cxx
qtBaseView.cxx
qtEntityItemDelegate.cxx
qtEntityItemEditor.cxx
qtEntityItemModel.cxx
qtGroupView.cxx
qtRootView.cxx
......@@ -35,6 +36,7 @@ set(QAttrLibHeaders
qtAttribute.h
qtBaseView.h
qtEntityItemDelegate.h
qtEntityItemEditor.h
qtEntityItemModel.h
qtGroupView.h
qtRootView.h
......
#include "smtk/Qt/qtEntityItemDelegate.h"
#include "smtk/Qt/qtEntityItemModel.h"
#include "smtk/Qt/qtEntityItemEditor.h"
#include <QApplication>
#include <QPainter>
......@@ -94,13 +95,24 @@ QWidget* QEntityItemDelegate::createEditor(
const QStyleOptionViewItem& option,
const QModelIndex &index) const
{
return NULL;
smtk::model::QEntityItemEditor* editor = new QEntityItemEditor(parent);
QObject::connect(
editor, SIGNAL(editingFinished()),
this, SLOT(commitAndCloseEditor()));
return editor;
}
void QEntityItemDelegate::setEditorData(
QWidget* editor,
const QModelIndex& index) const
{
smtk::model::QEntityItemEditor* entityEditor =
qobject_cast<smtk::model::QEntityItemEditor*>(editor);
if (entityEditor)
{
entityEditor->setTitle(index.data(QEntityItemModel::TitleTextRole).toString());
// TODO: editor should also allow adjusting entity type?
}
}
void QEntityItemDelegate::setModelData(
......@@ -108,10 +120,22 @@ void QEntityItemDelegate::setModelData(
QAbstractItemModel* model,
const QModelIndex &index) const
{
smtk::model::QEntityItemEditor* entityEditor =
qobject_cast<smtk::model::QEntityItemEditor*>(editor);
if (entityEditor)
{
// TODO: editor should also allow adjusting entity type?
model->setData(
index, entityEditor->title(), QEntityItemModel::TitleTextRole);
}
}
void QEntityItemDelegate::commitAndCloseEditor()
{
smtk::model::QEntityItemEditor* entityEditor =
qobject_cast<smtk::model::QEntityItemEditor*>(sender());
emit commitData(entityEditor);
emit closeEditor(entityEditor);
}
} // namespace model
......
#include "smtk/Qt/qtEntityItemEditor.h"
#include <QtGui/QLineEdit>
#include <QtGui/QHBoxLayout>
namespace smtk {
namespace model {
QEntityItemEditor::QEntityItemEditor(QWidget* parent)
: QWidget(parent)
{
this->m_title = new QLineEdit(this);
new QHBoxLayout(this);
QObject::connect(
this->m_title, SIGNAL(editingFinished()),
this, SIGNAL(editingFinished()));
}
QEntityItemEditor::~QEntityItemEditor()
{
}
/*
QSize QEntityItemEditor::sizeHint() const
{
return this->m_title->sizeHint();
}
*/
QString QEntityItemEditor::title() const
{
return this->m_title->text();
}
void QEntityItemEditor::setTitle(const QString& text)
{
this->m_title->setText(text);
}
} // namespace model
} // namespace smtk
#ifndef __smtk_qt_QEntityItemEditor_h
#define __smtk_qt_QEntityItemEditor_h
#include "smtk/QtSMTKExports.h"
#include <QtGui/QWidget>
class QLineEdit;
namespace smtk {
namespace model {
class QEntityItemEditor : public QWidget
{
Q_OBJECT
public:
QEntityItemEditor(QWidget* parent = 0);
virtual ~QEntityItemEditor();
//QSize sizeHint() const;
QString title() const;
void setTitle(const QString& text);
signals:
void editingFinished();
protected:
QLineEdit* m_title;
};
} // namespace model
} // namespace smtk
#endif // __smtk_qt_QEntityItemEditor_h
......@@ -304,43 +304,61 @@ bool QEntityItemModel::removeRows(int position, int rows, const QModelIndex& par
bool QEntityItemModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
bool didChange = false;
if(index.isValid() && role == Qt::EditRole)
if(index.isValid())
{
smtk::model::Entity* entity;
int row = index.row();
int col = index.column();
switch (col)
if (role == TitleTextRole)
{
case 0:
entity = this->m_storage->findEntity(this->m_subset[row]);
if (entity)
std::string sval = value.value<QString>().toStdString();
if (sval.size())
{
didChange = entity->setEntityFlags(value.value<int>());
this->m_storage->setStringProperty(
this->m_subset[row], "name", sval);
didChange = true;
}
break;
case 1:
// FIXME: No way to change dimension yet.
break;
case 2:
else
{
std::string sval = value.value<QString>().toStdString();
if (sval.size())
didChange = this->m_storage->removeStringProperty(
this->m_subset[row], "name");
}
}
else if (role == Qt::EditRole)
{
switch (col)
{
case 0:
entity = this->m_storage->findEntity(this->m_subset[row]);
if (entity)
{
this->m_storage->setStringProperty(
this->m_subset[row], "name", sval);
didChange = true;
didChange = entity->setEntityFlags(value.value<int>());
}
else
break;
case 1:
// FIXME: No way to change dimension yet.
break;
case 2:
{
didChange = this->m_storage->removeStringProperty(
this->m_subset[row], "name");
std::string sval = value.value<QString>().toStdString();
if (sval.size())
{
this->m_storage->setStringProperty(
this->m_subset[row], "name", sval);
didChange = true;
}
else
{
didChange = this->m_storage->removeStringProperty(
this->m_subset[row], "name");
}
}
break;
}
if (didChange)
{
emit(dataChanged(index, index));
}
break;
}
if (didChange)
{
emit(dataChanged(index, index));
}
}
return didChange;
......@@ -356,7 +374,6 @@ void QEntityItemModel::sort(int column, Qt::SortOrder order)
this->sortDataWithContainer(sorter, order);
}
break;
case 0:
case 1:
{
smtk::model::SortByEntityFlags comparator(this->m_storage);
......@@ -365,6 +382,7 @@ void QEntityItemModel::sort(int column, Qt::SortOrder order)
this->sortDataWithContainer(sorter, order);
}
break;
case 0:
case 2:
{
smtk::model::SortByEntityProperty<
......
Markdown is supported
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