From 127db7799ed4847b151a35a16cefab6c494128ef Mon Sep 17 00:00:00 2001 From: Silarn Date: Mon, 23 Dec 2019 23:16:36 -0600 Subject: WIP: Category QObj refactor --- src/categoriesdialog.cpp | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) (limited to 'src/categoriesdialog.cpp') diff --git a/src/categoriesdialog.cpp b/src/categoriesdialog.cpp index 70759419..03a7fc59 100644 --- a/src/categoriesdialog.cpp +++ b/src/categoriesdialog.cpp @@ -136,18 +136,19 @@ void CategoriesDialog::commitChanges() categories->reset(); for (int i = 0; i < ui->categoriesTable->rowCount(); ++i) { - int index = ui->categoriesTable->verticalHeader()->logicalIndex(i); - QString nexusIDString = ui->categoriesTable->item(index, 2)->text(); - QStringList nexusIDStringList = nexusIDString.split(',', Qt::SkipEmptyParts); - std::vector nexusIDs; - for (QStringList::iterator iter = nexusIDStringList.begin(); - iter != nexusIDStringList.end(); ++iter) { - nexusIDs.push_back(iter->toInt()); + int index = ui->categoriesTable->verticalHeader()->logicalIndex(i); + QVariantList nexusData = ui->categoriesTable->item(index, 2)->data(Qt::UserRole).toList(); + std::vector nexusCats; + for (QVariantList::iterator iter = nexusData.begin(); + iter != nexusData.end(); ++iter) { + QVariantList nexusInfo = iter->toList(); + nexusCats.push_back(CategoryFactory::NexusCategory(nexusInfo[0].toString(), nexusInfo[1].toInt())); } categories->addCategory( ui->categoriesTable->item(index, 0)->text().toInt(), - ui->categoriesTable->item(index, 1)->text(), nexusIDs, + ui->categoriesTable->item(index, 1)->text(), + nexusCats, ui->categoriesTable->item(index, 3)->text().toInt()); } categories->setParents(); @@ -169,8 +170,8 @@ void CategoriesDialog::refreshIDs() void CategoriesDialog::fillTable() { - CategoryFactory& categories = CategoryFactory::instance(); - QTableWidget* table = ui->categoriesTable; + CategoryFactory* categories = CategoryFactory::instance(); + QTableWidget* table = ui->categoriesTable; #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) table->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed); @@ -198,9 +199,8 @@ void CategoriesDialog::fillTable() 3, new ValidatingDelegate(this, new ExistingIDValidator(m_IDs))); int row = 0; - for (std::vector::const_iterator iter = - categories.m_Categories.begin(); - iter != categories.m_Categories.end(); ++iter, ++row) { + for (std::vector::const_iterator iter = categories->m_Categories.begin(); + iter != categories->m_Categories.end(); ++iter, ++row) { const CategoryFactory::Category& category = *iter; if (category.m_ID == 0) { --row; @@ -213,14 +213,23 @@ void CategoriesDialog::fillTable() idItem->setData(Qt::DisplayRole, category.m_ID); QScopedPointer nameItem(new QTableWidgetItem(category.m_Name)); - QScopedPointer nexusIDItem( - new QTableWidgetItem(MOBase::VectorJoin(category.m_NexusIDs, ","))); + QStringList nexusLabel; + QVariantList nexusData; + for (auto iter = category.m_NexusCats.begin(); iter < category.m_NexusCats.end(); ++iter) { + nexusLabel.append(iter->m_Name); + QVariantList data; + data.append(QVariant(iter->m_Name)); + data.append(QVariant(iter->m_ID)); + nexusData.append(data); + } + QScopedPointer nexusCatItem(new QTableWidgetItem(nexusLabel.join(", "))); + nexusCatItem->setData(Qt::UserRole, nexusData); QScopedPointer parentIDItem(new QTableWidgetItem()); parentIDItem->setData(Qt::DisplayRole, category.m_ParentID); table->setItem(row, 0, idItem.take()); table->setItem(row, 1, nameItem.take()); - table->setItem(row, 2, nexusIDItem.take()); + table->setItem(row, 2, nexusCatItem.take()); table->setItem(row, 3, parentIDItem.take()); } -- cgit v1.3.1