class MainWindow
: public QMainWindow,
private Ui
::MainWindow{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private:
void setupModel();
void setupChart();
void readFile();
void updateCarTotals
(const QString &,
int FORDS
=0,
int CHEVYS
=0,
int GMCS
=0);
QChart *m_chart;
int totalFord,totalChevy,totalGMC;
};
class MainWindow : public QMainWindow, private Ui::MainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
void setupModel();
void setupChart();
void readFile();
void updateCarTotals(const QString &, int FORDS=0, int CHEVYS=0,int GMCS=0);
QChart *m_chart;
QStandardItemModel *overallCarCountModel;
int totalFord,totalChevy,totalGMC;
};
To copy to clipboard, switch view to plain text mode
{
setupModel()
setupChart()
}
void MainWindow::setupModel()
{
overallCarCountModel->insertRows(0,2);
overallCarCountModel->insertColumns(0,3);
overallCarCountModel->setHeaderData(0,Qt::Horizontal,"Ford");
overallCarCountModel->setHeaderData(1,Qt::Horizontal,"Chevy");
overallCarCountModel->setHeaderData(2,Qt::Horizontal,"GMC");
}
void MainWindow::setupChart()
{
m_chart = new QChart;
m_chart->setTitle("Total Cars");
QPieSeries *series = new QPieSeries();
QHPieModelMapper *pcMapper = new QHPieModelMapper(this);
series->setPieSize(0.7); //I know this is the default, just trying whatever to get it working
pcMapper->setValuesRow(0);
pcMapper->setSeries(series);
pcMapper->setModel(overallCarCountModel );
m_chart->addSeries(series);
QChartView *overallCarsPieChartView = new QChartView(m_chart);
overallCarsPieChartView
->setRenderHint
(QPainter::Antialiasing);
overallCarsPieChartView ->setMinimumSize(200,200);
chartLayout->addWidget( overallCarsPieChartView );
overallCarsGroupBox->setLayout(chartLayout);
void MainWindow::readFile()
{
// ...
//code to open file, parse words and tally up cars by site name
// ...
updateCarTotals(siteName, fords, chevys, gmcs)
}
void MainWindow
::updateCarTotals(const QString &site,
int fords,
int chevys,
int gmcs
) {
QString fordCount,chevyCount,gmcCount;
fordCount.setNum(fords);
chevyCount.setNum(chevys);
gmcCount.setNum(gmcs);
totalFord+=fords;
totalChevy+=chevys;
totalGMC+=gmcs;
overallCarCountModel
->setData
(overallCarCountModel
->index
(0,
0),
QVariant(totalFord
));
overallCarCountModel
->setData
(overallCarCountModel
->index
(0,
1),
QVariant(totalChevy
));
overallCarCountModel
->setData
(overallCarCountModel
->index
(0,
2),
QVariant(totalGMC
));
}
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
setupModel()
setupChart()
}
void MainWindow::setupModel()
{
overallCarCountModel = new QStandardItemModel(this);
overallCarCountModel->insertRows(0,2);
overallCarCountModel->insertColumns(0,3);
overallCarCountModel->setHeaderData(0,Qt::Horizontal,"Ford");
overallCarCountModel->setHeaderData(1,Qt::Horizontal,"Chevy");
overallCarCountModel->setHeaderData(2,Qt::Horizontal,"GMC");
}
void MainWindow::setupChart()
{
QHBoxLayout* chartLayout = new QHBoxLayout;
m_chart = new QChart;
m_chart->setTitle("Total Cars");
QPieSeries *series = new QPieSeries();
QHPieModelMapper *pcMapper = new QHPieModelMapper(this);
series->setPieSize(0.7); //I know this is the default, just trying whatever to get it working
pcMapper->setValuesRow(0);
pcMapper->setSeries(series);
pcMapper->setModel(overallCarCountModel );
m_chart->addSeries(series);
QChartView *overallCarsPieChartView = new QChartView(m_chart);
overallCarsPieChartView ->setRenderHint(QPainter::Antialiasing);
overallCarsPieChartView ->setMinimumSize(200,200);
chartLayout->addWidget( overallCarsPieChartView );
overallCarsGroupBox->setLayout(chartLayout);
void MainWindow::readFile()
{
// ...
//code to open file, parse words and tally up cars by site name
// ...
updateCarTotals(siteName, fords, chevys, gmcs)
}
void MainWindow::updateCarTotals(const QString &site, int fords, int chevys, int gmcs)
{
QString fordCount,chevyCount,gmcCount;
fordCount.setNum(fords);
chevyCount.setNum(chevys);
gmcCount.setNum(gmcs);
totalFord+=fords;
totalChevy+=chevys;
totalGMC+=gmcs;
overallCarCountModel->setData(overallCarCountModel->index(0,0),QVariant(totalFord));
overallCarCountModel->setData(overallCarCountModel->index(0,1),QVariant(totalChevy));
overallCarCountModel->setData(overallCarCountModel->index(0,2),QVariant(totalGMC));
}
To copy to clipboard, switch view to plain text mode
Bookmarks