Skip to content

Commit 4f3f733

Browse files
committed
Implemented dialog to show chip database
1 parent a9bc710 commit 4f3f733

11 files changed

+323
-3
lines changed

qt/chip_db.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,8 @@ uint32_t ChipDb::pageSizeGetByName(const QString &name)
127127

128128
return info ? info->params[CHIP_PARAM_PAGE_SIZE] : 0;
129129
}
130+
131+
int ChipDb::size()
132+
{
133+
return chipInfoVector.size();
134+
}

qt/chip_db.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class ChipDb : public QObject
6363
QStringList *getNames();
6464
ChipInfo *chipInfoGetByName(const QString &name);
6565
uint32_t pageSizeGetByName(const QString &name);
66+
int size();
67+
68+
ChipInfo *operator[](int index) { return &chipInfoVector[index]; }
6669
};
6770

6871

qt/chip_db_dialog.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "chip_db_dialog.h"
2+
#include "ui_chip_db_dialog.h"
3+
4+
#define HEADER_LONG_WIDTH 100
5+
#define HEADER_SHORT_WIDTH 50
6+
7+
ChipDbDialog::ChipDbDialog(ChipDb *chipDb, QWidget *parent) : QDialog(parent),
8+
ui(new Ui::ChipDbDialog), chipDbTableModel(chipDb, parent)
9+
{
10+
ui->setupUi(this);
11+
chipDbProxyModel.setSourceModel(&chipDbTableModel);
12+
ui->chipDbTableView->setModel(&chipDbProxyModel);
13+
ui->chipDbTableView->setColumnWidth(CHIP_PARAM_NAME, HEADER_LONG_WIDTH);
14+
ui->chipDbTableView->setColumnWidth(CHIP_PARAM_PAGE_SIZE,
15+
HEADER_LONG_WIDTH);
16+
ui->chipDbTableView->setColumnWidth(CHIP_PARAM_BLOCK_SIZE,
17+
HEADER_LONG_WIDTH);
18+
ui->chipDbTableView->setColumnWidth(CHIP_PARAM_SIZE, HEADER_LONG_WIDTH);
19+
for (int i = CHIP_PARAM_SIZE + 1; i < CHIP_PARAM_NUM; i++)
20+
ui->chipDbTableView->setColumnWidth(i, HEADER_SHORT_WIDTH);
21+
}
22+
23+
ChipDbDialog::~ChipDbDialog()
24+
{
25+
delete ui;
26+
}

qt/chip_db_dialog.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef CHIP_DB_DALOG_H
2+
#define CHIP_DB_DALOG_H
3+
4+
#include "chip_db_table_model.h"
5+
#include <QDialog>
6+
#include <QSortFilterProxyModel>
7+
8+
namespace Ui {
9+
class ChipDbDialog;
10+
}
11+
12+
class ChipDbDialog : public QDialog
13+
{
14+
Q_OBJECT
15+
16+
Ui::ChipDbDialog *ui;
17+
ChipDbTableModel chipDbTableModel;
18+
QSortFilterProxyModel chipDbProxyModel;
19+
20+
public:
21+
explicit ChipDbDialog(ChipDb *chipDb, QWidget *parent = nullptr);
22+
~ChipDbDialog();
23+
};
24+
25+
#endif // CHIP_DB_DALOG_H

qt/chip_db_dialog.ui

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>ChipDbDialog</class>
4+
<widget class="QDialog" name="ChipDbDialog">
5+
<property name="windowModality">
6+
<enum>Qt::ApplicationModal</enum>
7+
</property>
8+
<property name="geometry">
9+
<rect>
10+
<x>0</x>
11+
<y>0</y>
12+
<width>1150</width>
13+
<height>600</height>
14+
</rect>
15+
</property>
16+
<property name="sizePolicy">
17+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
18+
<horstretch>0</horstretch>
19+
<verstretch>0</verstretch>
20+
</sizepolicy>
21+
</property>
22+
<property name="maximumSize">
23+
<size>
24+
<width>1150</width>
25+
<height>16777215</height>
26+
</size>
27+
</property>
28+
<property name="windowTitle">
29+
<string>Chip database</string>
30+
</property>
31+
<layout class="QGridLayout" name="gridLayout_2">
32+
<item row="0" column="0">
33+
<layout class="QGridLayout" name="gridLayout">
34+
<property name="sizeConstraint">
35+
<enum>QLayout::SetMaximumSize</enum>
36+
</property>
37+
<item row="0" column="0">
38+
<widget class="QTableView" name="chipDbTableView">
39+
<property name="sizePolicy">
40+
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
41+
<horstretch>0</horstretch>
42+
<verstretch>0</verstretch>
43+
</sizepolicy>
44+
</property>
45+
<property name="minimumSize">
46+
<size>
47+
<width>300</width>
48+
<height>300</height>
49+
</size>
50+
</property>
51+
<property name="sortingEnabled">
52+
<bool>true</bool>
53+
</property>
54+
<attribute name="horizontalHeaderDefaultSectionSize">
55+
<number>70</number>
56+
</attribute>
57+
<attribute name="horizontalHeaderMinimumSectionSize">
58+
<number>30</number>
59+
</attribute>
60+
<attribute name="verticalHeaderDefaultSectionSize">
61+
<number>30</number>
62+
</attribute>
63+
<attribute name="verticalHeaderMinimumSectionSize">
64+
<number>20</number>
65+
</attribute>
66+
</widget>
67+
</item>
68+
<item row="1" column="0">
69+
<widget class="QDialogButtonBox" name="buttonBox">
70+
<property name="orientation">
71+
<enum>Qt::Horizontal</enum>
72+
</property>
73+
<property name="standardButtons">
74+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
75+
</property>
76+
</widget>
77+
</item>
78+
</layout>
79+
</item>
80+
</layout>
81+
</widget>
82+
<resources/>
83+
<connections>
84+
<connection>
85+
<sender>buttonBox</sender>
86+
<signal>accepted()</signal>
87+
<receiver>ChipDbDialog</receiver>
88+
<slot>accept()</slot>
89+
<hints>
90+
<hint type="sourcelabel">
91+
<x>248</x>
92+
<y>254</y>
93+
</hint>
94+
<hint type="destinationlabel">
95+
<x>157</x>
96+
<y>274</y>
97+
</hint>
98+
</hints>
99+
</connection>
100+
<connection>
101+
<sender>buttonBox</sender>
102+
<signal>rejected()</signal>
103+
<receiver>ChipDbDialog</receiver>
104+
<slot>reject()</slot>
105+
<hints>
106+
<hint type="sourcelabel">
107+
<x>316</x>
108+
<y>260</y>
109+
</hint>
110+
<hint type="destinationlabel">
111+
<x>286</x>
112+
<y>274</y>
113+
</hint>
114+
</hints>
115+
</connection>
116+
</connections>
117+
</ui>

qt/chip_db_table_model.cpp

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#include "chip_db_table_model.h"
2+
3+
ChipDbTableModel::ChipDbTableModel(ChipDb *chipDb, QObject *parent) :
4+
QAbstractTableModel(parent)
5+
{
6+
this->chipDb = chipDb;
7+
}
8+
9+
int ChipDbTableModel::rowCount(const QModelIndex & /*parent*/) const
10+
{
11+
return chipDb->size();
12+
}
13+
14+
int ChipDbTableModel::columnCount(const QModelIndex & /*parent*/) const
15+
{
16+
return CHIP_PARAM_NUM;
17+
}
18+
19+
QVariant ChipDbTableModel::data(const QModelIndex &index, int role) const
20+
{
21+
if (role != Qt::DisplayRole)
22+
return QVariant();
23+
24+
switch (index.column())
25+
{
26+
case CHIP_PARAM_NAME:
27+
return (*chipDb)[index.row()]->name;
28+
case CHIP_PARAM_PAGE_SIZE:
29+
return (*chipDb)[index.row()]->params[CHIP_PARAM_PAGE_SIZE];
30+
case CHIP_PARAM_BLOCK_SIZE:
31+
return (*chipDb)[index.row()]->params[CHIP_PARAM_BLOCK_SIZE];
32+
case CHIP_PARAM_SIZE:
33+
return (*chipDb)[index.row()]->params[CHIP_PARAM_SIZE];
34+
case CHIP_PARAM_T_CS:
35+
return (*chipDb)[index.row()]->params[CHIP_PARAM_T_CS];
36+
case CHIP_PARAM_T_CLS:
37+
return (*chipDb)[index.row()]->params[CHIP_PARAM_T_CLS];
38+
case CHIP_PARAM_T_ALS:
39+
return (*chipDb)[index.row()]->params[CHIP_PARAM_T_ALS];
40+
case CHIP_PARAM_T_CLR:
41+
return (*chipDb)[index.row()]->params[CHIP_PARAM_T_CLR];
42+
case CHIP_PARAM_T_AR:
43+
return (*chipDb)[index.row()]->params[CHIP_PARAM_T_AR];
44+
case CHIP_PARAM_T_WP:
45+
return (*chipDb)[index.row()]->params[CHIP_PARAM_T_WP];
46+
case CHIP_PARAM_T_RP:
47+
return (*chipDb)[index.row()]->params[CHIP_PARAM_T_RP];
48+
case CHIP_PARAM_T_DS:
49+
return (*chipDb)[index.row()]->params[CHIP_PARAM_T_DS];
50+
case CHIP_PARAM_T_CH:
51+
return (*chipDb)[index.row()]->params[CHIP_PARAM_T_CH];
52+
case CHIP_PARAM_T_CLH:
53+
return (*chipDb)[index.row()]->params[CHIP_PARAM_T_CLH];
54+
case CHIP_PARAM_T_ALH:
55+
return (*chipDb)[index.row()]->params[CHIP_PARAM_T_ALH];
56+
case CHIP_PARAM_T_WC:
57+
return (*chipDb)[index.row()]->params[CHIP_PARAM_T_WC];
58+
case CHIP_PARAM_T_RC:
59+
return (*chipDb)[index.row()]->params[CHIP_PARAM_T_RC];
60+
case CHIP_PARAM_T_REA:
61+
return (*chipDb)[index.row()]->params[CHIP_PARAM_T_REA];
62+
}
63+
64+
return QVariant();
65+
}
66+
67+
QVariant ChipDbTableModel::headerData(int section, Qt::Orientation orientation,
68+
int role) const
69+
{
70+
if (!(role == Qt::DisplayRole && orientation == Qt::Horizontal))
71+
return QVariant();
72+
73+
switch (section)
74+
{
75+
case CHIP_PARAM_NAME: return tr("Name");
76+
case CHIP_PARAM_PAGE_SIZE: return tr("Page size");
77+
case CHIP_PARAM_BLOCK_SIZE: return tr("Block size");
78+
case CHIP_PARAM_SIZE: return tr("Size");
79+
case CHIP_PARAM_T_CS: return tr("tCH");
80+
case CHIP_PARAM_T_CLS: return tr("tCLS");
81+
case CHIP_PARAM_T_ALS: return tr("tALS");
82+
case CHIP_PARAM_T_CLR: return tr("tCLR");
83+
case CHIP_PARAM_T_AR: return tr("tAR");
84+
case CHIP_PARAM_T_WP: return tr("tWP");
85+
case CHIP_PARAM_T_RP: return tr("tRP");
86+
case CHIP_PARAM_T_DS: return tr("tDS");
87+
case CHIP_PARAM_T_CH: return tr("tCH");
88+
case CHIP_PARAM_T_CLH: return tr("tCLH");
89+
case CHIP_PARAM_T_ALH: return tr("tALH");
90+
case CHIP_PARAM_T_WC: return tr("tWC");
91+
case CHIP_PARAM_T_RC: return tr("tRC");
92+
case CHIP_PARAM_T_REA: return tr("tREA");
93+
}
94+
95+
return QVariant();
96+
}
97+

qt/chip_db_table_model.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef CHIP_DB_TABLE_MODEL_H
2+
#define CHIP_DB_TABLE_MODEL_H
3+
4+
#include "chip_db.h"
5+
#include <QAbstractTableModel>
6+
7+
class ChipDbTableModel : public QAbstractTableModel
8+
{
9+
Q_OBJECT
10+
11+
ChipDb *chipDb;
12+
13+
public:
14+
explicit ChipDbTableModel(ChipDb *chipDb, QObject *parent = nullptr);
15+
int rowCount(const QModelIndex & /*parent*/) const override;
16+
int columnCount(const QModelIndex & /*parent*/) const override;
17+
QVariant data(const QModelIndex &index, int role) const override;
18+
QVariant headerData(int section, Qt::Orientation orientation, int role)
19+
const override;
20+
};
21+
22+
#endif // CHIP_DB_TABLE_MODEL_H

qt/main_window.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "main_window.h"
77
#include "ui_main_window.h"
88
#include "settings_programmer_dialog.h"
9+
#include "chip_db_dialog.h"
910
#include "chip_db.h"
1011
#include "logger.h"
1112
#include <QDebug>
@@ -80,6 +81,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
8081
SLOT(slotProgReadBadBlocks()));
8182
connect(ui->actionProgrammer, SIGNAL(triggered()), this,
8283
SLOT(slotSettingsProgrammer()));
84+
connect(ui->actionChipDb, SIGNAL(triggered()), this,
85+
SLOT(slotSettingsChipDb()));
8386
}
8487

8588
MainWindow::~MainWindow()
@@ -403,3 +406,13 @@ void MainWindow::slotSettingsProgrammer()
403406
prog->setSkipBB(progDialog.isSkipBB());
404407
}
405408
}
409+
410+
void MainWindow::slotSettingsChipDb()
411+
{
412+
ChipDbDialog chipDbDialog(&chipDb, this);
413+
414+
if (chipDbDialog.exec() == QDialog::Accepted)
415+
{
416+
417+
}
418+
}

qt/main_window.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public slots:
5656
void slotProgReadBadBlocks();
5757
void slotSelectChip(int selectedChipNum);
5858
void slotSettingsProgrammer();
59+
void slotSettingsChipDb();
5960
};
6061

6162
#endif // MAIN_WINDOW_H

qt/main_window.ui

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@
234234
<string>Settings</string>
235235
</property>
236236
<addaction name="actionProgrammer"/>
237+
<addaction name="actionChipDb"/>
237238
</widget>
238239
<addaction name="menuFile"/>
239240
<addaction name="menuProgrammer"/>
@@ -320,6 +321,11 @@
320321
<string>Read bad blocks</string>
321322
</property>
322323
</action>
324+
<action name="actionChipDb">
325+
<property name="text">
326+
<string>Chip database</string>
327+
</property>
328+
</action>
323329
</widget>
324330
<layoutdefault spacing="6" margin="11"/>
325331
<resources/>

0 commit comments

Comments
 (0)