Why does the following code:
CBrowserWindow
::CBrowserWindow(QWidget *parent, CDatabaseFoundation
* pDatabase,
QString sTableName,
QString windowCaption
){
Q_CHECK_PTR(m_pModel); // checks for succesful creation
m_pModel->setTable(sTableName); // sets table name
m_pColumnNames
=new QStringList();
// creates new string list Q_CHECK_PTR(m_pColumnNames); // checks for succesful creation
// fetches record
m_pTableRecord
=new QSqlRecord();
// creates new record Q_CHECK_PTR(m_pTableRecord); // checks for susccesful creation
m_pTableRecord=&pDatabase->m_Database.record(sTableName); // fetches column names
QSqlRecord tempRec
=pDatabase
->m_Database.
record(sTableName
);
// fetches column names m_pTableRecord
=new QSqlRecord(tempRec
);
// read column names Q_CHECK_PTR(m_pTableRecord);
if (!m_pTableRecord->isEmpty()) {
for (m_iIndex=0; m_iIndex<m_pTableRecord->count(); m_iIndex++) {
m_pColumnNames->append(m_pTableRecord->fieldName(m_iIndex));
}
} // if
createBrowserContens(this, pDatabase, m_pColumnNames); // creates browser controls
setWindowTitle(windowCaption); // sets window title
/*
delete m_pModel; // deletes pModel;
delete m_pTableRecord; // deletes m_pTableRecord
// just to be sure
m_pModel=0;
m_pTableRecord=0;
*/
}
CBrowserWindow::CBrowserWindow(QWidget *parent, CDatabaseFoundation* pDatabase, QString sTableName, QString windowCaption)
: QDialog(parent)
{
m_pModel=new QSqlRelationalTableModel(parent); // creates new model
Q_CHECK_PTR(m_pModel); // checks for succesful creation
m_pModel->setTable(sTableName); // sets table name
m_pColumnNames=new QStringList(); // creates new string list
Q_CHECK_PTR(m_pColumnNames); // checks for succesful creation
// fetches record
m_pTableRecord=new QSqlRecord(); // creates new record
Q_CHECK_PTR(m_pTableRecord); // checks for susccesful creation
m_pTableRecord=&pDatabase->m_Database.record(sTableName); // fetches column names
QSqlRecord tempRec=pDatabase->m_Database.record(sTableName); // fetches column names
m_pTableRecord=new QSqlRecord(tempRec); // read column names
Q_CHECK_PTR(m_pTableRecord);
if (!m_pTableRecord->isEmpty()) {
for (m_iIndex=0; m_iIndex<m_pTableRecord->count(); m_iIndex++) {
m_pColumnNames->append(m_pTableRecord->fieldName(m_iIndex));
}
} // if
createBrowserContens(this, pDatabase, m_pColumnNames); // creates browser controls
setWindowTitle(windowCaption); // sets window title
/*
delete m_pModel; // deletes pModel;
delete m_pTableRecord; // deletes m_pTableRecord
// just to be sure
m_pModel=0;
m_pTableRecord=0;
*/
}
To copy to clipboard, switch view to plain text mode
Here is also createBrowserContens(..):
void CBrowserWindow
::createBrowserContens(QWidget* pParent, CDatabaseFoundation
* pDatabase,
QStringList* pColumnNames
) { Q_CHECK_PTR(m_pHorizLayout); // chechks creation of horiz layout
Q_CHECK_PTR(m_pVertLayout); // checks creation of vertical layout
Q_CHECK_PTR(m_pView); // checks creation of view
for(m_iIndex=0; m_iIndex<pColumnNames->count(); m_iIndex++) {
pDatabase->m_pModel->setHeaderData(m_iIndex, Qt::Horizontal, m_pColumnNames->at(m_iIndex)); // sets column names
qDebug() << m_iIndex << ": " << m_pColumnNames->at(m_iIndex);
//pView->showColumn(m_iIndex); // shows the selected column
}
m_pView->setModel(pDatabase->m_pModel); // sets model
Q_CHECK_PTR(m_pButtonAdd); // checks creation of pushbutton
Q_CHECK_PTR(m_pButtonChange); // checks creation of pushbutton
Q_CHECK_PTR(m_pButtonDelete); // checks creation of pushbutton
Q_CHECK_PTR(m_pButtonClose);
// leyout setup
m_pHorizLayout->addWidget(m_pButtonAdd);
m_pHorizLayout->addWidget(m_pButtonChange);
m_pHorizLayout->addWidget(m_pButtonDelete);
m_pHorizLayout->addWidget(m_pButtonClose);
m_pVertLayout->addWidget(m_pView);
m_pVertLayout->addLayout(m_pHorizLayout);
pParent->setLayout(m_pVertLayout);
// button connectors
connect(m_pButtonClose, SIGNAL(clicked()), this, SLOT(close()));
}
void CBrowserWindow::createBrowserContens(QWidget* pParent, CDatabaseFoundation* pDatabase, QStringList* pColumnNames) {
m_pHorizLayout=new QHBoxLayout();
Q_CHECK_PTR(m_pHorizLayout); // chechks creation of horiz layout
m_pVertLayout=new QVBoxLayout();
Q_CHECK_PTR(m_pVertLayout); // checks creation of vertical layout
m_pView=new QTableView(this);
Q_CHECK_PTR(m_pView); // checks creation of view
for(m_iIndex=0; m_iIndex<pColumnNames->count(); m_iIndex++) {
pDatabase->m_pModel->setHeaderData(m_iIndex, Qt::Horizontal, m_pColumnNames->at(m_iIndex)); // sets column names
qDebug() << m_iIndex << ": " << m_pColumnNames->at(m_iIndex);
//pView->showColumn(m_iIndex); // shows the selected column
}
m_pView->setModel(pDatabase->m_pModel); // sets model
m_pView->setItemDelegate(new QSqlRelationalDelegate(m_pView));
m_pButtonAdd=new QPushButton(QObject::trUtf8("Dodaj"));
Q_CHECK_PTR(m_pButtonAdd); // checks creation of pushbutton
m_pButtonChange=new QPushButton(QObject::trUtf8("Spremeni"));
Q_CHECK_PTR(m_pButtonChange); // checks creation of pushbutton
m_pButtonDelete=new QPushButton(QObject::trUtf8("Briši"));
Q_CHECK_PTR(m_pButtonDelete); // checks creation of pushbutton
m_pButtonClose=new QPushButton(QObject::trUtf8("Zapri"));
Q_CHECK_PTR(m_pButtonClose);
// leyout setup
m_pHorizLayout->addWidget(m_pButtonAdd);
m_pHorizLayout->addWidget(m_pButtonChange);
m_pHorizLayout->addWidget(m_pButtonDelete);
m_pHorizLayout->addWidget(m_pButtonClose);
m_pVertLayout->addWidget(m_pView);
m_pVertLayout->addLayout(m_pHorizLayout);
pParent->setLayout(m_pVertLayout);
// button connectors
connect(m_pButtonClose, SIGNAL(clicked()), this, SLOT(close()));
}
To copy to clipboard, switch view to plain text mode
does NOT display data fields in window??
Bookmarks