blob: ac5dcbfc3b4dbfba663f42d63c75c9c05a85ceed [file] [log] [blame]
Yingdi Yu348f5ea2014-03-01 14:47:25 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Yingdi Yu
5 *
6 * BSD license, See the LICENSE file for more information
7 *
8 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
9 */
10
11#include "profile-editor.h"
12#include "ui_profile-editor.h"
13#include <QtSql/QSqlRecord>
14#include <QtSql/QSqlField>
15#include <QtSql/QSqlError>
16
17#ifndef Q_MOC_RUN
18#include "logging.h"
19#endif
20
21INIT_LOGGER("ProfileEditor")
22
23using namespace std;
24
25ProfileEditor::ProfileEditor(QWidget *parent)
26 : QDialog(parent)
27 , ui(new Ui::ProfileEditor)
28 , m_tableModel(new QSqlTableModel())
29{
30 ui->setupUi(this);
31
32 connect(ui->addRowButton, SIGNAL(clicked()),
33 this, SLOT(onAddClicked()));
34 connect(ui->deleteRowButton, SIGNAL(clicked()),
35 this, SLOT(onDeleteClicked()));
36 connect(ui->okButton, SIGNAL(clicked()),
37 this, SLOT(onOkClicked()));
38}
39
40ProfileEditor::~ProfileEditor()
41{
42 delete ui;
43 delete m_tableModel;
44}
45
46void
47ProfileEditor::onCloseDBModule()
48{
49 _LOG_DEBUG("close db module");
50 if(m_tableModel)
51 {
52 delete m_tableModel;
53 _LOG_DEBUG("tableModel closed");
54 }
55}
56
57void
58ProfileEditor::onIdentityUpdated(const QString& identity)
59{
60 m_tableModel = new QSqlTableModel();
61
62 m_identity = identity;
63 ui->identityInput->setText(identity);
64
65 m_tableModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
66 m_tableModel->setTable("SelfProfile");
67 m_tableModel->select();
68 m_tableModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Type"));
69 m_tableModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Value"));
70
71 ui->profileTable->setModel(m_tableModel);
72 ui->profileTable->show();
73}
74
75void
76ProfileEditor::onAddClicked()
77{
78 int rowCount = m_tableModel->rowCount();
79 QSqlRecord record;
80 m_tableModel->insertRow(rowCount);
81 m_tableModel->setRecord(rowCount, record);
82}
83
84void
85ProfileEditor::onDeleteClicked()
86{
87 QItemSelectionModel* selectionModel = ui->profileTable->selectionModel();
88 QModelIndexList indexList = selectionModel->selectedIndexes();
89
90 int i = indexList.size() - 1;
91 for(; i >= 0; i--)
92 m_tableModel->removeRow(indexList[i].row());
93
94 m_tableModel->submitAll();
95}
96
97void
98ProfileEditor::onOkClicked()
99{
100 m_tableModel->submitAll();
101 emit updateProfile();
102 this->hide();
103}
104
105#if WAF
106#include "profile-editor.moc"
107#include "profile-editor.cpp.moc"
108#endif