mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-15 05:32:21 +00:00
Mainain Events in LTM Sidebar
Add the ability to create and maintain events in the LTMSidebar. This is a follow up to adding support for Events in seasons.xml. The last step is now to add support for annotating charts to show the events for the date range selected and possibly for the seasons within that date range.
This commit is contained in:
@@ -63,6 +63,22 @@ LTMSidebar::LTMSidebar(MainWindow *parent, const QDir &home) : QWidget(parent),
|
||||
dateRangeTree->setAttribute(Qt::WA_MacShowFocusRect, 0);
|
||||
#endif
|
||||
|
||||
eventTree = new QTreeWidget;
|
||||
allEvents = new QTreeWidgetItem(eventTree, ROOT_TYPE);
|
||||
allEvents->setText(0, tr("Events"));
|
||||
eventTree->setFrameStyle(QFrame::NoFrame);
|
||||
eventTree->setColumnCount(2);
|
||||
eventTree->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
eventTree->header()->hide();
|
||||
eventTree->setIndentation(5);
|
||||
eventTree->expandItem(allEvents);
|
||||
eventTree->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
eventTree->horizontalScrollBar()->setDisabled(true);
|
||||
eventTree->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
#ifdef Q_OS_MAC
|
||||
eventTree->setAttribute(Qt::WA_MacShowFocusRect, 0);
|
||||
#endif
|
||||
|
||||
seasons = parent->seasons;
|
||||
resetSeasons(); // reset the season list
|
||||
|
||||
@@ -74,6 +90,7 @@ LTMSidebar::LTMSidebar(MainWindow *parent, const QDir &home) : QWidget(parent),
|
||||
splitter->setContentsMargins(0,0,0,0);
|
||||
splitter->setOrientation(Qt::Vertical);
|
||||
splitter->addWidget(dateRangeTree);
|
||||
splitter->addWidget(eventTree);
|
||||
connect(splitter,SIGNAL(splitterMoved(int,int)), this, SLOT(splitterMoved(int,int)));
|
||||
|
||||
summary = new QWebView(this);
|
||||
@@ -105,7 +122,7 @@ LTMSidebar::LTMSidebar(MainWindow *parent, const QDir &home) : QWidget(parent),
|
||||
connect(dateRangeTree,SIGNAL(itemSelectionChanged()), this, SLOT(dateRangeTreeWidgetSelectionChanged()));
|
||||
connect(dateRangeTree,SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(dateRangePopup(const QPoint &)));
|
||||
connect(dateRangeTree,SIGNAL(itemChanged(QTreeWidgetItem *,int)), this, SLOT(dateRangeChanged(QTreeWidgetItem*, int)));
|
||||
|
||||
connect(eventTree,SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(eventPopup(const QPoint &)));
|
||||
// GC signal
|
||||
connect(main, SIGNAL(configChanged()), this, SLOT(configChanged()));
|
||||
connect(seasons, SIGNAL(seasonsChanged()), this, SLOT(resetSeasons()));
|
||||
@@ -125,6 +142,8 @@ LTMSidebar::configChanged()
|
||||
void
|
||||
LTMSidebar::dateRangeTreeWidgetSelectionChanged()
|
||||
{
|
||||
if (active == true) return;
|
||||
|
||||
const Season *dateRange = NULL;
|
||||
|
||||
if (dateRangeTree->selectedItems().isEmpty()) dateRange = NULL;
|
||||
@@ -137,6 +156,25 @@ LTMSidebar::dateRangeTreeWidgetSelectionChanged()
|
||||
}
|
||||
}
|
||||
|
||||
if (dateRange) {
|
||||
int i;
|
||||
// clear events - we need to add for currently selected season
|
||||
for (i=allEvents->childCount(); i > 0; i--) {
|
||||
delete allEvents->takeChild(0);
|
||||
}
|
||||
|
||||
// add this seasons events
|
||||
for (i=0; i <dateRange->events.count(); i++) {
|
||||
SeasonEvent event = dateRange->events.at(i);
|
||||
QTreeWidgetItem *add = new QTreeWidgetItem(allEvents);
|
||||
add->setText(0, event.name);
|
||||
add->setText(1, event.date.toString("MMM d, yyyy"));
|
||||
}
|
||||
|
||||
// make sure they fit
|
||||
eventTree->header()->resizeSections(QHeaderView::ResizeToContents);
|
||||
}
|
||||
|
||||
// Let the view know its changed....
|
||||
if (dateRange) emit dateRangeChanged(DateRange(dateRange->start, dateRange->end, dateRange->name));
|
||||
else emit dateRangeChanged(DateRange());
|
||||
@@ -150,6 +188,8 @@ LTMSidebar::dateRangeTreeWidgetSelectionChanged()
|
||||
void
|
||||
LTMSidebar::resetSeasons()
|
||||
{
|
||||
if (active == true) return;
|
||||
|
||||
QString now;
|
||||
|
||||
// remember currebt
|
||||
@@ -210,17 +250,17 @@ LTMSidebar::dateRangePopup(QPoint pos)
|
||||
|
||||
// create context menu
|
||||
QMenu menu(dateRangeTree);
|
||||
QAction *rename = new QAction(tr("Rename range"), dateRangeTree);
|
||||
QAction *edit = new QAction(tr("Edit details"), dateRangeTree);
|
||||
QAction *del = new QAction(tr("Delete range"), dateRangeTree);
|
||||
menu.addAction(rename);
|
||||
QAction *event = new QAction(tr("Add Event"), dateRangeTree);
|
||||
menu.addAction(edit);
|
||||
menu.addAction(del);
|
||||
menu.addAction(event);
|
||||
|
||||
// connect menu to functions
|
||||
connect(rename, SIGNAL(triggered(void)), this, SLOT(renameRange(void)));
|
||||
connect(edit, SIGNAL(triggered(void)), this, SLOT(editRange(void)));
|
||||
connect(del, SIGNAL(triggered(void)), this, SLOT(deleteRange(void)));
|
||||
connect(event, SIGNAL(triggered(void)), this, SLOT(addEvent(void)));
|
||||
|
||||
// execute the menu
|
||||
menu.exec(dateRangeTree->mapToGlobal(pos));
|
||||
@@ -228,7 +268,45 @@ LTMSidebar::dateRangePopup(QPoint pos)
|
||||
}
|
||||
|
||||
void
|
||||
LTMSidebar::renameRange()
|
||||
LTMSidebar::eventPopup(QPoint pos)
|
||||
{
|
||||
// no current season selected
|
||||
if (dateRangeTree->selectedItems().isEmpty()) return;
|
||||
|
||||
QTreeWidgetItem *item = eventTree->itemAt(pos);
|
||||
|
||||
// save context - which season and event are we working with?
|
||||
QTreeWidgetItem *which = dateRangeTree->selectedItems().first();
|
||||
if (which && which != allDateRanges) {
|
||||
activeDateRange = which;
|
||||
activeEvent = item;
|
||||
} else return;
|
||||
|
||||
// OK - we are working with a specific event..
|
||||
QMenu menu(eventTree);
|
||||
if (item != NULL && item->type() != ROOT_TYPE && allEvents->indexOfChild(item) != -1) {
|
||||
|
||||
QAction *edit = new QAction(tr("Edit details"), eventTree);
|
||||
QAction *del = new QAction(tr("Delete event"), eventTree);
|
||||
menu.addAction(edit);
|
||||
menu.addAction(del);
|
||||
|
||||
// connect menu to functions
|
||||
connect(edit, SIGNAL(triggered(void)), this, SLOT(editEvent(void)));
|
||||
connect(del, SIGNAL(triggered(void)), this, SLOT(deleteEvent(void)));
|
||||
}
|
||||
|
||||
// we can always add, regardless of any event being selected...
|
||||
QAction *addEvent = new QAction(tr("Add event"), eventTree);
|
||||
menu.addAction(addEvent);
|
||||
connect(addEvent, SIGNAL(triggered(void)), this, SLOT(addEvent(void)));
|
||||
|
||||
// execute the menu
|
||||
menu.exec(eventTree->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void
|
||||
LTMSidebar::renameRange() //XXX deprecated
|
||||
{
|
||||
// go edit the name
|
||||
activeDateRange->setFlags(activeDateRange->flags() | Qt::ItemIsEditable);
|
||||
@@ -261,16 +339,18 @@ LTMSidebar::editRange()
|
||||
EditSeasonDialog dialog(main, &seasons->seasons[index]);
|
||||
|
||||
if (dialog.exec()) {
|
||||
|
||||
active = true;
|
||||
|
||||
// update name
|
||||
activeDateRange->setText(0, seasons->seasons[index].getName());
|
||||
|
||||
// save changes away
|
||||
active = true;
|
||||
seasons->writeSeasons();
|
||||
active = false;
|
||||
|
||||
// signal its changed!
|
||||
//XXX dateRangeSelected(&seasons->seasons[index]);
|
||||
//dateRangeSelected(&seasons->seasons[index]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,6 +363,75 @@ LTMSidebar::deleteRange()
|
||||
seasons->deleteSeason(index);
|
||||
}
|
||||
|
||||
void
|
||||
LTMSidebar::addEvent()
|
||||
{
|
||||
SeasonEvent myevent("", QDate());
|
||||
int seasonindex = allDateRanges->indexOfChild(activeDateRange);
|
||||
EditSeasonEventDialog dialog(main, &myevent);
|
||||
|
||||
if (dialog.exec()) {
|
||||
|
||||
active = true;
|
||||
seasons->seasons[seasonindex].events.append(myevent);
|
||||
|
||||
QTreeWidgetItem *add = new QTreeWidgetItem(allEvents);
|
||||
add->setText(0, myevent.name);
|
||||
add->setText(1, myevent.date.toString("MMM d, yyyy"));
|
||||
|
||||
// make sure they fit
|
||||
eventTree->header()->resizeSections(QHeaderView::ResizeToContents);
|
||||
|
||||
// save changes away
|
||||
seasons->writeSeasons();
|
||||
active = false;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
LTMSidebar::deleteEvent()
|
||||
{
|
||||
active = true;
|
||||
|
||||
// now delete!
|
||||
int seasonindex = allDateRanges->indexOfChild(activeDateRange);
|
||||
int eventindex = allEvents->indexOfChild(activeEvent);
|
||||
|
||||
// wipe them away
|
||||
delete allEvents->takeChild(eventindex);
|
||||
seasons->seasons[seasonindex].events.removeAt(eventindex);
|
||||
|
||||
// save changes away
|
||||
seasons->writeSeasons();
|
||||
|
||||
active = false;
|
||||
}
|
||||
|
||||
void
|
||||
LTMSidebar::editEvent()
|
||||
{
|
||||
int seasonindex = allDateRanges->indexOfChild(activeDateRange);
|
||||
int eventindex = allEvents->indexOfChild(activeEvent);
|
||||
|
||||
EditSeasonEventDialog dialog(main, &seasons->seasons[seasonindex].events[eventindex]);
|
||||
|
||||
if (dialog.exec()) {
|
||||
|
||||
active = true;
|
||||
|
||||
// update name
|
||||
activeEvent->setText(0, seasons->seasons[seasonindex].events[eventindex].name);
|
||||
activeEvent->setText(1, seasons->seasons[seasonindex].events[eventindex].date.toString("MMM d, yyyy"));
|
||||
|
||||
// save changes away
|
||||
seasons->writeSeasons();
|
||||
active = false;
|
||||
|
||||
// signal its changed!
|
||||
//dateRangeSelected(&seasons->seasons[index]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
LTMSidebar::setSummary(DateRange dateRange)
|
||||
{
|
||||
|
||||
@@ -62,6 +62,8 @@ class LTMSidebar : public QWidget
|
||||
void dateRangeChanged(DateRange);
|
||||
|
||||
public slots:
|
||||
|
||||
// date range selection and editing
|
||||
void dateRangeTreeWidgetSelectionChanged();
|
||||
void dateRangePopup(QPoint);
|
||||
void dateRangeChanged(QTreeWidgetItem *, int);
|
||||
@@ -69,12 +71,19 @@ class LTMSidebar : public QWidget
|
||||
void editRange();
|
||||
void deleteRange();
|
||||
|
||||
void eventPopup(QPoint);
|
||||
void editEvent();
|
||||
void deleteEvent();
|
||||
void addEvent();
|
||||
|
||||
// config etc
|
||||
void configChanged();
|
||||
void resetSeasons(); // rebuild the seasons list if it changes
|
||||
|
||||
// gui components
|
||||
void setSummary(DateRange);
|
||||
|
||||
void splitterMoved(int, int);
|
||||
|
||||
private:
|
||||
|
||||
const QDir home;
|
||||
@@ -86,7 +95,10 @@ class LTMSidebar : public QWidget
|
||||
QTreeWidget *dateRangeTree;
|
||||
QTreeWidgetItem *allDateRanges;
|
||||
QTreeWidgetItem *activeDateRange; // when using context menus
|
||||
//const Season *dateRange;
|
||||
|
||||
QTreeWidget *eventTree;
|
||||
QTreeWidgetItem *allEvents;
|
||||
QTreeWidgetItem *activeEvent; // when using context menus
|
||||
|
||||
QWebView *summary;
|
||||
|
||||
|
||||
@@ -155,6 +155,62 @@ EditSeasonDialog::cancelClicked()
|
||||
reject();
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
* EDIT SEASONEVENT DIALOG
|
||||
*--------------------------------------------------------------------*/
|
||||
EditSeasonEventDialog::EditSeasonEventDialog(MainWindow *mainWindow, SeasonEvent *event) :
|
||||
QDialog(mainWindow, Qt::Dialog), mainWindow(mainWindow), event(event)
|
||||
{
|
||||
setWindowTitle(tr("Edit Event"));
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout(this);
|
||||
|
||||
// Grid
|
||||
QGridLayout *grid = new QGridLayout;
|
||||
QLabel *name = new QLabel("Name");
|
||||
QLabel *date = new QLabel("Date");
|
||||
|
||||
nameEdit = new QLineEdit(this);
|
||||
nameEdit->setText(event->name);
|
||||
|
||||
dateEdit = new QDateEdit(this);
|
||||
dateEdit->setDate(event->date);
|
||||
|
||||
grid->addWidget(name, 0,0);
|
||||
grid->addWidget(nameEdit, 0,1);
|
||||
grid->addWidget(date, 1,0);
|
||||
grid->addWidget(dateEdit, 1,1);
|
||||
|
||||
mainLayout->addLayout(grid);
|
||||
|
||||
// Buttons
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||||
buttonLayout->addStretch();
|
||||
applyButton = new QPushButton(tr("&OK"), this);
|
||||
cancelButton = new QPushButton(tr("&Cancel"), this);
|
||||
buttonLayout->addWidget(cancelButton);
|
||||
buttonLayout->addWidget(applyButton);
|
||||
mainLayout->addLayout(buttonLayout);
|
||||
|
||||
// connect up slots
|
||||
connect(applyButton, SIGNAL(clicked()), this, SLOT(applyClicked()));
|
||||
connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelClicked()));
|
||||
}
|
||||
|
||||
void
|
||||
EditSeasonEventDialog::applyClicked()
|
||||
{
|
||||
// get the values back
|
||||
event->name = nameEdit->text();
|
||||
event->date = dateEdit->date();
|
||||
accept();
|
||||
}
|
||||
|
||||
void
|
||||
EditSeasonEventDialog::cancelClicked()
|
||||
{
|
||||
reject();
|
||||
}
|
||||
|
||||
//
|
||||
// Manage the seasons array
|
||||
//
|
||||
|
||||
22
src/Season.h
22
src/Season.h
@@ -93,6 +93,28 @@ class EditSeasonDialog : public QDialog
|
||||
QDateEdit *fromEdit, *toEdit;
|
||||
};
|
||||
|
||||
class EditSeasonEventDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
G_OBJECT
|
||||
|
||||
|
||||
public:
|
||||
EditSeasonEventDialog(MainWindow *, SeasonEvent *);
|
||||
|
||||
public slots:
|
||||
void applyClicked();
|
||||
void cancelClicked();
|
||||
|
||||
private:
|
||||
MainWindow *mainWindow;
|
||||
SeasonEvent *event;
|
||||
|
||||
QPushButton *applyButton, *cancelButton;
|
||||
QLineEdit *nameEdit;
|
||||
QDateEdit *dateEdit;
|
||||
};
|
||||
|
||||
class Seasons : public QObject {
|
||||
|
||||
Q_OBJECT;
|
||||
|
||||
Reference in New Issue
Block a user