Changed: #1206 Update sheet builder plugin. Now plugin is using ICore for reading and writing settings, and it adds action in menu Sheet.

This commit is contained in:
dnk-88 2011-03-02 23:57:57 +02:00
parent 4b96864a9e
commit 5d0be05baf
12 changed files with 561 additions and 573 deletions

View file

@ -43,6 +43,8 @@ const char * const M_TOOLS = "ObjectViewerQt.Menu.Tools";
const char * const M_WINDOW = "ObjectViewerQt.Menu.Window"; const char * const M_WINDOW = "ObjectViewerQt.Menu.Window";
const char * const M_HELP = "ObjectViewerQt.Menu.Help"; const char * const M_HELP = "ObjectViewerQt.Menu.Help";
const char * const M_SHEET = "ObjectViewerQt.Menu.Sheet";
//actions //actions
const char * const NEW = "ObjectViewerQt.New"; const char * const NEW = "ObjectViewerQt.New";
const char * const OPEN = "ObjectViewerQt.Open"; const char * const OPEN = "ObjectViewerQt.Open";

View file

@ -62,8 +62,7 @@ bool CorePlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QStr
{ {
QtWin::extendFrameIntoClientArea(_mainWindow); QtWin::extendFrameIntoClientArea(_mainWindow);
_mainWindow->setContentsMargins(0, 0, 0, 0); _mainWindow->setContentsMargins(0, 0, 0, 0);
} }*/
*/
bool success = _mainWindow->initialize(errorString); bool success = _mainWindow->initialize(errorString);
CSearchPathsSettingsPage *serchPathPage = new CSearchPathsSettingsPage(this); CSearchPathsSettingsPage *serchPathPage = new CSearchPathsSettingsPage(this);
serchPathPage->applySearchPaths(); serchPathPage->applySearchPaths();

View file

@ -231,8 +231,10 @@ void MainWindow::createMenus()
m_toolsMenu = menuBar()->addMenu(tr("&Tools")); m_toolsMenu = menuBar()->addMenu(tr("&Tools"));
menuManager()->registerMenu(m_toolsMenu, Constants::M_TOOLS); menuManager()->registerMenu(m_toolsMenu, Constants::M_TOOLS);
m_sheetMenu = m_toolsMenu->addMenu(tr("&Sheet"));
menuManager()->registerMenu(m_sheetMenu, Constants::M_SHEET);
m_toolsMenu->addSeparator(); // m_toolsMenu->addSeparator();
m_toolsMenu->addAction(m_settingsAction); m_toolsMenu->addAction(m_settingsAction);

View file

@ -97,6 +97,8 @@ private:
QMenu *m_toolsMenu; QMenu *m_toolsMenu;
QMenu *m_helpMenu; QMenu *m_helpMenu;
QMenu *m_sheetMenu;
QAction *m_openAction; QAction *m_openAction;
QAction *m_exitAction; QAction *m_exitAction;
QAction *m_settingsAction; QAction *m_settingsAction;

View file

@ -21,7 +21,7 @@ SOURCE_GROUP("OVQT Extension System" FILES ${OVQT_EXT_SYS_SRC})
ADD_LIBRARY(ovqt_plugin_sheet_builder MODULE ${SRC} ${OVQT_PLUG_SHEET_BUILDER_MOC_SRC} ${OVQT_EXT_SYS_SRC}) ADD_LIBRARY(ovqt_plugin_sheet_builder MODULE ${SRC} ${OVQT_PLUG_SHEET_BUILDER_MOC_SRC} ${OVQT_EXT_SYS_SRC})
TARGET_LINK_LIBRARIES(ovqt_plugin_sheet_builder nelmisc ${QT_LIBRARIES}) TARGET_LINK_LIBRARIES(ovqt_plugin_sheet_builder ovqt_plugin_core nelmisc ${QT_LIBRARIES})
NL_DEFAULT_PROPS(ovqt_plugin_sheet_builder "NeL, Tools, 3D: Object Viewer Qt Plugin: Sheet builder") NL_DEFAULT_PROPS(ovqt_plugin_sheet_builder "NeL, Tools, 3D: Object Viewer Qt Plugin: Sheet builder")
NL_ADD_RUNTIME_FLAGS(ovqt_plugin_sheet_builder) NL_ADD_RUNTIME_FLAGS(ovqt_plugin_sheet_builder)

View file

@ -14,8 +14,18 @@
// You should have received a copy of the GNU Affero General Public License // 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/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// Project includes
#include "ovqt_sheet_builder.h" #include "ovqt_sheet_builder.h"
#include "sheetbuilderdialog.h"
#include "sheetbuilderconfgdialog.h"
#include "../core/icore.h"
#include "../core/imenu_manager.h"
#include "../core/core_constants.h"
// NeL includes
#include <nel/misc/debug.h>
// Qt includes
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtGui/QMessageBox> #include <QtGui/QMessageBox>
#include <QtGui/QMainWindow> #include <QtGui/QMainWindow>
@ -23,47 +33,29 @@
#include <QtGui/QAction> #include <QtGui/QAction>
#include <QtGui/QMenuBar> #include <QtGui/QMenuBar>
#include "../../extension_system/iplugin_spec.h"
#include "nel/misc/debug.h"
#include "sheetbuilderdialog.h"
#include "sheetbuilderconfgdialog.h"
using namespace Plugin; using namespace Plugin;
bool SheetBuilderPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString) bool SheetBuilderPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString)
{ {
Q_UNUSED(errorString); Q_UNUSED(errorString);
_plugMan = pluginManager; _plugMan = pluginManager;
QMainWindow *wnd = qobject_cast<QMainWindow *>(objectByName("CMainWindow"));
if (!wnd)
{
*errorString = tr("Not found MainWindow Object Viewer Qt.");
return false;
}
QMenu *toolsMenu = qobject_cast<QMenu *>(objectByName("ovqt.Menu.Tools"));
if (!toolsMenu)
{
*errorString = tr("Not found QMenu Tools.");
return false;
}
return true; return true;
} }
void SheetBuilderPlugin::extensionsInitialized() void SheetBuilderPlugin::extensionsInitialized()
{ {
QMenu *toolsMenu = qobject_cast<QMenu *>(objectByName("ovqt.Menu.Tools")); Core::IMenuManager *menuManager = Core::ICore::instance()->menuManager();
nlassert(toolsMenu);
toolsMenu->addSeparator(); QMenu *sheetMenu = menuManager->menu(Core::Constants::M_SHEET);
QAction *sheetBuilderAction = sheetMenu->addAction(tr("Sheet builder"));
QAction *actBuilder = toolsMenu->addAction("Sheet builder"); menuManager->registerAction(sheetBuilderAction, "SheetBuilder");
connect(actBuilder, SIGNAL(triggered()), this, SLOT(execBuilderDialog())); connect(sheetBuilderAction, SIGNAL(triggered()), this, SLOT(execBuilderDialog()));
} }
void SheetBuilderPlugin::execBuilderDialog() void SheetBuilderPlugin::execBuilderDialog()
{ {
QMainWindow *wnd = qobject_cast<QMainWindow *>(objectByName("CMainWindow")); QMainWindow *wnd = Core::ICore::instance()->mainWindow();
nlassert(wnd); nlassert(wnd);
SheetBuilderDialog dlg(wnd); SheetBuilderDialog dlg(wnd);
@ -100,25 +92,11 @@ QString SheetBuilderPlugin::description() const
return "make_sheet_id equivalent"; return "make_sheet_id equivalent";
} }
QList<QString> SheetBuilderPlugin::dependencies() const QStringList SheetBuilderPlugin::dependencies() const
{ {
return QList<QString>(); QStringList list;
} list.append(Core::Constants::OVQT_CORE_PLUGIN);
return list;
QObject* SheetBuilderPlugin::objectByName(const QString &name) const
{
Q_FOREACH (QObject *qobj, _plugMan->allObjects())
if (qobj->objectName() == name)
return qobj;
return 0;
}
ExtensionSystem::IPluginSpec *SheetBuilderPlugin::pluginByName(const QString &name) const
{
Q_FOREACH (ExtensionSystem::IPluginSpec *spec, _plugMan->plugins())
if (spec->name() == name)
return spec;
return 0;
} }
Q_EXPORT_PLUGIN(SheetBuilderPlugin) Q_EXPORT_PLUGIN(SheetBuilderPlugin)

View file

@ -50,10 +50,7 @@ namespace Plugin
QString version() const; QString version() const;
QString vendor() const; QString vendor() const;
QString description() const; QString description() const;
QList<QString> dependencies() const; QStringList dependencies() const;
QObject *objectByName(const QString &name) const;
ExtensionSystem::IPluginSpec *pluginByName(const QString &name) const;
void buildSheet(bool clean); void buildSheet(bool clean);

View file

@ -26,10 +26,8 @@
// std // std
#include <string> #include <string>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
using namespace NLMISC; using namespace NLMISC;
using namespace std; using namespace std;
@ -50,10 +48,16 @@ union TFormId
uint32 Id : 24; uint32 Id : 24;
} FormIDInfos; } FormIDInfos;
void serial(NLMISC::IStream &f) { f.serial(Id); } void serial(NLMISC::IStream &f)
{
f.serial(Id);
}
}; };
bool operator<(const TFormId& fid1, const TFormId& fid2) { return fid1.Id<fid2.Id; } bool operator<(const TFormId& fid1, const TFormId& fid2)
{
return fid1.Id<fid2.Id;
}
map<string,TFormId> FormToId; map<string,TFormId> FormToId;
@ -185,8 +189,6 @@ void readFormId( string& outputFileName )
} // readFormId // } // readFormId //
//----------------------------------------------- //-----------------------------------------------
// makeId // makeId
// //
@ -210,8 +212,6 @@ void makeId( list<string>& dirs )
} // makeId // } // makeId //
//----------------------------------------------- //-----------------------------------------------
// addId // addId
// //
@ -311,7 +311,6 @@ void addId( string fileName )
} // addId // } // addId //
//----------------------------------------------- //-----------------------------------------------
// getFileType // getFileType
// //
@ -324,7 +323,6 @@ bool getFileType( string& fileName, string& fileType )
} // getFileType // } // getFileType //
//----------------------------------------------- //-----------------------------------------------
// display // display
// //

View file

@ -15,6 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "sheetbuilderconfgdialog.h" #include "sheetbuilderconfgdialog.h"
#include "../core/icore.h"
#include <QListWidget> #include <QListWidget>
#include <QPushButton> #include <QPushButton>
@ -25,8 +26,8 @@
#include <QCloseEvent> #include <QCloseEvent>
#include <QFileDialog> #include <QFileDialog>
SheetBuilderConfigDialog::SheetBuilderConfigDialog(QWidget *parent) : SheetBuilderConfigDialog::SheetBuilderConfigDialog(QWidget *parent)
QDialog(parent) : QDialog(parent)
{ {
/* /*
* Paths * Paths
@ -117,8 +118,9 @@ SheetBuilderConfigDialog::SheetBuilderConfigDialog(QWidget *parent) :
void SheetBuilderConfigDialog::addPath() void SheetBuilderConfigDialog::addPath()
{ {
QString path = QString path =
QFileDialog::getExistingDirectory(this, "Choose path"); QFileDialog::getExistingDirectory(this, tr("Choose path"));
if (!path.isEmpty()) { if (!path.isEmpty())
{
QListWidgetItem *newItem = new QListWidgetItem; QListWidgetItem *newItem = new QListWidgetItem;
newItem->setText(path); newItem->setText(path);
newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
@ -164,18 +166,20 @@ void SheetBuilderConfigDialog::readSettings()
QString outputFile; QString outputFile;
QStringList extensions; QStringList extensions;
QSettings settings("ovqt_sheet_builder.ini", QSettings::IniFormat); QSettings *settings = Core::ICore::instance()->settings();
settings->beginGroup("SheetBuilder");
paths = settings.value("SheetPaths").toStringList(); paths = settings->value("SheetPaths").toStringList();
outputFile = settings.value("SheetOutputFile").toString(); outputFile = settings->value("SheetOutputFile").toString();
extensions = settings.value("ExtensionsAllowed").toStringList(); extensions = settings->value("ExtensionsAllowed").toStringList();
settings->endGroup();
lstPaths->clear(); lstPaths->clear();
lstExtensionsAllowed->clear(); lstExtensionsAllowed->clear();
QListWidgetItem *newItem; QListWidgetItem *newItem;
Q_FOREACH (QString path, paths) { Q_FOREACH (QString path, paths)
{
newItem = new QListWidgetItem; newItem = new QListWidgetItem;
newItem->setText(path); newItem->setText(path);
newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
@ -184,7 +188,8 @@ void SheetBuilderConfigDialog::readSettings()
txtOutputFile->setText(outputFile); txtOutputFile->setText(outputFile);
Q_FOREACH (QString extension, extensions) { Q_FOREACH (QString extension, extensions)
{
newItem = new QListWidgetItem; newItem = new QListWidgetItem;
newItem->setText(extension); newItem->setText(extension);
newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
@ -204,8 +209,13 @@ void SheetBuilderConfigDialog::writeSettings()
for (int i = 0; i < lstExtensionsAllowed->count(); i++) for (int i = 0; i < lstExtensionsAllowed->count(); i++)
extensions.push_back(lstExtensionsAllowed->item(i)->text()); extensions.push_back(lstExtensionsAllowed->item(i)->text());
QSettings settings("./ovqt_sheet_builder.ini", QSettings::IniFormat); QSettings *settings = Core::ICore::instance()->settings();
settings.setValue("SheetPaths", paths); settings->beginGroup("SheetBuilder");
settings.setValue("SheetOutputFile", outputFile); settings->setValue("SheetPaths", paths);
settings.setValue("ExtensionsAllowed", extensions); settings->setValue("SheetOutputFile", outputFile);
settings->setValue("ExtensionsAllowed", extensions);
settings->endGroup();
// Forced save settings
settings->sync();
} }

View file

@ -15,6 +15,11 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "sheetbuilderdialog.h" #include "sheetbuilderdialog.h"
#include "sheetbuilder.h"
#include "sheetbuilderconfgdialog.h"
#include "../core/icore.h"
#include "../core/core_constants.h"
#include <QCheckBox> #include <QCheckBox>
#include <QPushButton> #include <QPushButton>
#include <QLayout> #include <QLayout>
@ -23,13 +28,9 @@
#include <QTreeWidget> #include <QTreeWidget>
#include <QDebug> #include <QDebug>
#include "sheetbuilder.h" SheetBuilderDialog::SheetBuilderDialog(QWidget *parent)
#include "sheetbuilderconfgdialog.h" : QDialog(parent)
SheetBuilderDialog::SheetBuilderDialog(QWidget *parent) :
QDialog(parent)
{ {
QPushButton *btnOk = new QPushButton(tr("Make sheet")); QPushButton *btnOk = new QPushButton(tr("Make sheet"));
connect(btnOk, SIGNAL(clicked()), SLOT(buildSheet())); connect(btnOk, SIGNAL(clicked()), SLOT(buildSheet()));
@ -81,7 +82,8 @@ void SheetBuilderDialog::showConfig()
void SheetBuilderDialog::detailsShowHide() void SheetBuilderDialog::detailsShowHide()
{ {
if (!detailsVisible) { if (!detailsVisible)
{
defHeight = height(); defHeight = height();
defWidth = width(); defWidth = width();
} }
@ -89,7 +91,8 @@ void SheetBuilderDialog::detailsShowHide()
detailsVisible = !detailsVisible; detailsVisible = !detailsVisible;
txtOutput->setVisible(detailsVisible); txtOutput->setVisible(detailsVisible);
if (!detailsVisible) { if (!detailsVisible)
{
adjustSize(); adjustSize();
resize(defWidth, defHeight); resize(defWidth, defHeight);
} }
@ -106,16 +109,20 @@ void SheetBuilderDialog::buildSheet()
QString outputFile; QString outputFile;
QStringList extensions; QStringList extensions;
QSettings settings("ovqt_sheet_builder.ini", QSettings::IniFormat); // read settings
paths = settings.value("SheetPaths").toStringList(); QSettings *settings = Core::ICore::instance()->settings();
outputFile = settings.value("SheetOutputFile").toString(); settings->beginGroup("SheetBuilder");
extensions = settings.value("ExtensionsAllowed").toStringList(); paths = settings->value("SheetPaths").toStringList();
outputFile = settings->value("SheetOutputFile").toString();
extensions = settings->value("ExtensionsAllowed").toStringList();
settings->endGroup();
bool clean = chckClean->isChecked(); bool clean = chckClean->isChecked();
string configFileName("ovqt_sheet_builder.ini");
string outputFileName(outputFile.toStdString()); string outputFileName(outputFile.toStdString());
if (outputFileName.empty()) { if (outputFileName.empty())
{
displayInfo("Error: Output file is not specified"); displayInfo("Error: Output file is not specified");
return; return;
} }
@ -124,18 +131,10 @@ void SheetBuilderDialog::buildSheet()
Q_FOREACH (QString str, paths) Q_FOREACH (QString str, paths)
inputDirs.push_back(str.toStdString()); inputDirs.push_back(str.toStdString());
// load the config files Q_FOREACH (QString str, extensions)
CConfigFile configFile;
if(!CFile::fileExists(configFileName))
{ {
displayInfo(QString("Config file '%1' not found, working whithout filter").arg(configFileName.c_str()) );
}
else
{
Q_FOREACH (QString str, extensions) {
ExtensionsAllowed.insert(str.toStdString()); ExtensionsAllowed.insert(str.toStdString());
} }
}
// get the current associations (read the sheet_id and fill the working structures) // get the current associations (read the sheet_id and fill the working structures)
readFormId( outputFileName ); readFormId( outputFileName );
@ -152,7 +151,7 @@ void SheetBuilderDialog::buildSheet()
if( clean ) if( clean )
{ {
if( ExtensionsAllowed.empty() ) if( ExtensionsAllowed.empty() )
displayInfo("None extension list provided, the input will not be cleaned"); displayInfo(tr("None extension list provided, the input will not be cleaned"));
else else
{ {
map<TFormId,string>::iterator itSheets; map<TFormId,string>::iterator itSheets;
@ -176,9 +175,10 @@ void SheetBuilderDialog::buildSheet()
displayInfo("The file has been cleaned"); displayInfo("The file has been cleaned");
return; return;
} }
setCursor(Qt::WaitCursor);
// make the ids // make the ids
makeId( inputDirs ); makeId( inputDirs );
setCursor(Qt::ArrowCursor);
// save the new map // save the new map
COFile f( outputFileName ); COFile f( outputFileName );
@ -188,7 +188,7 @@ void SheetBuilderDialog::buildSheet()
COFile output; COFile output;
if( !output.open(sheetListFileName,false,true) ) if( !output.open(sheetListFileName,false,true) )
{ {
displayInfo(QString("Can't open output file %1").arg(sheetListFileName.c_str())); displayInfo(tr("Can't open output file %1").arg(sheetListFileName.c_str()));
return; return;
} }
map<TFormId,string>::iterator it1; map<TFormId,string>::iterator it1;
@ -198,13 +198,13 @@ void SheetBuilderDialog::buildSheet()
output.serialBuffer((uint8*)(const_cast<char*>(outputLine.data())),(uint)outputLine.size()); output.serialBuffer((uint8*)(const_cast<char*>(outputLine.data())),(uint)outputLine.size());
} }
displayInfo ("------------- results ----------------"); displayInfo (tr("------------- results ----------------"));
displayInfo (QString("%1 files added in '%2'").arg(NbFilesAdded).arg(outputFileName.c_str())); displayInfo (tr("%1 files added in '%2'").arg(NbFilesAdded).arg(outputFileName.c_str()));
displayInfo (QString("%1 files discarded because they are empty, begin with .# _ and so on").arg(NbFilesDiscarded)); displayInfo (tr("%1 files discarded because they are empty, begin with .# _ and so on").arg(NbFilesDiscarded));
displayInfo (QString("%1 files skipped because don't have extension").arg(NbFilesUnknownType)); displayInfo (tr("%1 files skipped because don't have extension").arg(NbFilesUnknownType));
displayInfo (QString("%1 types added in '%1'").arg(NbTypesAdded).arg(outputFileName.c_str())); displayInfo (tr("%1 types added in '%1'").arg(NbTypesAdded).arg(outputFileName.c_str()));
displayInfo (QString("%1 supported file types :").arg(FileTypeToId.size())); displayInfo (tr("%1 supported file types :").arg(FileTypeToId.size()));
for ( map<string,uint8>::iterator it = FileTypeToId.begin(); it != FileTypeToId.end(); ++it ) for ( map<string,uint8>::iterator it = FileTypeToId.begin(); it != FileTypeToId.end(); ++it )
{ {
displayInfo(QString("%1").arg((*it).first.c_str())); displayInfo(QString("%1").arg((*it).first.c_str()));