blob: 9488f4774c983001f2220f34c2480c78d2641d2c [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
Yingdi Yufa0b6a02014-04-30 14:26:42 -070023ProfileEditor::ProfileEditor(QWidget *parent)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080024 : QDialog(parent)
25 , ui(new Ui::ProfileEditor)
26 , m_tableModel(new QSqlTableModel())
27{
28 ui->setupUi(this);
29
30 connect(ui->addRowButton, SIGNAL(clicked()),
31 this, SLOT(onAddClicked()));
32 connect(ui->deleteRowButton, SIGNAL(clicked()),
33 this, SLOT(onDeleteClicked()));
34 connect(ui->okButton, SIGNAL(clicked()),
35 this, SLOT(onOkClicked()));
36}
37
38ProfileEditor::~ProfileEditor()
39{
40 delete ui;
41 delete m_tableModel;
42}
43
44void
45ProfileEditor::onCloseDBModule()
46{
47 _LOG_DEBUG("close db module");
48 if(m_tableModel)
49 {
50 delete m_tableModel;
51 _LOG_DEBUG("tableModel closed");
52 }
53}
54
55void
56ProfileEditor::onIdentityUpdated(const QString& identity)
57{
58 m_tableModel = new QSqlTableModel();
59
60 m_identity = identity;
61 ui->identityInput->setText(identity);
Yingdi Yufa0b6a02014-04-30 14:26:42 -070062
Yingdi Yu348f5ea2014-03-01 14:47:25 -080063 m_tableModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
64 m_tableModel->setTable("SelfProfile");
65 m_tableModel->select();
66 m_tableModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Type"));
67 m_tableModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Value"));
68
69 ui->profileTable->setModel(m_tableModel);
70 ui->profileTable->show();
71}
72
73void
74ProfileEditor::onAddClicked()
75{
76 int rowCount = m_tableModel->rowCount();
77 QSqlRecord record;
78 m_tableModel->insertRow(rowCount);
79 m_tableModel->setRecord(rowCount, record);
80}
81
82void
83ProfileEditor::onDeleteClicked()
84{
85 QItemSelectionModel* selectionModel = ui->profileTable->selectionModel();
86 QModelIndexList indexList = selectionModel->selectedIndexes();
87
Yingdi Yufa0b6a02014-04-30 14:26:42 -070088 int i = indexList.size() - 1;
Yingdi Yu348f5ea2014-03-01 14:47:25 -080089 for(; i >= 0; i--)
90 m_tableModel->removeRow(indexList[i].row());
Yingdi Yufa0b6a02014-04-30 14:26:42 -070091
Yingdi Yu348f5ea2014-03-01 14:47:25 -080092 m_tableModel->submitAll();
93}
94
95void
96ProfileEditor::onOkClicked()
97{
98 m_tableModel->submitAll();
99 emit updateProfile();
100 this->hide();
101}
102
103#if WAF
104#include "profile-editor.moc"
105#include "profile-editor.cpp.moc"
106#endif