Skip to content

Commit

Permalink
Version 0.3.1.
Browse files Browse the repository at this point in the history
- Changed C++ standard from C++11 to C++14 (it's time to start using std::make_unique).
- Fixed the crash occurring when showing an animation from CC UOP.
- Added const_iterator to ScriptObjTree.
- Tidied the ScriptSearch/SubDlg_SearchObj code.
- Changed some unscoped enums to enum class.
- Changed UOIdx::unknown to extra.

UOPPackage library version 3.2.
- Added iterators to UOPPackage and UOPBlock.
- Changed some data types from signed to unsigned (block&file number, addresses).
- Added UOPFile::freeData and hasData methods.
- Removed unused UOPHeader.cpp/.h.
  • Loading branch information
cbnolok committed Sep 7, 2018
1 parent f1837da commit 7fd03ba
Show file tree
Hide file tree
Showing 37 changed files with 767 additions and 495 deletions.
4 changes: 1 addition & 3 deletions src/Leviathan.pro
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Leviathan
TEMPLATE = app

CONFIG += c++11
CONFIG += c++14

RESOURCES = leviathan_resources.qrc

Expand Down Expand Up @@ -66,7 +66,6 @@ SOURCES += \
uoppackage/uoperror.cpp \
uoppackage/uopfile.cpp \
uoppackage/uophash.cpp \
uoppackage/uopheader.cpp \
uoppackage/uoppackage.cpp \
cpputils/strings.cpp \
cpputils/sysio.cpp
Expand Down Expand Up @@ -130,7 +129,6 @@ HEADERS += \
uoppackage/uoperror.h \
uoppackage/uopfile.h \
uoppackage/uophash.h \
uoppackage/uopheader.h \
uoppackage/uoppackage.h \
cpputils/maps.h

Expand Down
20 changes: 5 additions & 15 deletions src/forms/dlg_huepicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void Dlg_HuePicker::on_pushButton_set_clicked()
{
std::string strToSend = ".xcolor " + std::to_string(m_selectedHueIndex + 1);
auto ksResult = ks::KeystrokeSender::sendStringFastAsync(strToSend, true, g_sendKeystrokeAndFocusClient);
if (ksResult != ks::KSERR_OK)
if (ksResult != ks::KSError::Ok)
{
QMessageBox errorDlg(QMessageBox::Warning, "Warning", ks::getErrorStringStatic(ksResult), QMessageBox::NoButton, this);
errorDlg.exec();
Expand All @@ -253,7 +253,7 @@ void Dlg_HuePicker::on_pushButton_setClose_clicked()
{
std::string strToSend = ".xcolor " + std::to_string(m_selectedHueIndex);
auto ksResult = ks::KeystrokeSender::sendStringFastAsync(strToSend, true, g_sendKeystrokeAndFocusClient);
if (ksResult != ks::KSERR_OK)
if (ksResult != ks::KSError::Ok)
{
QMessageBox errorDlg(QMessageBox::Warning, "Warning", ks::getErrorStringStatic(ksResult), QMessageBox::NoButton, this);
errorDlg.exec();
Expand All @@ -279,14 +279,13 @@ void Dlg_HuePicker::on_lineEdit_preview_returnPressed()
if (ui->lineEdit_preview->text().isEmpty())
return;

ScriptSearch::SearchData_t sd;
ScriptSearch::SearchData sd;
sd.caseSensitive = false;
sd.key = ui->lineEdit_preview->text().toStdString();
if (ScriptUtils::strToSphereInt(sd.key) == -1)
sd.searchBy = ScriptSearch::SearchBy_t::Defname;
sd.searchBy = ScriptSearch::SearchBy::Defname;
else
sd.searchBy = ScriptSearch::SearchBy_t::ID;
sd.initialized = true;
sd.searchBy = ScriptSearch::SearchBy::ID;

std::vector<ScriptObjTree*> treesToSearchInto;
treesToSearchInto.push_back( m_previewIsItem ? getScriptObjTree(SCRIPTOBJ_TYPE_ITEM) : getScriptObjTree(SCRIPTOBJ_TYPE_CHAR) );
Expand All @@ -305,15 +304,6 @@ void Dlg_HuePicker::on_lineEdit_preview_returnPressed()

/* Enhanced Label implementation */

EnhancedLabel::EnhancedLabel(QWidget* parent, Qt::WindowFlags /*f*/)
: QLabel(parent)
{
}

EnhancedLabel::~EnhancedLabel()
{
}

void EnhancedLabel::mousePressEvent(QMouseEvent* /*event*/)
{
emit clicked();
Expand Down
6 changes: 4 additions & 2 deletions src/forms/dlg_huepicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ class EnhancedLabel : public QLabel
Q_OBJECT

public:
explicit EnhancedLabel(QWidget* parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
~EnhancedLabel();
explicit EnhancedLabel(QWidget* /*parent*/ = Q_NULLPTR, Qt::WindowFlags /*f*/ = Qt::WindowFlags())
{
}
~EnhancedLabel() = default;
//int m_index;

signals:
Expand Down
41 changes: 17 additions & 24 deletions src/forms/maintab_chars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ MainTab_Chars::MainTab_Chars(QWidget *parent) :
// Set stretch factors to the splitter between the QGraphicsView and the lists layout
ui->splitter_img_lists->setStretchFactor(0,3); // column 0: lists layout
ui->splitter_img_lists->setStretchFactor(1,1); // column 1: QGraphicsView

m_subdlg_searchObj = std::make_unique<SubDlg_SearchObj>(window());
}


Expand Down Expand Up @@ -86,13 +88,12 @@ bool MainTab_Chars::eventFilter(QObject* watched, QEvent* event)

return false;
}
else if ( (keyEv->key()==Qt::Key_F) && (keyEv->modifiers() & Qt::ControlModifier) )
if ( (keyEv->key()==Qt::Key_F) && (keyEv->modifiers() & Qt::ControlModifier) )
{ // presset CTRL + F
on_pushButton_search_clicked();
return false;
}
else
return QObject::eventFilter(watched, event);
return QObject::eventFilter(watched, event);
}

void MainTab_Chars::updateViews()
Expand All @@ -114,18 +115,16 @@ void MainTab_Chars::updateViews()
const ScriptObjTree *trees[2] = { g_scriptObjTree_Chars, g_scriptObjTree_Spawns };
for (int tree_i = 0; tree_i < 2; ++tree_i)
{
for (size_t category_i = 0; category_i < trees[tree_i]->m_categories.size(); ++category_i)
for (ScriptCategory* categoryInst : trees[tree_i]->m_categories)
{
ScriptCategory *categoryInst = trees[tree_i]->m_categories[category_i];
QStandardItem *categoryItem = new QStandardItem(categoryInst->m_categoryName.c_str());
m_categoryMap[categoryItem] = categoryInst;
categoryItem->setSelectable(false);
if (tree_i == 1)
categoryItem->setForeground(QBrush(QColor("red")));
root->appendRow(categoryItem);
for (size_t subsection_i = 0; subsection_i < categoryInst->m_subsections.size(); ++subsection_i)
for (ScriptSubsection* subsectionInst : categoryInst->m_subsections)
{
ScriptSubsection *subsectionInst = categoryInst->m_subsections[subsection_i];
QStandardItem *subsectionItem = new QStandardItem(subsectionInst->m_subsectionName.c_str());
categoryItem->appendRow(subsectionItem);
m_subsectionMap[subsectionItem] = subsectionInst; // So that i know at which ScriptSubsection each QStandardItem corresponds.
Expand All @@ -143,11 +142,11 @@ void MainTab_Chars::onManual_treeView_organizer_selectionChanged(const QModelInd
if (m_organizer_model->rowCount() == 0) // Empty list, can't proceed.
return;

QStandardItem *subsection_item = m_organizer_model->itemFromIndex(selected);
if (!m_subsectionMap.count(subsection_item)) // If the selected item isn't in the map, it is a Category, not a Subsection.
QStandardItem *subsectionItem = m_organizer_model->itemFromIndex(selected);
if (!m_subsectionMap.count(subsectionItem)) // If the selected item isn't in the map, it is a Category, not a Subsection.
return;
ScriptSubsection *subsection_inst = m_subsectionMap[subsection_item];
//if (subsectionObj == nullptr) // Checking again (maybe useless, but...), because if the pointer isn't valid the program will crash.
ScriptSubsection *subsectionInst = m_subsectionMap[subsectionItem];
//if (subsectionItem == nullptr) // Checking again (maybe useless, but...), because if the pointer isn't valid the program will crash.
// return;

m_objList_model->removeRows(0,m_objList_model->rowCount());
Expand All @@ -157,11 +156,9 @@ void MainTab_Chars::onManual_treeView_organizer_selectionChanged(const QModelInd
ui->treeView_objList->setUpdatesEnabled(false);

/* Populate the object list */
for (size_t subsection_i = 0; subsection_i < subsection_inst->m_objects.size(); ++subsection_i)
for (ScriptObj* obj : subsectionInst->m_objects)
{
// Build the two QStandardItem for each ScriptObj in this Subsection

ScriptObj *obj = subsection_inst->m_objects[subsection_i];
QList<QStandardItem*> row;

/* Build the description part */
Expand Down Expand Up @@ -194,7 +191,7 @@ void MainTab_Chars::onManual_treeView_organizer_selectionChanged(const QModelInd
row.append(description_item);

/* Build the defname part */
std::string def = obj->m_defname.empty() ? obj->m_ID : obj->m_defname;
const std::string& def = obj->m_defname.empty() ? obj->m_ID : obj->m_defname;
QStandardItem *defname_item = new QStandardItem(def.c_str());
row.append(defname_item);

Expand Down Expand Up @@ -223,7 +220,7 @@ void MainTab_Chars::on_treeView_objList_doubleClicked(const QModelIndex &index)

std::string strToSend = ".add " + IDIndex.data().toString().toStdString();
auto ksResult = ks::KeystrokeSender::sendStringFastAsync(strToSend, true, g_sendKeystrokeAndFocusClient);
if (ksResult != ks::KSERR_OK)
if (ksResult != ks::KSError::Ok)
{
QMessageBox errorDlg(QMessageBox::Warning, "Warning", ks::getErrorStringStatic(ksResult), QMessageBox::NoButton, this);
errorDlg.exec();
Expand Down Expand Up @@ -283,7 +280,7 @@ void MainTab_Chars::on_pushButton_summon_clicked()

std::string strToSend = ".add " + selection->selectedRows(1)[0].data().toString().toStdString();
auto ksResult = ks::KeystrokeSender::sendStringFastAsync(strToSend, true, g_sendKeystrokeAndFocusClient);
if (ksResult != ks::KSERR_OK)
if (ksResult != ks::KSError::Ok)
{
QMessageBox errorDlg(QMessageBox::Warning, "Warning", ks::getErrorStringStatic(ksResult), QMessageBox::NoButton, this);
errorDlg.exec();
Expand All @@ -294,7 +291,7 @@ void MainTab_Chars::on_pushButton_remove_clicked()
{
std::string strToSend = ".remove";
auto ksResult = ks::KeystrokeSender::sendStringFastAsync(strToSend, true, g_sendKeystrokeAndFocusClient);
if (ksResult != ks::KSERR_OK)
if (ksResult != ks::KSError::Ok)
{
QMessageBox errorDlg(QMessageBox::Warning, "Warning", ks::getErrorStringStatic(ksResult), QMessageBox::NoButton, this);
errorDlg.exec();
Expand Down Expand Up @@ -362,10 +359,7 @@ void MainTab_Chars::on_pushButton_search_clicked()
if (g_loadedScriptsProfile == -1)
return;

SubDlg_SearchObj dlg(window());
if (m_lastSearchData.initialized)
dlg.setSearchData(m_lastSearchData);
if (!dlg.exec())
if (!m_subdlg_searchObj->exec())
return;

const std::vector<ScriptObjTree*> trees =
Expand All @@ -374,8 +368,7 @@ void MainTab_Chars::on_pushButton_search_clicked()
getScriptObjTree(SCRIPTOBJ_TYPE_SPAWN)
};

m_lastSearchData = dlg.getSearchData();
m_scriptSearch.reset(new ScriptSearch(trees, m_lastSearchData));
m_scriptSearch = std::make_unique<ScriptSearch>(trees, m_subdlg_searchObj->getSearchData());
doSearch(false);
}

Expand Down
5 changes: 3 additions & 2 deletions src/forms/maintab_chars.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#ifndef MAINTAB_CHARS_H
#define MAINTAB_CHARS_H

#include "subdlg_searchobj.h"
#include <QWidget>
#include <memory> // for smart pointers

class SubDlg_SearchObj;
class ScriptSearch;
class ScriptCategory;
class ScriptSubsection;
class ScriptObj;
Expand Down Expand Up @@ -54,8 +55,8 @@ private slots:
QStandardItemModel *m_organizer_model;
QStandardItemModel *m_objList_model;

std::unique_ptr<SubDlg_SearchObj> m_subdlg_searchObj;
std::unique_ptr<ScriptSearch> m_scriptSearch;
ScriptSearch::SearchData_t m_lastSearchData;

void doSearch (bool backwards);
};
Expand Down
Loading

0 comments on commit 7fd03ba

Please sign in to comment.