blob: f0b067d14846c993bf473168da3dbec87bd98b21 [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2013, Regents of the University of California
* Yingdi Yu
*
* BSD license, See the LICENSE file for more information
*
* Author: Yingdi Yu <yingdi@cs.ucla.edu>
*/
#include "profile-editor.hpp"
#include "ui_profile-editor.h"
#include <QtSql/QSqlRecord>
#include <QtSql/QSqlField>
#include <QtSql/QSqlError>
#ifndef Q_MOC_RUN
#include "logging.h"
#endif
// INIT_LOGGER("ProfileEditor")
namespace chronochat {
ProfileEditor::ProfileEditor(QWidget *parent)
: QDialog(parent)
, ui(new Ui::ProfileEditor)
, m_tableModel(new QSqlTableModel())
{
ui->setupUi(this);
connect(ui->addRowButton, SIGNAL(clicked()),
this, SLOT(onAddClicked()));
connect(ui->deleteRowButton, SIGNAL(clicked()),
this, SLOT(onDeleteClicked()));
connect(ui->okButton, SIGNAL(clicked()),
this, SLOT(onOkClicked()));
}
ProfileEditor::~ProfileEditor()
{
delete ui;
if (m_tableModel)
delete m_tableModel;
}
void
ProfileEditor::onCloseDBModule()
{
if (m_tableModel) {
delete m_tableModel;
m_tableModel = 0;
}
}
void
ProfileEditor::onIdentityUpdated(const QString& identity)
{
m_identity = identity;
ui->identityInput->setText(identity);
}
void
ProfileEditor::resetPanel()
{
m_tableModel = new QSqlTableModel();
m_tableModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
m_tableModel->setTable("SelfProfile");
m_tableModel->select();
m_tableModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Type"));
m_tableModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Value"));
ui->profileTable->setModel(m_tableModel);
ui->profileTable->show();
}
void
ProfileEditor::onAddClicked()
{
int rowCount = m_tableModel->rowCount();
QSqlRecord record;
m_tableModel->insertRow(rowCount);
m_tableModel->setRecord(rowCount, record);
}
void
ProfileEditor::onDeleteClicked()
{
QItemSelectionModel* selectionModel = ui->profileTable->selectionModel();
QModelIndexList indexList = selectionModel->selectedIndexes();
for (int i = indexList.size() - 1; i >= 0; i--)
m_tableModel->removeRow(indexList[i].row());
m_tableModel->submitAll();
}
void
ProfileEditor::onOkClicked()
{
m_tableModel->submitAll();
emit updateProfile();
this->hide();
}
} // namespace chronochat
#if WAF
#include "profile-editor.moc"
// #include "profile-editor.cpp.moc"
#endif