Specific implementation of BaseEditor for use with a table view. More...
#include <baseeditor.h>


Public Member Functions | |
| TableBaseEditor (QWidget *parent=0) | |
| virtual bool | isDirty () const |
| SqlTableModel * | model () const |
| QTableView * | table () const |
Protected Slots | |
| virtual void | updateButtons () |
| virtual void | onNewButtonPress () |
| virtual void | onSubmitButtonPress () |
| virtual void | onUndoButtonPress () |
Specific implementation of BaseEditor for use with a table view.
| TableBaseEditor::TableBaseEditor | ( | QWidget * | parent = 0 |
) |
: BaseEditor(parent) { m_model = new SqlTableModel(this, Database::staticCon()); m_model->setEditStrategy(QSqlTableModel::OnManualSubmit); m_table = new QTableView(this); m_table->setModel(m_model); // button layout setup QVBoxLayout *buttonLayout = new QVBoxLayout(); buttonLayout->addWidget(button(BaseEditor::ButtonNew)); buttonLayout->addStretch(); buttonLayout->addWidget(button(BaseEditor::ButtonUndo)); buttonLayout->addWidget(button(BaseEditor::ButtonSubmit)); buttonLayout->addStretch(1); buttonLayout->addWidget(button(BaseEditor::ButtonClose)); // main layout setup mainLayout()->addWidget(m_table, 0, 0, 1, 1); mainLayout()->addLayout(buttonLayout, 0, 1, 2, 1); updateButtons(); }
| bool TableBaseEditor::isDirty | ( | ) | const [virtual] |
Implements BaseEditor.
Referenced by ProjectCalibrationEditor::updateButtons(), and updateButtons().
{
for (int i = 0; i < m_model->rowCount(); i++)
for (int j = 0; j < m_model->columnCount(); j++)
if (m_model->isDirty(m_model->index(i, j)))
return true;
return false;
}
| SqlTableModel * TableBaseEditor::model | ( | ) | const |
Referenced by CalibrationEditor::CalibrationEditor(), ProjectCalibrationEditor::onNewButtonPress(), ProjectCalibrationEditor::onSensorChannelSelection(), and UnitConversionEditor::UnitConversionEditor().
{
return m_model;
}
| void TableBaseEditor::onNewButtonPress | ( | ) | [protected, virtual, slot] |
Implements BaseEditor.
Reimplemented in ProjectCalibrationEditor.
{
m_model->insertRecord(-1, QSqlRecord());
Q_ASSERT(m_model->rowCount() - 1 > -1);
updateButtons();
}
| void TableBaseEditor::onSubmitButtonPress | ( | ) | [protected, virtual, slot] |
Implements BaseEditor.
{
if (!m_model->submitAll())
qWarning() << "Unable to save data: " << m_model->lastError()
<< "\nfrom query: " << m_model->query().lastQuery();
else
Database::notifyTableChange(m_model->tableName());
updateButtons();
}
| void TableBaseEditor::onUndoButtonPress | ( | ) | [protected, virtual, slot] |
Implements BaseEditor.
{
m_model->revertAll();
updateButtons();
}
| QTableView * TableBaseEditor::table | ( | ) | const |
| void TableBaseEditor::updateButtons | ( | ) | [protected, virtual, slot] |
Implements BaseEditor.
Reimplemented in ProjectCalibrationEditor.
Referenced by onNewButtonPress(), onSubmitButtonPress(), onUndoButtonPress(), TableBaseEditor(), and UnitConversionEditor::UnitConversionEditor().
{
bool editorDirty = isDirty();
button(BaseEditor::ButtonSubmit)->setEnabled(editorDirty);
button(BaseEditor::ButtonUndo)->setEnabled(editorDirty);
}
1.7.1