Created
October 20, 2013 04:18
-
-
Save MarianoGnu/7065022 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "dialogdatabase.h" | |
#include "ui_dialogdatabase.h" | |
#include <QPushButton> | |
#include <QInputDialog> | |
#include <sstream> | |
#include <iomanip> | |
DialogDataBase::DialogDataBase(QWidget *parent) : | |
QDialog(parent), | |
ui(new Ui::DialogDataBase) | |
{ | |
ui->setupUi(this); | |
characters = new GameCharacterModel(this); | |
ui->tableNew_CharacterProperties->setModel(characters); | |
} | |
DialogDataBase::~DialogDataBase() | |
{ | |
delete ui; | |
} | |
void DialogDataBase::on_toolSwitchStyle_clicked(bool checked) | |
{ | |
if (checked) | |
ui->stackedStyle->setCurrentIndex(1); | |
else | |
ui->stackedStyle->setCurrentIndex(0); | |
} | |
void DialogDataBase::on_tabOld_Pages_currentChanged(int index) | |
{ | |
ui->listNew_Pages->setCurrentRow(index); | |
} | |
void DialogDataBase::on_pushOld_CharacterMax_clicked() | |
{ | |
bool b_ok; | |
int n_num = QInputDialog::getInt(this,"Change Maximum Number", "Maximum Number", ui->listOld_Character->currentRow(), 1, 5000,1, &b_ok); | |
if (b_ok){ | |
if (n_num < ui->listOld_Character->count()) | |
for (int i = ui->listOld_Character->count(); i > n_num; i--){ | |
QListWidgetItem *itm = ui->listOld_Character->takeItem(i-1); | |
delete itm; | |
} | |
else{ | |
std::stringstream ss; | |
for (int i = ui->listOld_Character->count(); i < n_num; i++){ | |
ss.str(""); | |
ss << std::setfill('0') << std::setw(4) << i + 1 << ": "; | |
ui->listOld_Character->insertItem(i, QString::fromStdString(ss.str())); | |
} | |
} | |
} | |
} | |
void DialogDataBase::on_toolNew_AddCharacter_clicked() | |
{ | |
bool selected = ui->tableNew_CharacterProperties->currentIndex().row() >= 0 && ui->tableNew_CharacterProperties->currentIndex().row() < characters->rowCount(); | |
characters->insertRows(selected? ui->tableNew_CharacterProperties->currentIndex().row() : characters->rowCount() - 1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef DIALOGDATABASE_H | |
#define DIALOGDATABASE_H | |
#include <QDialog> | |
#include "gamecharactermodel.h" | |
namespace Ui { | |
class DialogDataBase; | |
} | |
class DialogDataBase : public QDialog | |
{ | |
Q_OBJECT | |
public: | |
explicit DialogDataBase(QWidget *parent = 0); | |
~DialogDataBase(); | |
private slots: | |
void on_toolSwitchStyle_clicked(bool checked); | |
void on_tabOld_Pages_currentChanged(int index); | |
void on_pushOld_CharacterMax_clicked(); | |
void on_toolNew_AddCharacter_clicked(); | |
private: | |
Ui::DialogDataBase *ui; | |
GameCharacterModel *characters; | |
}; | |
#endif // DIALOGDATABASE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "gamecharactermodel.h" | |
#include <QDebug> | |
GameCharacterModel::GameCharacterModel(QObject *parent) : | |
QAbstractTableModel(parent) | |
{ | |
itemData = QVector< QVector<QVariant> >(); | |
customTypes = QVector<PropertyType>(); | |
emit headerDataChanged(Qt::Horizontal,0,columnCount() - 1); | |
} | |
Qt::ItemFlags GameCharacterModel::flags(const QModelIndex &index) const | |
{ | |
Q_UNUSED (index); | |
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; | |
} | |
QVariant GameCharacterModel::data(const QModelIndex &index, int role) const | |
{ | |
if (role != Qt::DisplayRole || role != Qt::EditRole) | |
return QVariant(); | |
if ((index.row() >= 0 && index.row() < rowCount(QModelIndex())) || | |
(index.column() >= 0 && index.column() < columnCount(QModelIndex()))) | |
return itemData[index.row()][index.column()]; | |
return QVariant(); | |
} | |
QVariant GameCharacterModel::headerData(int section, Qt::Orientation orientation, int role) | |
{ | |
if (role != Qt::DisplayRole || orientation != Qt::Horizontal) | |
return QVariant(); | |
if (section >= COL_COUNT && section < COL_COUNT + customNames.count() - 2) | |
return customNames[section - COL_COUNT]; | |
switch (section) | |
{ | |
case (COL_NAME): | |
return tr("Name"); | |
case (COL_TITLE): | |
return tr("Title"); | |
case (COL_MINLVL): | |
return tr("MinLv"); | |
case (COL_MAXLVL): | |
return tr("MaxLv"); | |
case (COL_DOCRITICAL): | |
return tr("DoCritical"); | |
case (COL_CRITICAL): | |
return tr("Critical"); | |
case (COL_DUALWEAPONS): | |
return tr("DualWeapons"); | |
case (COL_FIXEDEQUIP): | |
return tr("FixedEquip"); | |
case (COL_AI): | |
return tr("A.I."); | |
case (COL_STRONGDEFENSE): | |
return tr("StrDef"); | |
case (COL_PROFESSION): | |
return tr("Profession"); | |
case (COL_FACE): | |
return tr("Face"); | |
case (COL_CHARA): | |
return tr("Charaset"); | |
case (COL_BATTLER): | |
return tr("Battler"); | |
case (COL_HPCURVE): | |
return tr("Hp"); | |
case (COL_MPCURVE): | |
return tr("Mp"); | |
case (COL_ATTACKCURVE): | |
return tr("Attack"); | |
case (COL_DEFENSECURVE): | |
return tr("Defense"); | |
case (COL_INTELLIGENCECURVE): | |
return tr("Intelligence"); | |
case (COL_AGILITYCURVE): | |
return tr("Agility"); | |
case (COL_EXPCURVE): | |
return tr("Experience"); | |
case (COL_INITIALWEAPON): | |
return tr("InitWeapon"); | |
case (COL_INITIALSHIELD): | |
return tr("InitShield"); | |
case (COL_INITIALARMOR): | |
return tr("InitArmor"); | |
case (COL_INITIALHELMET): | |
return tr("InitHelmet"); | |
case (COL_INITIALOTHER): | |
return tr("InitMisc"); | |
case (COL_UNARMEDANIMATION): | |
return tr("UnarmedAnimation"); | |
case (COL_SKILLS): | |
return tr("Skills"); | |
case (COL_ATTRIBUTERANKS): | |
return tr("AttRanks"); | |
case (COL_STATUSRANKS): | |
return tr("StsRanks"); | |
} | |
return QVariant(); | |
} | |
int GameCharacterModel::rowCount(const QModelIndex &parent) const | |
{ | |
Q_UNUSED (parent); | |
return itemData.count(); | |
} | |
int GameCharacterModel::columnCount(const QModelIndex &parent) const | |
{ | |
Q_UNUSED (parent); | |
return (COL_COUNT + customNames.count()); | |
} | |
bool GameCharacterModel::setData(const QModelIndex &index, const QVariant &value, int role) | |
{ | |
if (role != Qt::EditRole) | |
return false; | |
if ((index.row() >= 0 && index.row() < rowCount(QModelIndex())) || | |
(index.column() >= 0 && index.column() < columnCount(QModelIndex()))) { | |
itemData[index.row()][index.column()] = value; | |
emit dataChanged(index, index); | |
return true; | |
} | |
return false; | |
} | |
bool GameCharacterModel::setHeaderData(int section, Qt::Orientation orientation, | |
const QVariant &value, int role) | |
{ | |
if (role != Qt::DisplayRole || orientation != Qt::Horizontal) | |
return false; | |
if (section >= COL_COUNT && section < columnCount()){ | |
customNames[section - COL_COUNT] = value.toString(); | |
emit headerDataChanged(orientation, section, section); | |
return true; | |
} | |
return false; | |
} | |
bool GameCharacterModel::insertRows(int row, const QModelIndex &parent) | |
{ | |
beginInsertRows(parent,row, row); | |
itemData.insert(row, QVector<QVariant>(columnCount())); | |
/* Default Values */ | |
setData(createIndex(row,COL_NAME), QVariant("")); | |
setData(createIndex(row,COL_TITLE), QVariant("Name")); | |
setData(createIndex(row,COL_MINLVL), QVariant(1)); | |
setData(createIndex(row,COL_MAXLVL), QVariant(99)); | |
setData(createIndex(row,COL_DOCRITICAL), QVariant(true)); | |
setData(createIndex(row,COL_CRITICAL), QVariant(30)); | |
setData(createIndex(row,COL_DUALWEAPONS), QVariant(false)); | |
setData(createIndex(row,COL_FIXEDEQUIP), QVariant(false)); | |
setData(createIndex(row,COL_AI), QVariant(false)); | |
setData(createIndex(row,COL_STRONGDEFENSE), QVariant(false)); | |
setData(createIndex(row,COL_PROFESSION), QVariant(-1)); | |
setData(createIndex(row,COL_FACE), QVariant(-1)); | |
setData(createIndex(row,COL_CHARA), QVariant(-1)); | |
setData(createIndex(row,COL_BATTLER), QVariant(0)); | |
setData(createIndex(row,COL_HPCURVE), QVariant(0)); | |
setData(createIndex(row,COL_MPCURVE), QVariant(0)); | |
setData(createIndex(row,COL_ATTACKCURVE), QVariant(0)); | |
setData(createIndex(row,COL_DEFENSECURVE), QVariant(0)); | |
setData(createIndex(row,COL_INTELLIGENCECURVE), QVariant(0)); | |
setData(createIndex(row,COL_AGILITYCURVE), QVariant(0)); | |
setData(createIndex(row,COL_EXPCURVE), QVariant(0)); | |
setData(createIndex(row,COL_INITIALWEAPON), QVariant(-1)); | |
setData(createIndex(row,COL_INITIALSHIELD), QVariant(-1)); | |
setData(createIndex(row,COL_INITIALARMOR), QVariant(-1)); | |
setData(createIndex(row,COL_INITIALHELMET), QVariant(-1)); | |
setData(createIndex(row,COL_INITIALOTHER), QVariant(-1)); | |
setData(createIndex(row,COL_UNARMEDANIMATION), QVariant(0)); | |
setData(createIndex(row,COL_SKILLS), QVariant(0)); | |
setData(createIndex(row,COL_ATTRIBUTERANKS), QVariant(0)); | |
setData(createIndex(row,COL_STATUSRANKS), QVariant(0)); | |
endInsertRows(); | |
return true; | |
} | |
bool GameCharacterModel::removeRows(int /*row*/, int /*count*/, const QModelIndex &/*parent*/) | |
{ | |
return true; | |
} | |
bool GameCharacterModel::insertColumns(int /*column*/, const QModelIndex &/*parent*/) | |
{ | |
return true; | |
} | |
bool GameCharacterModel::removeColumns(int /*column*/, int /*count*/, const QModelIndex &/*parent*/) | |
{ | |
return true; | |
} | |
QModelIndex GameCharacterModel::index(int row, int column, const QModelIndex &parent) const | |
{ | |
if (!hasIndex(row, column, parent)) | |
return QModelIndex(); | |
return createIndex(row, column); | |
} | |
QModelIndex GameCharacterModel::parent(const QModelIndex &child) const | |
{ | |
Q_UNUSED (child); | |
return QModelIndex(); //This model has not nested data. | |
} | |
bool GameCharacterModel::setCustomPropertyName(const int c_id, const QString c_name) | |
{ | |
return setHeaderData(COL_COUNT+c_id,Qt::Horizontal, c_name, Qt::DisplayRole); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef GAMECHARACTERMODEL_H | |
#define GAMECHARACTERMODEL_H | |
#include <QAbstractItemModel> | |
#include <QStringList> | |
class GameCharacterModel : public QAbstractTableModel | |
{ | |
Q_OBJECT | |
public: | |
enum Column | |
{ | |
COL_NAME = 0, | |
COL_TITLE, | |
COL_MINLVL, | |
COL_MAXLVL, | |
COL_DOCRITICAL, | |
COL_CRITICAL, | |
COL_DUALWEAPONS, | |
COL_FIXEDEQUIP, | |
COL_AI, | |
COL_STRONGDEFENSE, | |
COL_PROFESSION, | |
COL_FACE, | |
COL_CHARA, | |
COL_BATTLER, | |
COL_HPCURVE, | |
COL_MPCURVE, | |
COL_ATTACKCURVE, | |
COL_DEFENSECURVE, | |
COL_INTELLIGENCECURVE, | |
COL_AGILITYCURVE, | |
COL_EXPCURVE, | |
COL_INITIALWEAPON, | |
COL_INITIALSHIELD, | |
COL_INITIALARMOR, | |
COL_INITIALHELMET, | |
COL_INITIALOTHER, | |
COL_UNARMEDANIMATION, | |
COL_SKILLS, | |
COL_ATTRIBUTERANKS, | |
COL_STATUSRANKS, | |
COL_COUNT | |
}; | |
enum PropertyType { | |
INTEGER, | |
STRING, | |
EDITBUTTON, | |
INDEXOFHERO, | |
INDEXOFPROFESSION, | |
INDEXOFSKILL, | |
INDEXOFITEM, | |
INDEXOFENEMY, | |
INDEXOFTROOP, | |
INDEXOFATTRIBUTE, | |
INDEXOFSTATUS, | |
INDEXOFBATTLEANIMATION, | |
INDEXOFBATTLEANIMATION2, | |
INDEXOFTERRAIN, | |
INDEXOFCHIPSET, | |
INDEXOFCOMMONEVENT | |
}; | |
explicit GameCharacterModel(QObject *parent = 0); | |
/*Item data handling*/ | |
Qt::ItemFlags flags(const QModelIndex &index) const; | |
QVariant data(const QModelIndex &index, int role) const; | |
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole); | |
bool isValid(); | |
int rowCount(const QModelIndex &parent = QModelIndex()) const; | |
int columnCount(const QModelIndex &parent = QModelIndex()) const; | |
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); | |
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role); | |
bool insertRows(int row, const QModelIndex &parent = QModelIndex()); | |
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); | |
bool insertColumns(int column, const QModelIndex &parent = QModelIndex()); | |
bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()); | |
/*Navigation and model index creation*/ | |
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; | |
QModelIndex parent(const QModelIndex &child) const; | |
bool setCustomPropertyName(const int c_id, const QString c_name); | |
signals: | |
public slots: | |
private: | |
QVector< QVector<QVariant> > itemData; | |
QStringList customNames; | |
QVector<PropertyType> customTypes; | |
}; | |
#endif // GAMECHARACTERMODEL_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment