Changeset d97bcab


Ignore:
Timestamp:
04/15/10 14:49:59 (12 years ago)
Author:
kirilma <kirilma@…>
Branches:
master, qt5
Children:
04acaf9
Parents:
f5b68a4
Message:

implement deleting a conference

pass event about it to mainwindow to update select control
fix Conference::activeConference() to work when first conference is removed

Location:
src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/gui/importschedulewidget.cpp

    rf5b68a4 rd97bcab  
    2727#include <QNetworkAccessManager>
    2828#include <QNetworkReply>
     29#include <QMessageBox>
    2930#include <QDebug>
    3031#include <appsettings.h>
     
    167168void ImportScheduleWidget::on_delete()
    168169{
    169     // TODO: implement
     170    int active_id = Conference::activeConference();
     171    Conference active_conference = Conference::getById(active_id);
     172
     173    QMessageBox::StandardButton answer =
     174        QMessageBox::question(0
     175            , "Deletion confirmation"
     176            , QString("Really delete the %1 conference").arg(active_conference.title())
     177            , QMessageBox::Yes | QMessageBox::No
     178            , QMessageBox::No);
     179
     180    if (answer == QMessageBox::Yes) {
     181        QString title = active_conference.title();
     182        Conference::deleteConference(active_id);
     183        emit(scheduleDeleted(title));
     184    }
    170185}
    171186
  • src/gui/importschedulewidget.h

    rf5b68a4 rd97bcab  
    4444    signals:
    4545        void scheduleImported(int confId);
     46        void scheduleDeleted(const QString& title);
    4647    private:
    4748        void importFromNetwork(const QString& url);
  • src/gui/mainwindow.cpp

    rf5b68a4 rd97bcab  
    7575
    7676    connect(importScheduleWidget, SIGNAL(scheduleImported(int)), SLOT(scheduleImported(int)));
     77    connect(importScheduleWidget, SIGNAL(scheduleDeleted(const QString&)), SLOT(scheduleDeleted(const QString&)));
    7778
    7879    // event details have changed
     
    161162}
    162163
     164void MainWindow::scheduleDeleted(const QString& title)
     165{
     166    int idx = selectConference->findText(title);
     167
     168    if (idx == -1) {
     169        // should not happen
     170        qWarning() << __PRETTY_FUNCTION__ << "removed non-existent item:" << title;
     171    } else {
     172        // will it signal "changed"?
     173        selectConference->removeItem(idx);
     174    }
     175}
     176
    163177void MainWindow::aboutApp()
    164178{
  • src/gui/mainwindow.h

    rf5b68a4 rd97bcab  
    3434private slots:
    3535    void scheduleImported(int aConfId);
     36    void scheduleDeleted(const QString& title);
    3637    void aboutApp();
    3738    void conferenceMapClicked();
  • src/mvc/conference.cpp

    rf5b68a4 rd97bcab  
    1818 */
    1919#include "conference.h"
     20#include "../sql/sqlengine.h"
    2021
    2122QSqlRecord const Conference::sColumns = Conference::toRecord(QList<QSqlField>()
     
    5253int Conference::activeConference()
    5354{
    54     QSqlQuery query("SELECT id FROM conference WHERE active = 1");
    55     query.exec();
     55    {
     56        QSqlQuery query("SELECT id FROM conference WHERE active = 1");
     57        query.exec();
    5658
    57     QList<int> activeConfs;
    58     while(query.next())
    59         activeConfs.append(query.record().value("id").toInt());
     59        // TODO: change it so that it will select somw existing ID
    6060
    61     qDebug() << __PRETTY_FUNCTION__
    62         << "activeConfs.count()" << activeConfs.count()
    63         ;
     61        if (query.next()) {
     62            return query.record().value("id").toInt();
     63        }
     64    }
    6465
    65     if(activeConfs.count()==0) // no active DB
    66         return 1;
    67     else // even if there are more active confs, the first from the list is confidered active
    68         return activeConfs[0];
     66    QSqlQuery query2("SELECT id FROM conference ORDER BY id");
     67    if (query2.next()) {
     68        return query2.record().value("id").toInt();
     69    }
     70
     71    return -1;
    6972}
    7073
     74void Conference::deleteConference(int id)
     75{
     76    SqlEngine::deleteConference(id);
     77}
     78
  • src/mvc/conference.h

    rf5b68a4 rd97bcab  
    3636    static QList<Conference> getAll();
    3737    static int activeConference();
     38    static void deleteConference(int id);
    3839
    3940public:
  • src/sql/sqlengine.cpp

    rf5b68a4 rd97bcab  
    321321}
    322322
     323void SqlEngine::deleteConference(int id)
     324{
     325    QSqlDatabase db = QSqlDatabase::database();
     326
     327    if ( !db.isValid() || !db.isOpen()) {
     328        return;
     329    }
     330
     331    beginTransaction();
     332
     333    QHash<QString, QVariant> params;
     334    params["xid_conference"] = id;
     335    execQueryWithParameter(db, "DELETE FROM LINK WHERE xid_conference = :xid_conference", params);
     336    execQueryWithParameter(db, "DELETE FROM EVENT_ROOM WHERE xid_conference = :xid_conference", params);
     337    execQueryWithParameter(db, "DELETE FROM EVENT_PERSON WHERE xid_conference = :xid_conference", params);
     338    execQueryWithParameter(db, "DELETE FROM EVENT WHERE xid_conference = :xid_conference", params);
     339    execQueryWithParameter(db, "DELETE FROM CONFERENCE WHERE id = :xid_conference", params);
     340    execQuery(db, "DELETE FROM ROOM WHERE NOT EXISTS(SELECT * FROM EVENT_ROOM WHERE xid_room = ROOM.id)");
     341    execQuery(db, "DELETE FROM PERSON WHERE NOT EXISTS(SELECT * FROM EVENT_PERSON WHERE xid_person = PERSON.id)");
     342
     343    commitTransaction();
     344}
     345
    323346bool SqlEngine::execQuery(QSqlDatabase &aDatabase, const QString &aQuery)
    324347{
     
    336359}
    337360
     361bool SqlEngine::execQueryWithParameter(QSqlDatabase &aDatabase, const QString &aQuery, const QHash<QString, QVariant>& params)
     362{
     363    qDebug() << "SQL:" << aQuery << "params:" << params;
     364
     365    QSqlQuery sqlQuery(aDatabase);
     366    sqlQuery.prepare(aQuery);
     367    foreach (QString param_key, params.keys()) {
     368        sqlQuery.bindValue(param_key, params[param_key]);
     369    }
     370    if( !sqlQuery.exec() ){
     371       qDebug() << "SQL ERR: " << sqlQuery.lastError().number() << ", " << sqlQuery.lastError().text();
     372       return false;
     373    }
     374    else{
     375       //qDebug() << "SQL OK.\n";
     376       return true;
     377    }
     378}
     379
  • src/sql/sqlengine.h

    rf5b68a4 rd97bcab  
    3737        static void addLinkToDB(QHash<QString,QString> &aLink);
    3838        static void addRoomToDB(QHash<QString,QString> &aRoom);
     39        static void deleteConference(int id);
    3940
    4041        static bool beginTransaction();
     
    4647        static QString login(const QString &aDatabaseType, const QString &aDatabaseName);
    4748        static bool execQuery(QSqlDatabase &aDatabase, const QString &aQuery);
     49        static bool execQueryWithParameter(QSqlDatabase &aDatabase, const QString &aQuery, const QHash<QString, QVariant>& params);
    4850};
    4951
Note: See TracChangeset for help on using the changeset viewer.