94129cca196da005777cc4d9975c77574b935f7c
[scorecard] / src / main-window.h
1 /*
2  * Copyright (C) 2009 Sakari Poussa
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, version 2.
7  */
8
9 #include <QMainWindow>
10 #include <QTableView>
11 #include <QListView>
12 #include <QPushButton>
13 #include <QTextEdit>
14 #include <QVBoxLayout>
15 #include <QItemSelectionModel>
16 #include <QList>
17 #include <QLabel>
18 #include <QActionGroup>
19 #include <QXmlDefaultHandler>
20
21 #include "data.h"
22 #include "table-model.h"
23 #include "list-model.h"
24
25 class MainWindow : public QMainWindow
26 {
27   Q_OBJECT
28
29 public:
30   MainWindow(QMainWindow *parent = 0);
31   void createLayoutTable(QWidget *parent = 0);
32   void createLayoutList(QWidget *parent = 0);
33   void createListView(QList<Score *> &, QList <Club *> &);
34   void updateTitleBar();
35   void loadScoreFile(QString &fileName, QList<Score *> &scoreList);
36   void loadClubFile(QString &fileName, QList<Club *> &clubList);
37   void saveScoreFile(QString &fileName, QList<Score *> &scoreList);
38   void saveClubFile(QString &fileName, QList<Club *> &clubList);
39
40 signals:
41   void dataChanged();
42
43 private slots:
44   void scoreSelectionChanged(const QItemSelection &selected,
45                              const QItemSelection &deselected);
46   void courseSelectionChanged(const QItemSelection &selected,
47                               const QItemSelection &deselected);
48   void changeCurrent(const QModelIndex &current,
49                      const QModelIndex &previous);
50   void newScore();
51   void deleteScore();
52   void editScore();
53   void newCourse();
54   void deleteCourse();
55   void editCourse();
56   void viewStatistics();
57   void listScores();
58   void listCourses();
59
60 private:
61
62   void loadSettings(void);
63   Club * findClub(QString &name);
64   Course * findCourse(const QString &clubName, const QString &courseName);
65   Course * findCourse();
66   Score * findScore(QString & clubName, QString & courseName);
67                                
68   void showNote(QString msg);
69   void getStat(QTextEdit *);
70
71   void viewScore(Score * score, Course * course);
72   void viewCourse(Course * course);
73
74   QList<Score *> scoreList;
75   QList<Club *> clubList;
76
77   ScoreTableModel *scoreTableModel;
78   ScoreListModel *scoreListModel;
79   CourseListModel *courseListModel;
80
81   QAbstractItemModel *tableModel;
82   QItemSelectionModel *selectionModel;
83
84   QTableView *table;
85   QListView *list;
86
87   // Layouts
88   QWidget *centralWidget;
89
90   // Menus
91   QMenu *menu;
92
93   // Actions
94   QAction *newScoreAction;
95   QAction *newCourseAction;
96   QAction *statAction;
97
98   QActionGroup *filterGroup;
99   QAction *listScoreAction;
100   QAction *listCourseAction;
101
102   void createMenus();
103   void createActions();
104
105   // Windows
106   QMainWindow *scoreWin;
107   QMainWindow *courseWin;
108 };