From: Sakari Poussa Date: Tue, 27 Apr 2010 03:24:11 +0000 (+0300) Subject: - Fixed course delete crashes X-Git-Url: http://vcs.maemo.org/git/?p=scorecard;a=commitdiff_plain;h=306a8cca83cf28073b95bbd84e30a0f5c7fae167 - Fixed course delete crashes - Text alignment correct in list view - Make list view selections correctly - Color tuning --- diff --git a/debian/control b/debian/control index 3d762a5..70807c2 100644 --- a/debian/control +++ b/debian/control @@ -7,7 +7,7 @@ Standards-Version: 3.7.2 Package: scorecard Architecture: any -Depends: libqt4-gui (>= 4.5.3~git20090723) +Depends: libqt4-gui (>= 4.6.2~git20100310) Description: Simple golf score card application for N900 to keep track of your golf scores . Further Information: http://scorecard.garage.maemo.org diff --git a/scorecard.pro b/scorecard.pro index 2fd2cd9..9a8dac3 100644 --- a/scorecard.pro +++ b/scorecard.pro @@ -50,7 +50,6 @@ unix { target.path =$$BINDIR data.path = $$DATADIR - data.files += data/club.xml desktop.path = $$MAEMODIR desktop.files += maemo/scorecard.desktop diff --git a/src/data.cpp b/src/data.cpp index 6ff2d98..ad0813c 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -242,6 +242,11 @@ Club * Course::parent() return club; } +void Course::setParent(Club *parent) +{ + club = parent; +} + QDomElement Course::toElement(QDomDocument doc) { QDomElement node = doc.createElement("course"); @@ -337,6 +342,7 @@ Club::Club(QString &name) void Club::addCourse(Course *iCourse) { courseList << iCourse; + iCourse->setParent(this); } void Club::delCourse(Course * course) { diff --git a/src/data.h b/src/data.h index 5709416..4ab4e61 100644 --- a/src/data.h +++ b/src/data.h @@ -86,6 +86,7 @@ class Course { QString getTotal(int what); void dump(); Club * parent(); + void setParent(Club *parent); private: QList holeList; diff --git a/src/list-model.cpp b/src/list-model.cpp index 76e42d4..5c3e8be 100644 --- a/src/list-model.cpp +++ b/src/list-model.cpp @@ -53,13 +53,13 @@ QVariant ScoreListModel::data(const QModelIndex &index, int role) const QString tabs; int len = s.length(); - if (len > 40) + if (len >= 40) tabs = "\t"; - else if (len > 32) + else if (len >= 32) tabs = "\t\t"; - else if (len > 24) + else if (len >= 24) tabs = "\t\t\t"; - else if (len > 16) + else if (len >= 16) tabs = "\t\t\t\t"; else tabs = "\t\t\t\t\t"; diff --git a/src/main-window.cpp b/src/main-window.cpp index 42c6b44..deda9ef 100644 --- a/src/main-window.cpp +++ b/src/main-window.cpp @@ -29,6 +29,8 @@ QString scoreFile; QString clubFileName("club.xml"); QString clubFile; QString logFile("/tmp/scorecard.log"); +QString titleScores("ScoreCard - Scores"); +QString titleCourses("ScoreCard - Courses"); bool dateLessThan(const Score *s1, const Score *s2) { @@ -85,6 +87,7 @@ Course *MainWindow::findCourse(const QString &clubName, } // Find course based on current selection on the list +// TODO: make sure this is only called when course list is the model... Course *MainWindow::findCourse() { QModelIndex index = selectionModel->currentIndex(); @@ -122,7 +125,6 @@ MainWindow::MainWindow(QMainWindow *parent): QMainWindow(parent) createMenus(); createListView(scoreList, clubList); - updateTitleBar(); createLayoutList(centralWidget); } @@ -173,7 +175,7 @@ void MainWindow::createLayoutList(QWidget *parent) void MainWindow::createListView(QList &scoreList, QList &clubList) { - list = new QListView; + list = new QListView(this); scoreListModel = new ScoreListModel(scoreList, clubList); courseListModel = new CourseListModel(clubList); @@ -181,25 +183,27 @@ void MainWindow::createListView(QList &scoreList, list->setStyleSheet(ScoreStyle::style()); list->setSelectionMode(QAbstractItemView::SingleSelection); + list->setProperty("FingerScrolling", true); // Initial view listScores(); + + connect(list, SIGNAL(clicked(QModelIndex)), + this, SLOT(clickedList(QModelIndex))); } void MainWindow::listScores() { list->setModel(scoreListModel); selectionModel = list->selectionModel(); - connect(selectionModel, SIGNAL(selectionChanged (const QItemSelection &, const QItemSelection &)), - this, SLOT(scoreSelectionChanged(const QItemSelection &, const QItemSelection &))); + updateTitleBar(titleScores); } void MainWindow::listCourses() { list->setModel(courseListModel); selectionModel = list->selectionModel(); - connect(selectionModel, SIGNAL(selectionChanged (const QItemSelection &, const QItemSelection &)), - this, SLOT(courseSelectionChanged(const QItemSelection &, const QItemSelection &))); + updateTitleBar(titleCourses); } void MainWindow::createActions() @@ -241,10 +245,9 @@ void MainWindow::createMenus() menu->addActions(filterGroup->actions()); } -void MainWindow::updateTitleBar() +void MainWindow::updateTitleBar(QString & msg) { - QString title("ScoreCard"); - setWindowTitle(title); + setWindowTitle(msg); } void MainWindow::showNote(QString msg) @@ -256,42 +259,31 @@ void MainWindow::showNote(QString msg) #endif } -void MainWindow::scoreSelectionChanged(const QItemSelection &selected, - const QItemSelection &deselected) +void MainWindow::clickedList(const QModelIndex &index) { - QModelIndexList list = selected.indexes(); - - int row = list.at(0).row(); + int row = index.row(); - Score * score = scoreList.at(row); - Course * course = findCourse(score->getClubName(), score->getCourseName()); - viewScore(score, course); -} - -void MainWindow::courseSelectionChanged(const QItemSelection &selected, - const QItemSelection &deselected) -{ - QModelIndexList indexes = selected.indexes(); - - int row = indexes.at(0).row(); - - QString str = courseListModel->data(indexes.at(0), Qt::DisplayRole).toString(); - - QStringList strList = str.split(","); + const QAbstractItemModel *m = index.model(); + if (m == scoreListModel) { + if (row < scoreList.count()) { + Score * score = scoreList.at(row); + Course * course = findCourse(score->getClubName(), score->getCourseName()); + viewScore(score, course); + } + } + else if (m == courseListModel) { + QString str = courseListModel->data(index, Qt::DisplayRole).toString(); + QStringList strList = str.split(","); - if (strList.count() != 2) { - showNote(QString("Invalid course selection")); - return; + if (strList.count() != 2) { + showNote(QString("Invalid course selection")); + return; + } + Course * course = findCourse(strList.at(0), strList.at(1)); + viewCourse(course); } - Course * course = findCourse(strList.at(0), strList.at(1)); - viewCourse(course); } -void MainWindow::changeCurrent(const QModelIndex ¤t, - const QModelIndex &previous) -{ - qDebug() << "Current: " << current; -} void MainWindow::newCourse() { @@ -340,8 +332,7 @@ void MainWindow::newCourse() } // Save it saveClubFile(clubFile, clubList); - // TODO: update on live - //courseListModel->update(courseList); + courseListModel->update(clubList); list->update(); } } @@ -503,8 +494,7 @@ void MainWindow::editScore() } } -void MainWindow::viewScore(Score * score, - Course * course) +void MainWindow::viewScore(Score * score, Course * course) { scoreWin = new QMainWindow(this); QString title = QString("Score: %1, %2 - %3").arg(score->getClubName()).arg(score->getCourseName()).arg(score->getDate()); diff --git a/src/main-window.h b/src/main-window.h index 94129cc..c552f2d 100644 --- a/src/main-window.h +++ b/src/main-window.h @@ -31,7 +31,7 @@ public: void createLayoutTable(QWidget *parent = 0); void createLayoutList(QWidget *parent = 0); void createListView(QList &, QList &); - void updateTitleBar(); + void updateTitleBar(QString & msg); void loadScoreFile(QString &fileName, QList &scoreList); void loadClubFile(QString &fileName, QList &clubList); void saveScoreFile(QString &fileName, QList &scoreList); @@ -41,12 +41,8 @@ signals: void dataChanged(); private slots: - void scoreSelectionChanged(const QItemSelection &selected, - const QItemSelection &deselected); - void courseSelectionChanged(const QItemSelection &selected, - const QItemSelection &deselected); - void changeCurrent(const QModelIndex ¤t, - const QModelIndex &previous); + void clickedList(const QModelIndex &index); + void newScore(); void deleteScore(); void editScore(); diff --git a/src/score-common.h b/src/score-common.h index 2b28aaa..08ce96f 100644 --- a/src/score-common.h +++ b/src/score-common.h @@ -38,9 +38,9 @@ class ScoreColor static QColor holeFg() { return Qt::yellow; } static QColor birdie() { return Qt::yellow; } static QColor par() { return Qt::green; } - static QColor bogey() { return QColor(0x20, 0x4a, 0x87); } - static QColor doubleBogey() { return QColor(0x34, 0x65, 0xa4); } - static QColor bad() { return QColor(0x72, 0x9f, 0xcf); } + static QColor bogey() { return Qt::cyan; } + static QColor doubleBogey() { return Qt::red; } + static QColor bad() { return Qt::red; } static QColor subTotal() { return Qt::white; } static QColor total() { return Qt::white; } }; @@ -51,7 +51,7 @@ public: { return QString("QTableView {" "background-color: white;" - "color : red;" + "color : gray;" "border: solid green;" "font-size : 20px;" "font-style : italic;"