void DateListDialog::updateTreeWidget(){
for (int i = 0; i < dates.size(); ++i) {
for(int j = 0; j<24; j++){
//timeChild[j]->setFlags(Qt::NoItemFlags);
}
itemParent->setText(1, foods[i]);
for(int k = 0; k<7; k++){
itemParent->setText(k+2, totalValues[k+(7*i)]);
//cout << totalValues[k+(7*i)].toStdString() << endl;
}
itemParent->setText(0, dates[i]);
for(int j = 0; j<24; j++){
timeChild[j]->setText(1, times[j+(24*i)]);
}
for(int i = 0; i<24; i++){
if(i == 0){
time = "12 AM";
} else if(i > 0 && i < 12){
} else if(i == 12){
time = "12 PM";
} else if(i > 12){
}
timeChild[i]->setText(0, time);
}
treeWidget->addTopLevelItem(itemParent);
}
allDates << dates;
allTimes << times;
/*for(int i = 0; i<allDates.size();i++){
for(int j = 0; j<24; j++){
if(!allTimes[j+(24*i)].contains("No Food")){
cout << allTimes[j+(24*i)].toStdString() << flush;
}
}
cout << endl;
}*/
allFoods << foods;
allValues << totalValues;
}
void DateListDialog::editDate()
{
dates.clear();
times.clear();
foods.clear();
totalValues.clear();
for(int i = 0; i<24;i++){
addedTimes[i].clear();
}
edit = true;
for(int i = 0; i<24; i++){
if(!allTimes[i].contains("No Food")){
addedTimes[i] = allTimes[i];
}
for(int i = 0; i<7; i++){
totalValue[i] = allValues[i].toInt();
}
}
posInt = treeWidget->indexOfTopLevelItem(treeWidget->currentItem());
ListWidgetDialog w;
w.exec();
if(changed == true){
for(int i = 23; i>=0; i--){
allTimes.removeAt(i+(24*posInt));
}
allDates.removeAt(posInt);
allFoods.removeAt(posInt);
for(int i = 6; i>=0; i--){
allValues.removeAt(i+(7*posInt));
}
// cout << "Changed = true" << endl;
treeWidget->takeTopLevelItem(posInt);
updateTreeWidget();
}
edit = false;
/* for(int i = 0; i<allTimes.size(); i++){
if(!allTimes[i].contains("No Food")){
cout << allTimes[i].toStdString() << endl;
}
}*/
}
void DateListDialog::treeWidget_clicked(){
//cout << "HELLO" << endl;
}
void DateListDialog::deleteDate()
{
posInt = treeWidget->indexOfTopLevelItem(treeWidget->currentItem());
if(posInt >= 0){
treeWidget->takeTopLevelItem(posInt);
for(int i = 23; i>=0; i--){
allTimes.removeAt(i+(24*posInt));
//cout << i+(24*posInt) << endl;
}
//cout << "SELECTED POSITION IS: " << posInt << endl;
allDates.removeAt(posInt);
allFoods.removeAt(posInt);
for(int i = 6; i>=0; i--){
allValues.removeAt(i+(7*posInt));
}
QFile file(QDir::homePath() + "/datedata.txt");
out.setCodec("UTF-8");
for(int i = 0; i<allDates.size(); i++){
out << allDates[i] << endl;
for(int j = 0; j<24; j++){
out << allTimes[j+(24*i)] << endl;
}
out << allFoods[i] << endl;
for(int k = 0; k<7; k++){
allValues[k+(7*i)];
}
out << endl;
}
}
file.close();
}
//cout << "SIZE AFTER WRITE: " << allDates.size() << endl;
}
Bookmarks