diff --git a/daily.h b/daily.h index bdfdc3b5..b750bec5 100644 --- a/daily.h +++ b/daily.h @@ -39,7 +39,7 @@ public: ~Daily(); void ReloadGraphs(); void ResetGraphLayout(); - gGraphView *SharedWidget() { return GraphView; } + gGraphView *graphView() { return GraphView; } void RedrawGraphs(); void LoadDate(QDate date); QDate getDate() { return previous_date; } diff --git a/daily.ui b/daily.ui index 338b8aaa..40967469 100644 --- a/daily.ui +++ b/daily.ui @@ -324,6 +324,9 @@ + + 4 + diff --git a/mainwindow.cpp b/mainwindow.cpp index e844fcfa..7d8a69f7 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -199,10 +199,10 @@ void MainWindow::Startup() daily=new Daily(ui->tabWidget,NULL,this); ui->tabWidget->insertTab(1,daily,tr("Daily")); - overview=new Overview(ui->tabWidget,daily->SharedWidget()); + overview=new Overview(ui->tabWidget,daily->graphView()); ui->tabWidget->insertTab(2,overview,tr("Overview")); if (PROFILE["EnableOximetry"].toBool()) { - oximetry=new Oximetry(ui->tabWidget,daily->SharedWidget()); + oximetry=new Oximetry(ui->tabWidget,daily->graphView()); ui->tabWidget->insertTab(3,oximetry,tr("Oximetry")); } if (daily) daily->ReloadGraphs(); @@ -467,7 +467,7 @@ void MainWindow::on_oximetryButton_clicked() if (QMessageBox::question(this,"Question","Do you have a CMS50[x] Oximeter?\nOne is required to use this section.\nNote: This section is not fully completed yet.",QMessageBox::Yes,QMessageBox::No)==QMessageBox::No) return; PROFILE["EnableOximetry"]=true; } - oximetry=new Oximetry(ui->tabWidget,daily->SharedWidget()); + oximetry=new Oximetry(ui->tabWidget,daily->graphView()); ui->tabWidget->insertTab(3,oximetry,tr("Oximetry")); first=true; } @@ -599,3 +599,4 @@ void MainWindow::on_action_Frequently_Asked_Questions_triggered() ui->webView->load(QUrl("http://sourceforge.net/apps/mediawiki/sleepyhead/index.php?title=Frequently_Asked_Questions")); ui->tabWidget->setCurrentIndex(0); } + diff --git a/overview.h b/overview.h index 7a03c966..32a72190 100644 --- a/overview.h +++ b/overview.h @@ -29,6 +29,7 @@ public: explicit Overview(QWidget *parent, gGraphView *shared=NULL); ~Overview(); + gGraphView *graphView() { return GraphView; } void ReloadGraphs(); void ResetGraphLayout(); void RedrawGraphs(); diff --git a/oximetry.h b/oximetry.h index da694638..57ddcc4a 100644 --- a/oximetry.h +++ b/oximetry.h @@ -146,6 +146,8 @@ public: void RedrawGraphs(); + gGraphView *graphView() { return GraphView; } + private slots: void on_RefreshPortsButton_clicked(); void on_RunButton_toggled(bool checked); diff --git a/preferencesdialog.cpp b/preferencesdialog.cpp index 04d38531..bdc1bb7d 100644 --- a/preferencesdialog.cpp +++ b/preferencesdialog.cpp @@ -7,12 +7,17 @@ #include #include #include "preferencesdialog.h" + + +#include +#include #include "ui_preferencesdialog.h" #include "SleepLib/machine_common.h" extern QFont * defaultfont; extern QFont * mediumfont; extern QFont * bigfont; +extern MainWindow * mainwin; PreferencesDialog::PreferencesDialog(QWidget *parent,Profile * _profile) : QDialog(parent), @@ -40,7 +45,7 @@ PreferencesDialog::PreferencesDialog(QWidget *parent,Profile * _profile) : } importModel=new QStringListModel(importLocations,this); ui->importListWidget->setModel(importModel); - ui->tabWidget->removeTab(3); + //ui->tabWidget->removeTab(3); Q_ASSERT(profile!=NULL); ui->tabWidget->setCurrentIndex(0); @@ -158,28 +163,24 @@ PreferencesDialog::PreferencesDialog(QWidget *parent,Profile * _profile) : shortformat.replace("yy","yyyy"); }*/ - QTreeWidget *tree=ui->graphTree; - tree->clear(); - tree->setColumnCount(1); // 1 visible common.. (1 hidden) + graphFilterModel=new MySortFilterProxyModel(this); + graphModel=new QStandardItemModel(this); + graphFilterModel->setSourceModel(graphModel); + graphFilterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); + graphFilterModel->setFilterKeyColumn(0); + ui->graphView->setModel(graphFilterModel); - QTreeWidgetItem *daily=new QTreeWidgetItem((QTreeWidget *)0,QStringList("Daily Graphs")); - QTreeWidgetItem *overview=new QTreeWidgetItem((QTreeWidget *)0,QStringList("Overview Graphs")); - tree->insertTopLevelItem(0,daily); - tree->insertTopLevelItem(0,overview); - QTreeWidgetItem *it=new QTreeWidgetItem(daily,QStringList("Event Flags"));//,QTreeWidgetItem::UserType); - it->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsSelectable|Qt::ItemIsEnabled); - it->setCheckState(0,Qt::Checked); - daily->addChild(it); - //QTreeWidgetItem *root=NULL;//new QTreeWidgetItem((QTreeWidget *)0,QStringList("Stuff")); - //=new QTreeWidgetItem(root,l); - //ui->graphTree->setModel( - tree->sortByColumn(0,Qt::AscendingOrder); + + + resetGraphModel(); +// tree->sortByColumn(0,Qt::AscendingOrder); } PreferencesDialog::~PreferencesDialog() { + disconnect(graphModel,SIGNAL(itemChanged(QStandardItem*)),this,SLOT(on_graphModel_changed(QStandardItem*))); delete ui; } @@ -402,3 +403,227 @@ void PreferencesDialog::on_removeImportLocation_clicked() importLocations.removeAll(dir); } } + + +void PreferencesDialog::on_graphView_activated(const QModelIndex &index) +{ + QString a=index.data().toString(); + qDebug() << "Could do something here with" << a; +} + +void PreferencesDialog::on_graphFilter_textChanged(const QString &arg1) +{ + graphFilterModel->setFilterFixedString(arg1); +} + + +MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent) + :QSortFilterProxyModel(parent) +{ + +} + +bool MySortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const +{ + if (source_parent == qobject_cast(sourceModel())->invisibleRootItem()->index()) { + // always accept children of rootitem, since we want to filter their children + return true; + } + + return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); +} + +void PreferencesDialog::on_graphModel_changed(QStandardItem * item) +{ + QModelIndex index=item->index(); + + gGraphView *gv=NULL; + bool ok; + + const QModelIndex & row=index.sibling(index.row(),0); + bool checked=row.data(Qt::CheckStateRole)!=0; + QString name=row.data().toString(); + + int group=row.data(Qt::UserRole+1).toInt(); + int id=row.data(Qt::UserRole+2).toInt(); + switch(group) { + case 0: gv=mainwin->getDaily()->graphView(); break; + case 1: gv=mainwin->getOverview()->graphView(); break; + case 2: gv=mainwin->getOximetry()->graphView(); break; + default: ; + } + + if (!gv) + return; + + gGraph *graph=(*gv)[id]; + if (!graph) + return; + + if (graph->visible()!=checked) { + graph->setVisible(checked); + } + + EventDataType val; + + if (index.column()==1) { + val=index.data().toDouble(&ok); + + if (!ok) { + graphModel->setData(index,QString::number(graph->rec_miny,'f',1)); + ui->graphView->update(); + } else { + if ((val < graph->rec_maxy) || (val==0)) { + graph->recMinY(val); + } else { + graphModel->setData(index,QString::number(graph->rec_miny,'f',1)); + ui->graphView->update(); + } + } + } else if (index.column()==2) { + val=index.data().toDouble(&ok); + if (!ok) { + graphModel->setData(index,QString::number(graph->rec_maxy,'f',1)); + ui->graphView->update(); + } else { + if ((val > graph->rec_miny) || (val==0)) { + graph->recMaxY(val); + } else { + graphModel->setData(index,QString::number(graph->rec_maxy,'f',1)); + ui->graphView->update(); + } + } + + } +// qDebug() << name << checked; +} + +void PreferencesDialog::resetGraphModel() +{ + + graphModel->clear(); + QStandardItem *daily=new QStandardItem("Daily Graphs"); + QStandardItem *overview=new QStandardItem("Overview Graphs"); + daily->setEditable(false); + overview->setEditable(false); + + graphModel->appendRow(daily); + graphModel->appendRow(overview); + connect(graphModel,SIGNAL(itemChanged(QStandardItem*)),this,SLOT(on_graphModel_changed(QStandardItem*))); + + ui->graphView->setAlternatingRowColors(true); + + ui->graphView->setFirstColumnSpanned(0,daily->index(),true); + graphModel->setColumnCount(3); + QStringList headers; + headers.append("Graph"); + headers.append("Min"); + headers.append("Max"); + graphModel->setHorizontalHeaderLabels(headers); + ui->graphView->setColumnWidth(0,250); + ui->graphView->setColumnWidth(1,50); + ui->graphView->setColumnWidth(2,50); + + gGraphView *gv=mainwin->getDaily()->graphView(); + for (int i=0;isize();i++) { + QList items; + QString title=(*gv)[i]->title(); + QStandardItem *it=new QStandardItem(title); + it->setCheckable(true); + it->setCheckState((*gv)[i]->visible() ? Qt::Checked : Qt::Unchecked); + it->setEditable(false); + it->setData(0,Qt::UserRole+1); + it->setData(i,Qt::UserRole+2); + items.push_back(it); + + if (title!="Event Flags") { + + it=new QStandardItem(QString::number((*gv)[i]->rec_miny,'f',1)); + it->setEditable(true); + items.push_back(it); + + it=new QStandardItem(QString::number((*gv)[i]->rec_maxy,'f',1)); + it->setEditable(true); + items.push_back(it); + } else { + it=new QStandardItem(tr("N/A")); // not applicable. + it->setEditable(false); + items.push_back(it); + items.push_back(it->clone()); + } + + daily->insertRow(i,items); + } + + gv=mainwin->getOverview()->graphView(); + for (int i=0;isize();i++) { + QList items; + QStandardItem *it=new QStandardItem((*gv)[i]->title()); + it->setCheckable(true); + it->setCheckState((*gv)[i]->visible() ? Qt::Checked : Qt::Unchecked); + it->setEditable(false); + items.push_back(it); + it->setData(1,Qt::UserRole+1); + it->setData(i,Qt::UserRole+2); + + it=new QStandardItem(QString::number((*gv)[i]->rec_miny,'f',1)); + it->setEditable(true); + items.push_back(it); + + it=new QStandardItem(QString::number((*gv)[i]->rec_maxy,'f',1)); + it->setEditable(true); + items.push_back(it); + + overview->insertRow(i,items); + } + if (mainwin->getOximetry()) { + QStandardItem *oximetry=new QStandardItem("Oximetry Graphs"); + graphModel->appendRow(oximetry); + oximetry->setEditable(false); + gv=mainwin->getOximetry()->graphView(); + for (int i=0;isize();i++) { + QList items; + QStandardItem *it=new QStandardItem((*gv)[i]->title()); + it->setCheckable(true); + it->setCheckState((*gv)[i]->visible() ? Qt::Checked : Qt::Unchecked); + it->setEditable(false); + it->setData(2,Qt::UserRole+1); + it->setData(i,Qt::UserRole+2); + items.push_back(it); + + it=new QStandardItem(QString::number((*gv)[i]->rec_miny,'f',1)); + it->setEditable(true); + items.push_back(it); + + it=new QStandardItem(QString::number((*gv)[i]->rec_maxy,'f',1)); + it->setEditable(true); + items.push_back(it); + + oximetry->insertRow(i,items); + } + } + + ui->graphView->expandAll(); +} + +void PreferencesDialog::on_resetGraphButton_clicked() +{ + if (QMessageBox::question(this,"Confirmation","Are you sure you want to reset your graph preferences to the defaults?",QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes) { + gGraphView *gv[3]; + gv[0]=mainwin->getDaily()->graphView(); + gv[1]=mainwin->getOverview()->graphView(); + gv[2]=mainwin->getOximetry()->graphView(); + for (int j=0;j<3;j++) { + if (gv[j]!=NULL) { + for (int i=0;isize();i++) { + gGraph *g=(*(gv[j]))[i]; + g->recMaxY(0); + g->recMinY(0); + g->setVisible(true); + } + } + } + resetGraphModel(); + ui->graphView->update(); + } + } diff --git a/preferencesdialog.h b/preferencesdialog.h index 16aa9f29..96623739 100644 --- a/preferencesdialog.h +++ b/preferencesdialog.h @@ -10,12 +10,25 @@ #include #include #include +#include +#include #include "SleepLib/profiles.h" namespace Ui { class PreferencesDialog; } +class MySortFilterProxyModel:public QSortFilterProxyModel +{ + Q_OBJECT +public: + MySortFilterProxyModel(QObject *parent = 0); + +protected: + bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; + +}; + class PreferencesDialog : public QDialog { Q_OBJECT @@ -39,13 +52,25 @@ private slots: void on_removeImportLocation_clicked(); + void on_graphView_activated(const QModelIndex &index); + + void on_graphFilter_textChanged(const QString &arg1); + + void on_graphModel_changed(QStandardItem * item); + + void on_resetGraphButton_clicked(); + private: + void resetGraphModel(); Ui::PreferencesDialog *ui; Profile * profile; QHash m_new_colors; QStringList importLocations; QStringListModel *importModel; + MySortFilterProxyModel *graphFilterModel; + QStandardItemModel *graphModel; }; + #endif // PREFERENCESDIALOG_H diff --git a/preferencesdialog.ui b/preferencesdialog.ui index a0b715ed..2bf23a95 100644 --- a/preferencesdialog.ui +++ b/preferencesdialog.ui @@ -493,46 +493,50 @@ p, li { white-space: pre-wrap; } 0 - - - - This page is yet another work in progress. Please ignore. - - - - - - 0 - 0 - - - Filter - - - 4 + Search - + - - - true - - - - 1 + + + + + + + 3 - + + + + + 0 + 0 + + + + &Defaults + + + + + + + Please Note: Graph visibility also depends on machine availability. + + + + @@ -1247,16 +1251,42 @@ It has no effect on single cpu machines. - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - false - + + + + 6 + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + &Cancel + + + + + + + &Ok + + + + @@ -1264,14 +1294,14 @@ It has no effect on single cpu machines. - buttonBox - accepted() + okButton + clicked() PreferencesDialog accept() - 248 - 254 + 444 + 303 157 @@ -1280,14 +1310,14 @@ It has no effect on single cpu machines. - buttonBox - rejected() + cancelButton + clicked() PreferencesDialog reject() - 316 - 260 + 154 + 303 286