Changed: #1193 Polish sheet id view plugin code.

This commit is contained in:
dnk-88 2011-03-04 15:50:24 +02:00
parent 364f7fddff
commit cf39fcd06c
11 changed files with 203 additions and 227 deletions

View file

@ -9,12 +9,11 @@ SET(OVQT_EXT_SYS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin.
${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_spec.h)
SET(OVQT_DISP_SHEET_ID_PLUGIN_HDR
bin_reader.h
dialog.h
sheet_id_view.h
disp_sheet_id_plugin.h)
SET(OVQT_DISP_SHEET_ID_PLUGIN_UIS
dialog.ui)
sheet_id_view.ui)
SET(QT_USE_QTGUI TRUE)
SET(QT_USE_QTOPENGL TRUE)
@ -29,7 +28,7 @@ SOURCE_GROUP("OVQT Extension System" FILES ${OVQT_EXT_SYS_SRC})
ADD_LIBRARY(ovqt_plugin_disp_sheet_id MODULE ${SRC} ${OVQT_DISP_SHEET_ID_PLUGIN_MOC_SRC} ${OVQT_EXT_SYS_SRC} ${OVQT_DISP_SHEET_ID_PLUGIN_UI_HDRS})
TARGET_LINK_LIBRARIES(ovqt_plugin_disp_sheet_id nelmisc nel3d ${QT_LIBRARIES})
TARGET_LINK_LIBRARIES(ovqt_plugin_disp_sheet_id ovqt_plugin_core nelmisc nel3d ${QT_LIBRARIES})
IF(WITH_STLPORT)
TARGET_LINK_LIBRARIES(ovqt_plugin_disp_sheet_id ${CMAKE_THREAD_LIBS_INIT})

View file

@ -1,55 +0,0 @@
#include "nel/misc/types_nl.h"
#include <stdio.h>
#include "bin_reader.h"
#include <QTableWidget>
#include <QTableWidgetItem>
#include <QByteArray>
#include <QVector>
#include "nel/misc/path.h"
#include "nel/misc/sheet_id.h"
#include <vector>
#include "nel/misc/types_nl.h"
class CPred
{
public:
bool operator()(const CSheetId &a, const CSheetId &b)
{
return a.toString()<b.toString();
}
};
BinReader::BinReader(QString dir)
{
QByteArray dirChar = dir.toLatin1();
char* dirCharRef = dirChar.data();
// NLMISC::CApplicationContext appContext;
CPath::addSearchPath(dirCharRef);
CSheetId::init(false);
CSheetId::buildIdVector(this->SheetList);
CPred Pred;
sort(this->SheetList.begin(), this->SheetList.end(), Pred);
// this->SheetList.fromStdVector(sheets);
}
int BinReader::count()
{
return this->SheetList.size();
}
std::vector<CSheetId> BinReader::getVector() const
{
return this->SheetList;
}
void BinReader::pushToTable(QTableWidget*& table)
{
table->clear();
table->setRowCount(this->SheetList.size());
table->setColumnCount(2);
for (int i = 0; i < this->SheetList.size(); i++)
{
QTableWidgetItem* item1 = new QTableWidgetItem(QString(this->SheetList[i].toString().c_str()));
QTableWidgetItem* item2 = new QTableWidgetItem(QString("%1").arg(this->SheetList[i].asInt()));
table->setItem(i,1,item1);
table->setItem(i,2,item2);
}
}

View file

@ -1,24 +0,0 @@
#include "nel/misc/types_nl.h"
#include <stdio.h>
#include <QTableWidget>
#include <QTableWidgetItem>
#include <QByteArray>
#include <QVector>
#include "nel/misc/path.h"
#include "nel/misc/sheet_id.h"
#include <vector>
#include "nel/misc/types_nl.h"
using namespace std;
using namespace NLMISC;
class BinReader
{
public:
BinReader(QString dir);
int count();
void pushToTable(QTableWidget*& table);
std::vector<CSheetId> getVector() const;
private:
std::vector<CSheetId> SheetList;
};

View file

@ -1,47 +0,0 @@
#include "dialog.h"
#include "ui_dialog.h"
#include "bin_reader.h"
#include "QMessageBox"
#include "QSettings"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
QSettings settings("ovqt_sheet_builder.ini", QSettings::IniFormat);
dir = settings.value("PathToSheetId", "").toString();
connect(ui->reloadButton,SIGNAL(clicked()),this,SLOT(reloadTable()));
connect(ui->browseButton,SIGNAL(clicked()),this,SLOT(getDir()));
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::reloadTable()
{
QFile file(dir + QString("./sheet_id.bin"));
if(file.exists() == true)
{
QSettings settings("ovqt_sheet_builder.ini", QSettings::IniFormat);
settings.setValue("PathToSheetId", dir);
BinReader reader(this->dir);
reader.pushToTable(ui->table);
}
else
{
QMessageBox errorBox;
errorBox.setText(QString("File sheet_id.bin doesn't exist in direcotry: \n") + this->dir);
errorBox.exec();
}
}
void Dialog::getDir()
{
QFileDialog fileDialog(this);
fileDialog.setFileMode(QFileDialog::DirectoryOnly);
this->dir = fileDialog.getExistingDirectory();
}

View file

@ -1,28 +0,0 @@
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include <QFileDialog>
namespace Ui
{
class Dialog;
}
class Dialog : public QDialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = 0);
~Dialog();
public Q_SLOTS:
void reloadTable();
void getDir();
private:
QString dir;
Ui::Dialog *ui;
};
#endif // DIALOG_H

View file

@ -1,5 +1,27 @@
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// Project includes
#include "disp_sheet_id_plugin.h"
#include "dialog.h"
#include "sheet_id_view.h"
#include "../core/icore.h"
#include "../core/imenu_manager.h"
#include "../core/core_constants.h"
// Qt includes
#include <QtCore/QObject>
#include <QtGui/QMessageBox>
#include <QtGui/QMainWindow>
@ -7,43 +29,38 @@
#include <QtGui/QAction>
#include <QtGui/QMenuBar>
#include "../../extension_system/iplugin_spec.h"
// NeL includes
#include "nel/misc/debug.h"
using namespace Plugin;
using namespace SheetIdViewPlugin;
bool MyPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString)
bool DispSheetIdPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString)
{
Q_UNUSED(errorString);
_plugMan = pluginManager;
QMainWindow *wnd = qobject_cast<QMainWindow *>(objectByName("CMainWindow"));
if (!wnd)
{
*errorString = tr("Not found QMainWindow Object Viewer Qt.");
return false;
}
return true;
}
void MyPlugin::extensionsInitialized()
void DispSheetIdPlugin::extensionsInitialized()
{
QMenu *toolsMenu = qobject_cast<QMenu *>(objectByName("ovqt.Menu.Tools"));
nlassert(toolsMenu);
Core::IMenuManager *menuManager = Core::ICore::instance()->menuManager();
QAction *newAction = toolsMenu->addAction("Display sheet id");
QMenu *sheetMenu = menuManager->menu(Core::Constants::M_SHEET);
QAction *sheetIdViewAction = sheetMenu->addAction(tr("Sheet id view"));
menuManager->registerAction(sheetIdViewAction, "SheetIdView");
connect(sheetIdViewAction, SIGNAL(triggered()), this, SLOT(execBuilderDialog()));
connect(newAction, SIGNAL(triggered()), this, SLOT(execMessageBox()));
connect(sheetIdViewAction, SIGNAL(triggered()), this, SLOT(execMessageBox()));
}
void MyPlugin::execMessageBox()
void DispSheetIdPlugin::execMessageBox()
{
Dialog dialog;
SheetIdView dialog;
dialog.show();
dialog.exec();
}
void MyPlugin::setNelContext(NLMISC::INelContext *nelContext)
void DispSheetIdPlugin::setNelContext(NLMISC::INelContext *nelContext)
{
#ifdef NL_OS_WINDOWS
// Ensure that a context doesn't exist yet.
@ -53,45 +70,31 @@ void MyPlugin::setNelContext(NLMISC::INelContext *nelContext)
_LibContext = new NLMISC::CLibraryContext(*nelContext);
}
QString MyPlugin::name() const
QString DispSheetIdPlugin::name() const
{
return "Display sheet id";
}
QString MyPlugin::version() const
QString DispSheetIdPlugin::version() const
{
return "0.1";
return "1.0";
}
QString MyPlugin::vendor() const
QString DispSheetIdPlugin::vendor() const
{
return "pemeon";
}
QString MyPlugin::description() const
QString DispSheetIdPlugin::description() const
{
return "Display sheet id";
}
QList<QString> MyPlugin::dependencies() const
QStringList DispSheetIdPlugin::dependencies() const
{
return QList<QString>();
QStringList list;
list.append(Core::Constants::OVQT_CORE_PLUGIN);
return list;
}
QObject* MyPlugin::objectByName(const QString &name) const
{
Q_FOREACH (QObject *qobj, _plugMan->allObjects())
if (qobj->objectName() == name)
return qobj;
return 0;
}
ExtensionSystem::IPluginSpec *MyPlugin::pluginByName(const QString &name) const
{
Q_FOREACH (ExtensionSystem::IPluginSpec *spec, _plugMan->plugins())
if (spec->name() == name)
return spec;
return 0;
}
Q_EXPORT_PLUGIN(MyPlugin)
Q_EXPORT_PLUGIN(DispSheetIdPlugin)

View file

@ -1,5 +1,21 @@
#ifndef PLUGIN1_H
#define PLUGIN1_H
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef SHEET_ID_VIEW_PLUGIN_H
#define SHEET_ID_VIEW_PLUGIN_H
#include "../../extension_system/iplugin.h"
@ -17,10 +33,10 @@ namespace NLQT
class IPluginSpec;
}
namespace Plugin
namespace SheetIdViewPlugin
{
class MyPlugin : public QObject, public ExtensionSystem::IPlugin
class DispSheetIdPlugin : public QObject, public ExtensionSystem::IPlugin
{
Q_OBJECT
Q_INTERFACES(ExtensionSystem::IPlugin)
@ -35,10 +51,7 @@ public:
QString version() const;
QString vendor() const;
QString description() const;
QList<QString> dependencies() const;
QObject *objectByName(const QString &name) const;
ExtensionSystem::IPluginSpec *pluginByName(const QString &name) const;
QStringList dependencies() const;
private Q_SLOTS:
void execMessageBox();
@ -51,6 +64,6 @@ private:
};
} // namespace Plugin1
} // namespace SheetIdViewPlugin
#endif // PLUGIN1_H
#endif // SHEET_ID_VIEW_PLUGIN_H

View file

@ -0,0 +1,75 @@
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "sheet_id_view.h"
#include "ui_dialog.h"
#include "nel/misc/path.h"
#include <QtGui/QMessageBox>
#include <QtGui/QApplication>
class CPred
{
public:
bool operator()(const NLMISC::CSheetId &a, const NLMISC::CSheetId &b)
{
return a.toString()<b.toString();
}
};
SheetIdView::SheetIdView(QWidget *parent)
: QDialog(parent)
{
m_ui.setupUi(this);
connect(m_ui.reloadButton, SIGNAL(clicked()), this, SLOT(pushToTable()));
}
SheetIdView::~SheetIdView()
{
}
void SheetIdView::pushToTable()
{
// Check sheet_id.bin
try
{
NLMISC::CPath::lookup("sheet_id.bin");
}
catch (NLMISC::Exception &e)
{
QMessageBox::critical(this, e.what(), tr("Path not found for sheet_id.bin. Add in the settings search path to the file"), QMessageBox::Ok);
return;
}
// Load sheet_id.bin file
NLMISC::CSheetId::init(false);
NLMISC::CSheetId::buildIdVector(m_sheetList);
CPred Pred;
sort(m_sheetList.begin(), m_sheetList.end(), Pred);
// Fill table
m_ui.table->clear();
m_ui.table->setRowCount(m_sheetList.size());
m_ui.table->setColumnCount(2);
for (size_t i = 0; i < m_sheetList.size(); i++)
{
QApplication::processEvents();
QTableWidgetItem* item1 = new QTableWidgetItem(QString(m_sheetList[i].toString().c_str()));
QTableWidgetItem* item2 = new QTableWidgetItem(QString("%1").arg(m_sheetList[i].asInt()));
m_ui.table->setItem(i,1,item1);
m_ui.table->setItem(i,2,item2);
}
}

View file

@ -0,0 +1,43 @@
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef SHEET_ID_VIEW_H
#define SHEET_ID_VIEW_H
#include "ui_sheet_id_view.h"
#include "nel/misc/types_nl.h"
#include "nel/misc/sheet_id.h"
#include <QtGui/QDialog>
class SheetIdView : public QDialog
{
Q_OBJECT
public:
explicit SheetIdView(QWidget *parent = 0);
~SheetIdView();
public Q_SLOTS:
void pushToTable();
private:
std::vector<NLMISC::CSheetId> m_sheetList;
Ui::SheetIdView m_ui;
};
#endif // SHEET_ID_VIEW_H

View file

@ -1,21 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<class>SheetIdView</class>
<widget class="QDialog" name="SheetIdView">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>508</width>
<height>531</height>
<width>426</width>
<height>393</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>Sheet Id View</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTableWidget" name="table"/>
<widget class="QTableWidget" name="table">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
@ -32,17 +36,10 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="browseButton">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="reloadButton">
<property name="text">
<string>Display</string>
<string>Fill table</string>
</property>
</widget>
</item>
@ -63,7 +60,7 @@
<connection>
<sender>endButton</sender>
<signal>clicked()</signal>
<receiver>Dialog</receiver>
<receiver>SheetIdView</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">

View file

@ -26,7 +26,7 @@
<enum>QTabWidget::East</enum>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<property name="movable">
<bool>true</bool>