14 * You should have received a copy of the GNU General Public License |
14 * You should have received a copy of the GNU General Public License |
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 */ |
16 */ |
17 #include "ProfileMashs.h" |
17 #include "ProfileMashs.h" |
18 #include "EditProfileMash.h" |
18 #include "EditProfileMash.h" |
19 #include "../ui/ui_ProfileMashs.h" |
19 #include "MainWindow.h" |
20 #include "config.h" |
20 #include "config.h" |
21 #include "bmsapp.h" |
21 #include "bmsapp.h" |
22 |
22 |
23 |
23 |
24 ProfileMashs::ProfileMashs(QWidget *parent) : QDialog(parent), ui(new Ui::ProfileMashs) |
24 ProfileMashs::ProfileMashs(QWidget *parent) : QDialog(parent) |
25 { |
25 { |
26 qDebug() << "ProfileMashs start"; |
26 qDebug() << "ProfileMashs start"; |
27 |
27 |
28 ui->setupUi(this); |
28 gridLayout = new QGridLayout(this); |
|
29 gridLayout->setObjectName(QString::fromUtf8("gridLayout")); |
|
30 tableMashs = new QTableWidget(this); |
|
31 tableMashs->setObjectName(QString::fromUtf8("tableMashs")); |
|
32 tableMashs->setEnabled(true); |
|
33 QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
|
34 sizePolicy.setHorizontalStretch(0); |
|
35 sizePolicy.setVerticalStretch(0); |
|
36 tableMashs->setSizePolicy(sizePolicy); |
|
37 tableMashs->setMinimumSize(QSize(1104, 0)); |
|
38 gridLayout->addWidget(tableMashs, 0, 0, 1, 1); |
|
39 |
|
40 groupBox = new QGroupBox(this); |
|
41 groupBox->setObjectName(QString::fromUtf8("groupBox")); |
|
42 groupBox->setEnabled(true); |
|
43 groupBox->setFlat(false); |
|
44 horizontalLayout = new QHBoxLayout(groupBox); |
|
45 horizontalLayout->setSpacing(6); |
|
46 horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); |
|
47 horizontalLayout->setContentsMargins(0, 0, 0, 0); |
|
48 |
|
49 quitButton = new QPushButton(groupBox); |
|
50 quitButton->setObjectName(QString::fromUtf8("quitButton")); |
|
51 quitButton->setMinimumSize(QSize(80, 24)); |
|
52 quitButton->setText(tr("Quit")); |
|
53 QIcon icon; |
|
54 icon.addFile(QString::fromUtf8(":icons/silk/door_out.png"), QSize(), QIcon::Normal, QIcon::Off); |
|
55 quitButton->setIcon(icon); |
|
56 horizontalLayout->addWidget(quitButton, 0, Qt::AlignLeft); |
|
57 |
|
58 insertButton = new QPushButton(groupBox); |
|
59 insertButton->setObjectName(QString::fromUtf8("insertButton")); |
|
60 insertButton->setMinimumSize(QSize(80, 24)); |
|
61 insertButton->setText(tr("New")); |
|
62 QIcon icon3; |
|
63 icon3.addFile(QString::fromUtf8(":icons/silk/table_row_insert.png"), QSize(), QIcon::Normal, QIcon::Off); |
|
64 insertButton->setIcon(icon3); |
|
65 horizontalLayout->addWidget(insertButton, 0, Qt::AlignRight); |
|
66 gridLayout->addWidget(groupBox, 1, 0, 1, 1); |
|
67 |
|
68 connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromProfileMashs())); |
|
69 connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked())); |
29 emit refreshTable(); |
70 emit refreshTable(); |
30 |
|
31 setWindowTitle( QString("BMSapp - %1 - Profile Mashs").arg(VERSIONSTRING) ); |
|
32 } |
71 } |
33 |
72 |
34 |
73 |
35 void ProfileMashs::refreshTable() |
74 void ProfileMashs::refreshTable() |
36 { |
75 { |
42 qDebug() << "ProfileMashs reload"; |
81 qDebug() << "ProfileMashs reload"; |
43 |
82 |
44 QSqlQuery query("SELECT * FROM profile_mash ORDER BY name"); |
83 QSqlQuery query("SELECT * FROM profile_mash ORDER BY name"); |
45 const QStringList labels({tr("Name"), tr("Notes"), tr("Steps"), tr("Edit")}); |
84 const QStringList labels({tr("Name"), tr("Notes"), tr("Steps"), tr("Edit")}); |
46 |
85 |
47 ui->tableMashs->setColumnCount(4); |
86 this->tableMashs->setColumnCount(4); |
48 ui->tableMashs->setColumnWidth(0, 250); /* Name */ |
87 this->tableMashs->setColumnWidth(0, 250); /* Name */ |
49 ui->tableMashs->setColumnWidth(1, 675); /* Notes */ |
88 this->tableMashs->setColumnWidth(1, 675); /* Notes */ |
50 ui->tableMashs->setColumnWidth(2, 75); /* Steps */ |
89 this->tableMashs->setColumnWidth(2, 75); /* Steps */ |
51 ui->tableMashs->setColumnWidth(3, 80); /* Edit button */ |
90 this->tableMashs->setColumnWidth(3, 80); /* Edit button */ |
52 ui->tableMashs->setRowCount(query.size()); |
91 this->tableMashs->setRowCount(query.size()); |
53 ui->tableMashs->setHorizontalHeaderLabels(labels); |
92 this->tableMashs->setHorizontalHeaderLabels(labels); |
54 ui->tableMashs->verticalHeader()->hide(); |
93 this->tableMashs->verticalHeader()->hide(); |
55 ui->tableMashs->setFixedSize(1080 + 24, 640); /* Even if this is too large, it works */ |
|
56 |
94 |
57 QTableWidgetItem *rightitem = new QTableWidgetItem(); |
95 QTableWidgetItem *rightitem = new QTableWidgetItem(); |
58 rightitem->setTextAlignment(Qt::AlignRight); |
96 rightitem->setTextAlignment(Qt::AlignRight); |
59 |
97 |
60 query.first(); |
98 query.first(); |
61 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { |
99 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { |
62 ui->tableMashs->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString())); /* Name */ |
100 this->tableMashs->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString())); /* Name */ |
63 ui->tableMashs->setItem(ridx, 1, new QTableWidgetItem(query.value(2).toString())); /* Notes */ |
101 this->tableMashs->setItem(ridx, 1, new QTableWidgetItem(query.value(2).toString())); /* Notes */ |
64 |
102 |
65 QJsonParseError parseError; |
103 QJsonParseError parseError; |
66 const auto& json = query.value(3).toString(); |
104 const auto& json = query.value(3).toString(); |
67 |
105 |
68 if (!json.trimmed().isEmpty()) { |
106 if (!json.trimmed().isEmpty()) { |
70 const auto& doc = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError); |
108 const auto& doc = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError); |
71 |
109 |
72 if (parseError.error != QJsonParseError::NoError) |
110 if (parseError.error != QJsonParseError::NoError) |
73 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ; |
111 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ; |
74 |
112 |
75 // qDebug() << " ** " << doc << doc.isArray() << doc.array().size() ; |
|
76 |
|
77 w = QString("%1").arg(doc.array().size()); |
113 w = QString("%1").arg(doc.array().size()); |
78 QTableWidgetItem *item = new QTableWidgetItem(w); |
114 QTableWidgetItem *item = new QTableWidgetItem(w); |
79 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
115 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
80 ui->tableMashs->setItem(ridx, 2, item); |
116 this->tableMashs->setItem(ridx, 2, item); |
81 } |
117 } |
82 |
118 |
83 /* Add the Edit button */ |
119 /* Add the Edit button */ |
84 pWidget = new QWidget(); |
120 pWidget = new QWidget(); |
85 QPushButton* btn_edit = new QPushButton(); |
121 QPushButton* btn_edit = new QPushButton(); |
88 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); |
124 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); |
89 pLayout = new QHBoxLayout(pWidget); |
125 pLayout = new QHBoxLayout(pWidget); |
90 pLayout->addWidget(btn_edit); |
126 pLayout->addWidget(btn_edit); |
91 pLayout->setContentsMargins(5, 0, 5, 0); |
127 pLayout->setContentsMargins(5, 0, 5, 0); |
92 pWidget->setLayout(pLayout); |
128 pWidget->setLayout(pLayout); |
93 ui->tableMashs->setCellWidget(ridx, 3, pWidget); |
129 this->tableMashs->setCellWidget(ridx, 3, pWidget); |
94 query.next(); |
130 query.next(); |
95 } |
131 } |
96 |
|
97 setWindowTitle( QString("BMSapp - %1 - Profile Mashs").arg(VERSIONSTRING) ); |
|
98 } |
132 } |
99 |
133 |
100 |
134 |
101 ProfileMashs::~ProfileMashs() |
135 ProfileMashs::~ProfileMashs() {} |
102 { |
|
103 qDebug() << "ProfileMashs done"; |
|
104 delete ui; |
|
105 } |
|
106 |
136 |
107 |
137 |
108 void ProfileMashs::edit(int recno) |
138 void ProfileMashs::edit(int recno) |
109 { |
139 { |
110 qDebug() << "ProfileMashs edit:" << recno; |
|
111 |
|
112 EditProfileMash dialog(recno, this); |
140 EditProfileMash dialog(recno, this); |
113 /* Signal from editor if a refresh is needed */ |
141 /* Signal from editor if a refresh is needed */ |
114 connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); |
142 connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); |
115 dialog.setModal(true); |
143 dialog.setModal(true); |
116 dialog.exec(); |
144 dialog.exec(); |