void DefinitionManager::selectedPack(QTableWidgetItem *item, QTableWidgetItem *) { emit packSelected(item != NULL); if (item != NULL) selected = item->data(Qt::UserRole).toString(); else selected = QString(); }
DefinitionManager::DefinitionManager(QWidget *parent) : QWidget(parent), isUpdating(false), dimensionManager(DimensionIdentifier::Instance()), blockManager(BlockIdentifier::Instance()), biomeManager(BiomeIdentifier::Instance()), entityManager(EntityIdentifier::Instance()), flatteningConverter(FlatteningConverter::Instance()) { setWindowFlags(Qt::Window); setWindowTitle(tr("Definitions")); QVBoxLayout *layout = new QVBoxLayout; QStringList labels; labels << tr("Name") << tr("Version") << tr("Type"); table = new QTableWidget(0, 3); table->setHorizontalHeaderLabels(labels); table->horizontalHeader()->setSectionResizeMode( QHeaderView::ResizeToContents); table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); table->horizontalHeader()->setHighlightSections(false); table->verticalHeader()->hide(); table->setShowGrid(false); table->setSelectionBehavior(QAbstractItemView::SelectRows); layout->addWidget(table, 1); QWidget *buttonBar = new QWidget; QHBoxLayout *buttons = new QHBoxLayout; QPushButton *add = new QPushButton(tr("Add Pack...")); connect(add, SIGNAL(clicked()), this, SLOT(addPack())); buttons->addWidget(add); QPushButton *remove = new QPushButton(tr("Remove Pack")); connect(remove, SIGNAL(clicked()), this, SLOT(removePack())); connect(this, SIGNAL(packSelected(bool)), remove, SLOT(setEnabled(bool))); buttons->addWidget(remove); QPushButton *save = new QPushButton(tr("Export Pack...")); connect(save, SIGNAL(clicked()), this, SLOT(exportPack())); connect(this, SIGNAL(packSelected(bool)), save, SLOT(setEnabled(bool))); buttons->addWidget(save); buttonBar->setLayout(buttons); layout->addWidget(buttonBar, 0); emit packSelected(false); setLayout(layout); QSettings settings; sorted = settings.value("packs").toList(); // clean old hashed files without extra seed QString destdir = QStandardPaths::writableLocation(QStandardPaths::DataLocation); const QStringList old_hashed_list { "1050220429", "1241760321", "1443276275", "1798448990", "2422344665" }; for ( const auto& old_hashed_file : old_hashed_list ) { QString old_path = destdir + "/" + old_hashed_file + ".json"; QFile::remove(old_path); sorted.removeOne(old_path); } // copy over built-in definitions if necessary QDir dir; dir.mkpath(destdir); QDirIterator it(":/definitions", QDir::Files | QDir::Readable); while (it.hasNext()) { it.next(); installJson(it.filePath(), false, false); } settings.setValue("packs", sorted); // we load the definitions backwards for priority. for (int i = sorted.length() - 1; i >= 0; i--) loadDefinition(sorted[i].toString()); // hook up table selection signal connect(table, SIGNAL(currentItemChanged(QTableWidgetItem*, QTableWidgetItem*)), this, SLOT(selectedPack(QTableWidgetItem*, QTableWidgetItem*))); // fill out table refresh(); }
DefinitionManager::DefinitionManager(QWidget *parent) : QWidget(parent) { setWindowFlags(Qt::Window); setWindowTitle(tr("Definitions")); QVBoxLayout *layout=new QVBoxLayout; QStringList labels; labels<<tr("Name")<<tr("Version")<<tr("Type"); //<<tr("Active"); table=new QTableWidget(0,3); table->setHorizontalHeaderLabels(labels); table->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); table->horizontalHeader()->setSectionResizeMode(0,QHeaderView::Stretch); table->horizontalHeader()->setHighlightSections(false); table->verticalHeader()->hide(); table->setShowGrid(false); table->setSelectionBehavior(QAbstractItemView::SelectRows); layout->addWidget(table,1); QWidget *buttonBar=new QWidget; QHBoxLayout *buttons=new QHBoxLayout; QPushButton *add=new QPushButton(tr("Add Pack...")); connect(add,SIGNAL(clicked()), this,SLOT(addPack())); buttons->addWidget(add); QPushButton *remove=new QPushButton(tr("Remove Pack")); connect(remove,SIGNAL(clicked()), this,SLOT(removePack())); connect(this,SIGNAL(packSelected(bool)), remove,SLOT(setEnabled(bool))); buttons->addWidget(remove); QPushButton *save=new QPushButton(tr("Export Pack...")); connect(save,SIGNAL(clicked()), this,SLOT(exportPack())); connect(this,SIGNAL(packSelected(bool)), save,SLOT(setEnabled(bool))); buttons->addWidget(save); buttonBar->setLayout(buttons); layout->addWidget(buttonBar,0); emit packSelected(false); setLayout(layout); dimensionList = new Dimensions; blocks=new BlockIdentifier; biomes=new BiomeIdentifier; QSettings settings; sorted=settings.value("packs").toList(); lastUpdated=settings.value("packupdates").toHash(); //copy over built-in definitions if necessary QString defdir=QStandardPaths::writableLocation(QStandardPaths::DataLocation); QDir dir; dir.mkpath(defdir); QDirIterator it(":/definitions",QDir::Files|QDir::Readable); while (it.hasNext()) { it.next(); installJson(it.filePath(),false,false); } settings.setValue("packs",sorted); // we load the definitions backwards for priority. for (int i=sorted.length()-1;i>=0;i--) loadDefinition(sorted[i].toString()); //hook up table selection signal connect(table,SIGNAL(currentItemChanged(QTableWidgetItem*,QTableWidgetItem*)), this, SLOT(selectedPack(QTableWidgetItem*,QTableWidgetItem*))); //fill out table refresh(); }