#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
){
ui->setupUi(this);
query->prepare("select p.shareid, p.pricedate, p.valuecol, p.totalvalue, s.sharename from pricedata p inner join shareid s on p.shareid = s.shareid"
"where p.shareid = :share");
populateGroupBox();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::updatePriceData(int idx)
{
if(record.isEmpty())
{
qDebug() << "Error! Record is empty";
return;
}
QVariant shareidx
= record.
value("shareid");
query->bindValue(":share", shareidx.toInt());
qDebug() << query->lastQuery();
priceQueryModel->setQuery(*query);
if(priceQueryModel->lastError().isValid())
qDebug() << priceQueryModel->lastError();
ui->tableView->setModel(priceQueryModel);
priceQueryModel->removeColumn(0);
priceQueryModel
->setHeaderData
(0, Qt
::Horizontal,
QObject::tr("Closing Date"));
priceQueryModel
->setHeaderData
(1, Qt
::Horizontal,
QObject::tr("Share Price"));
priceQueryModel
->setHeaderData
(2, Qt
::Horizontal,
QObject::tr("Total Value"));
priceQueryModel
->setHeaderData
(3, Qt
::Horizontal,
QObject::tr("Company"));
}
void MainWindow::populateGroupBox(void)
{
comboQueryModel->setQuery("select sharename, shareid from shareid");
ui->comboBox->setModel(comboQueryModel);
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindowClass)
{
ui->setupUi(this);
connect(ui->comboBox, SIGNAL(itemChanged(QModelIndex)), this, SLOT(showPriceData(QModelIndex)));
priceQueryModel = new QSqlQueryModel;
query = new QSqlQuery;
query->prepare("select p.shareid, p.pricedate, p.valuecol, p.totalvalue, s.sharename from pricedata p inner join shareid s on p.shareid = s.shareid"
"where p.shareid = :share");
populateGroupBox();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::updatePriceData(int idx)
{
QSqlRecord record = comboQueryModel->record(idx);
if(record.isEmpty())
{
qDebug() << "Error! Record is empty";
return;
}
QVariant shareidx = record.value("shareid");
query->bindValue(":share", shareidx.toInt());
qDebug() << query->lastQuery();
priceQueryModel->setQuery(*query);
if(priceQueryModel->lastError().isValid())
qDebug() << priceQueryModel->lastError();
ui->tableView->setModel(priceQueryModel);
priceQueryModel->removeColumn(0);
priceQueryModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Closing Date"));
priceQueryModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Share Price"));
priceQueryModel->setHeaderData(2, Qt::Horizontal, QObject::tr("Total Value"));
priceQueryModel->setHeaderData(3, Qt::Horizontal, QObject::tr("Company"));
}
void MainWindow::populateGroupBox(void)
{
comboQueryModel = new QSqlQueryModel;
comboQueryModel->setQuery("select sharename, shareid from shareid");
ui->comboBox->setModel(comboQueryModel);
}
To copy to clipboard, switch view to plain text mode
Bookmarks