Skip to content

Commit

Permalink
consolidate table data, fix combobox table item
Browse files Browse the repository at this point in the history
  • Loading branch information
enderslash1010 committed Jan 3, 2025
1 parent 6d6b4d3 commit 3e83279
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
33 changes: 17 additions & 16 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,35 +263,36 @@ void MainWindow::connect(SaveFieldID sfID, QExtendedSlider* slider, int start, i
slider->setScaling(start, spacing, count);
}

// TODO: consolidate these into struct?
const int MINE_ARRAY_ROW_COUNT = 150;
const Mapping MINEArrayMapping =
{
{MINE_MapID, MINE_MineID, MINE_NumHarvests, MINE_Cooldown},
{"Map ID", "Mine ID", "Number of Harvests", "Cooldown"}
const TableDefinition MINEArrayDefinition
{
150, // row count
{ // array mapping
{MINE_MapID, MINE_MineID, MINE_NumHarvests, MINE_Cooldown},
{"Map ID", "Mine ID", "Number of Harvests", "Cooldown"}
},
{QExtendedComboBox_T, QExtendedLineEdit_T, QExtendedLineEdit_T, QExtendedLineEdit_T},
{&MapMapping, nullptr, nullptr, nullptr}
};
QList<ExtendedWidgetType> MINEArrayWidgetTypes = {QExtendedComboBox_T, QExtendedLineEdit_T, QExtendedLineEdit_T, QExtendedLineEdit_T};
QList<const Mapping*> MINEArrayColumnMapping = {&MapMapping, nullptr, nullptr, nullptr};

// QTableWidget
void MainWindow::connect(SaveFieldID sfID, QExtendedTableWidget* table, const int rowCount, const Mapping* mapping, QList<ExtendedWidgetType> columnTypes)
void MainWindow::connect(SaveFieldID sfID, QExtendedTableWidget* table, const TableDefinition* def)
{
table->setRowCount(rowCount);
table->setColumnCount(std::size(mapping->keys));
table->setRows(rowCount);
table->setCols(std::size(mapping->keys));
table->setRowCount(def->row_count);
table->setColumnCount(std::size(def->array_mapping.keys));
table->setRows(def->row_count);
table->setCols(std::size(def->array_mapping.keys));

QHeaderView* header = table->horizontalHeader();
header->setSectionResizeMode(QHeaderView::Stretch);

table->setHorizontalHeaderLabels(mapping->values);
table->setHorizontalHeaderLabels(def->array_mapping.values);

table->setProperty(SAVE_FIELD_PROPERTY, sfID);
table->setSaveFieldID(sfID);

saveFieldMap.insert({sfID, {table, Type::ARRAY_T}});

table->setup(rowCount, MINEArrayWidgetTypes, MINEArrayColumnMapping, &MINEArrayMapping);
table->setup(&MINEArrayDefinition);

QObject::connect(table, &QExtendedTableWidget::tableCellChanged, this, &MainWindow::updateTable);
}
Expand Down Expand Up @@ -389,7 +390,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(WTHRUnk2, ui->WTHRUnk2, Type::UINT_T);

// MINE
connect(MINEArray, ui->MINEArray, MINE_ARRAY_ROW_COUNT, &MINEArrayMapping, MINEArrayWidgetTypes);
connect(MINEArray, ui->MINEArray, &MINEArrayDefinition);

// TBOX

Expand Down
2 changes: 1 addition & 1 deletion gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MainWindow : public QMainWindow
void connect(SaveFieldID sfID, QExtendedComboBox* thisComboBox, QExtendedComboBox* sourceComboBox, std::vector<const Mapping*>& dynamicMapping);
void connect(SaveFieldID sfID, QExtendedRadioButtons* radioButtonFrame, std::unordered_map<QString, QRadioButton*>& rbs);
void connect(SaveFieldID sfID, QExtendedSlider* slider, int start, int spacing, int count);
void connect(SaveFieldID sfID, QExtendedTableWidget* table, const int rowCount, const Mapping* mapping, QList<ExtendedWidgetType> columnTypes);
void connect(SaveFieldID sfID, QExtendedTableWidget* table, const TableDefinition* def);

void setField(SaveFieldID sfID);
QString getField(SaveFieldID sfID, int row = 0, int col = 0);
Expand Down
24 changes: 15 additions & 9 deletions include/QExtendedWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,14 @@ class QExtendedSlider : public QSlider, public QExtendedWidget
}
};

struct TableDefinition
{
int row_count;
Mapping array_mapping;
QList<ExtendedWidgetType> widget_types;
QList<const Mapping*> column_mapping;
};

class QExtendedTableWidget : public QTableWidget, public QExtendedWidget
{
Q_OBJECT
Expand All @@ -247,15 +255,15 @@ private slots:
public:

QExtendedTableWidget(QWidget* parent = nullptr) : QTableWidget(parent) { }
void setup(int rows, QList<ExtendedWidgetType> types, QList<const Mapping*> columnMapping, const Mapping* tableMapping)
void setup(const TableDefinition* def)
{
this->tableMapping = tableMapping;
for (int row = 0; row < rows; row++)
this->tableMapping = &def->array_mapping;
for (int row = 0; row < def->row_count; row++)
{
std::vector<QExtendedWidget*> newRow;
for (int col = 0; col < types.size(); col++)
for (int col = 0; col < def->widget_types.size(); col++)
{
switch (types.at(col))
switch (def->widget_types.at(col))
{
case QExtendedLineEdit_T:
{
Expand All @@ -276,10 +284,8 @@ private slots:
cb->setEditable(true);
newRow.push_back(cb);
this->setCellWidget(row, col, cb);
if (columnMapping.at(col) != nullptr) cb->setMapping(columnMapping.at(col));

if (cb->lineEdit() != nullptr) QObject::connect(cb->lineEdit(), &QLineEdit::editingFinished, this, &QExtendedTableWidget::cellEdited);
else QObject::connect(cb, &QComboBox::currentTextChanged, this, &QExtendedTableWidget::cellEdited);
if (def->column_mapping.at(col) != nullptr) cb->setMapping(def->column_mapping.at(col));
QObject::connect(cb, &QComboBox::currentTextChanged, this, &QExtendedTableWidget::cellEdited);

cb->setProperty("row", row);
cb->setProperty("column", col);
Expand Down

0 comments on commit 3e83279

Please sign in to comment.