Public Member Functions | Protected Slots

TableBaseEditor Class Reference

Specific implementation of BaseEditor for use with a table view. More...

#include <baseeditor.h>

Inheritance diagram for TableBaseEditor:
Inheritance graph
[legend]
Collaboration diagram for TableBaseEditor:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 TableBaseEditor (QWidget *parent=0)
virtual bool isDirty () const
SqlTableModelmodel () const
QTableViewtable () const

Protected Slots

virtual void updateButtons ()
virtual void onNewButtonPress ()
virtual void onSubmitButtonPress ()
virtual void onUndoButtonPress ()

Detailed Description

Specific implementation of BaseEditor for use with a table view.


Constructor & Destructor Documentation

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();
}


Member Function Documentation

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
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);
}


The documentation for this class was generated from the following files: