#include <QtGui>
#include "datelistdialog.h"
#include "abitem.h"
#include <sstream>
#include <iostream>
using namespace std;
DateListDialog::DateListDialog()
{
labels << tr("Date") << tr("Food") << tr("Total Protein") << tr("Total Carb") << tr("Total Fat");
treeWidget->setColumnCount(5);
treeWidget->setHeaderLabels(labels);
mainLayout->addWidget(treeWidget);
setLayout(mainLayout);
for(int i = 0; i < 3; i++){
string filename = "/";
string type [] = {"date","food","totalProtein","totalCarb","totalFat"};
string number;
stringstream convert;
filename.append(type[i]);
convert << i;
number = convert.str();
filename.append(".txt");
input.setCodec("UTF-8");
while(!input.atEnd()){
if(filename == "/date.txt"){
dates << input.readLine();
} else if(filename == "/food.txt"){
foods << input.readLine();
} else if(filename == "/totalProtein.txt"){
totalProteins << input.readLine();
} else if(filename == "/totalCarb.txt"){
totalCarbs << in.readLine();
in.readLine();
} else if(filename == "/totalFat.txt"){
totalFats << in.readLine();
in.readLine();
}
}
}
}
for (int i = 0; i < 5; ++i) {
//item->setText(0,"HELLO");
item->setText(0, dates[i]);
item->setText(1, foods[i]);
item->setText(2, totalProteins[i]);
item->setText(3, totalCarbs[i]);
item->setText(4, totalFats[i]);
treeWidget->addTopLevelItem(item);
}
}
#include <QtGui>
#include "datelistdialog.h"
#include "abitem.h"
#include <sstream>
#include <iostream>
using namespace std;
DateListDialog::DateListDialog()
{
QStringList foods;
QStringList dates;
QStringList totalProteins;
QStringList totalFats;
QStringList totalCarbs;
QStringList labels;
labels << tr("Date") << tr("Food") << tr("Total Protein") << tr("Total Carb") << tr("Total Fat");
treeWidget = new QTreeWidget;
treeWidget->setColumnCount(5);
treeWidget->setHeaderLabels(labels);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(treeWidget);
setLayout(mainLayout);
for(int i = 0; i < 3; i++){
string filename = "/";
string type [] = {"date","food","totalProtein","totalCarb","totalFat"};
string number;
stringstream convert;
filename.append(type[i]);
convert << i;
number = convert.str();
filename.append(".txt");
QString filename2 = QString::fromStdString(filename);
QFile i(QDir::homePath() + filename2);
if (i.open(QIODevice::ReadOnly)) {
QTextStream input(&i);
input.setCodec("UTF-8");
while(!input.atEnd()){
if(filename == "/date.txt"){
dates << input.readLine();
} else if(filename == "/food.txt"){
foods << input.readLine();
} else if(filename == "/totalProtein.txt"){
totalProteins << input.readLine();
} else if(filename == "/totalCarb.txt"){
totalCarbs << in.readLine();
in.readLine();
} else if(filename == "/totalFat.txt"){
totalFats << in.readLine();
in.readLine();
}
}
}
}
for (int i = 0; i < 5; ++i) {
QTreeWidgetItem* item = new QTreeWidgetItem;
//item->setText(0,"HELLO");
item->setText(0, dates[i]);
item->setText(1, foods[i]);
item->setText(2, totalProteins[i]);
item->setText(3, totalCarbs[i]);
item->setText(4, totalFats[i]);
treeWidget->addTopLevelItem(item);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks