Implemented insertRows to model.
[emufront] / src / dialogs / emufrontdatadialog.cpp
1 // EmuFront
2 // Copyright 2010 Mikko Keinänen
3 //
4 // This file is part of EmuFront.
5 //
6 //
7 // EmuFront is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2 as published by
9 // the Free Software Foundation and appearing in the file gpl.txt included in the
10 // packaging of this file.
11 //
12 // EmuFront is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with EmuFront.  If not, see <http://www.gnu.org/licenses/>.
19
20 #include <QtGui>
21 #include "emufrontdatadialog.h"
22
23 EmuFrontDataDialog::EmuFrontDataDialog(QWidget *parent) :
24     EmuFrontDialog(parent)
25 {
26     editButton = new QPushButton(tr("&Edit"));
27     editButton->setEnabled(false);
28     addButton = new QPushButton(tr("&Add"));
29     deleteButton = new QPushButton(tr("&Delete"));
30     deleteButton->setEnabled(false);
31     objectList = new QTableView(this);
32     buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Vertical);
33     buttonBox->addButton(editButton, QDialogButtonBox::ActionRole);
34     buttonBox->addButton(addButton, QDialogButtonBox::ActionRole);
35     buttonBox->addButton(deleteButton, QDialogButtonBox::ActionRole);
36     // this be called from the implementing classes:
37     //connectSignals();
38     layout();
39 }
40
41 void EmuFrontDataDialog::postInit()
42 {
43     connectSignals();
44     setHiddenColumns();
45     hideColumns();
46 }
47
48 void EmuFrontDataDialog::layout()
49 {
50     QHBoxLayout *mainLayout = new QHBoxLayout;
51     mainLayout->addWidget(objectList);
52     mainLayout->addWidget(buttonBox);
53     setLayout(mainLayout);
54 }
55
56 void EmuFrontDataDialog::hideColumns()
57 {
58     foreach(int c, hiddenColumns)
59         objectList->hideColumn(c);
60 }
61
62 void EmuFrontDataDialog::connectSignals()
63 {
64     connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
65     /*connect(objectList, SIGNAL(clicked(const QModelIndex &)),
66         this, SLOT(listObjectClicked(const QModelIndex &)));*/
67     connect(editButton, SIGNAL(clicked()), this, SLOT(editButtonClicked()));
68     connect(addButton, SIGNAL(clicked()), this, SLOT(addButtonClicked()));
69     connect(deleteButton, SIGNAL(clicked()), this, SLOT(deleteButtonClicked()));
70 }
71
72 void EmuFrontDataDialog::editButtonClicked()
73 {
74     qDebug() << "Edit button clicked";
75 }
76
77 void EmuFrontDataDialog::deleteButtonClicked()
78 {
79     qDebug() << "Delete button clicked";
80 }
81
82 void EmuFrontDataDialog::addButtonClicked()
83 {
84     qDebug() << "Delete button clicked";
85     int row = objectList->currentIndex().row();
86     if (row == -1) row  = 0;
87     model->insertRows(row, 1);
88     QModelIndex ind = model->index(row, 1);
89     if (!ind.isValid()){
90         qDebug() << "Invalid index";
91         return;
92     }
93     objectList->setCurrentIndex(ind);
94     objectList->edit(ind);
95 }