Changed: Added 'data directory' box and re-arranged filters.

This commit is contained in:
sfb 2011-06-07 12:14:10 -05:00
parent 884f74b01e
commit d0c381ed94
3 changed files with 137 additions and 36 deletions

View file

@ -9,6 +9,8 @@
#include <QColorDialog>
#include <QSettings>
#include <QTextStream>
#include <QFileDialog>
#include <QDirIterator>
#include "../core/icore.h"
#include "../core/imenu_manager.h"
@ -27,6 +29,7 @@ MissionCompilerMainWindow::MissionCompilerMainWindow(QWidget *parent) :
{
ui->setupUi(this);
m_lastDir = ".";
m_compileLog = "";
updateCompileLog();
@ -35,24 +38,11 @@ MissionCompilerMainWindow::MissionCompilerMainWindow(QWidget *parent) :
m_undoStack = new QUndoStack(this);
// Populate the "all" primitives box.
QStringList list;
std::vector<std::string> paths;
NLMISC::CPath::getFileList("primitive", paths);
std::vector<std::string>::iterator itr = paths.begin();
while( itr != paths.end() )
{
const char *path2 = (*itr).c_str();
list << path2;
++itr;
}
m_regexpFilter = new QRegExp();
m_regexpFilter->setPatternSyntax(QRegExp::FixedString);
m_regexpFilter->setCaseSensitivity(Qt::CaseInsensitive);
m_allPrimitivesModel = new QStringListModel(list, this);
m_allPrimitivesModel = new QStringListModel(this);
m_filteredProxyModel = new QSortFilterProxyModel(this);
m_filteredProxyModel->setSourceModel(m_allPrimitivesModel);
m_filteredProxyModel->setDynamicSortFilter(true);
@ -65,12 +55,63 @@ MissionCompilerMainWindow::MissionCompilerMainWindow(QWidget *parent) :
connect(ui->actionValidate, SIGNAL(triggered()), this, SLOT(handleValidation()));
connect(ui->actionCompile, SIGNAL(triggered()), this, SLOT(handleCompile()));
connect(ui->actionPublish, SIGNAL(triggered()), this, SLOT(handlePublish()));
connect(ui->allPrimitivesList, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(handleAllDoubleClick(const QModelIndex &)));
connect(ui->dataDirButton, SIGNAL(clicked()), this, SLOT(handleDataDirButton()));
connect(ui->dataDirEdit, SIGNAL(textChanged(const QString &)), this, SLOT(handleDataDirChanged(const QString &)));
// Set the default data dir to the primitives path.
QSettings *settings = Core::ICore::instance()->settings();
settings->beginGroup(Core::Constants::DATA_PATH_SECTION);
m_lastDir = settings->value(Core::Constants::PRIMITIVES_PATH).toString();
ui->dataDirEdit->setText(m_lastDir);
populateAllPrimitives(m_lastDir);
settings->endGroup();
NLLIGO::Register();
m_ligoConfig.readPrimitiveClass(NLMISC::CPath::lookup("world_editor_classes.xml").c_str(), false);
NLLIGO::CPrimitiveContext::instance().CurrentLigoConfig = &m_ligoConfig;
}
void MissionCompilerMainWindow::populateAllPrimitives(const QString &dataDir)
{
// First we need to clear out the models entirely.
QStringList emptyList;
m_selectedPrimitivesModel->setStringList(emptyList);
m_allPrimitivesModel->setStringList(emptyList);
// Populate the "all" primitives box.
QStringList list;
// Filter for only primitive files.
QStringList filters;
filters << "*.primitive";
QDirIterator it(dataDir, filters, QDir::Files, QDirIterator::Subdirectories|QDirIterator::FollowSymlinks);
while(it.hasNext())
{
it.next();
list << it.fileName();
}
m_allPrimitivesModel->setStringList(list);
}
void MissionCompilerMainWindow::handleDataDirChanged(const QString &text)
{
populateAllPrimitives(text);
}
void MissionCompilerMainWindow::handleDataDirButton()
{
QString newPath = QFileDialog::getExistingDirectory(this, "", m_lastDir);
if(!newPath.isEmpty())
{
ui->dataDirEdit->setText(newPath);
m_lastDir = newPath;
populateAllPrimitives(newPath);
}
}
void MissionCompilerMainWindow::handleFilterChanged(const QString &text)
{
m_regexpFilter->setPattern(text);
@ -87,6 +128,19 @@ void MissionCompilerMainWindow::handlePublish()
compileMission(true);
}
void MissionCompilerMainWindow::handleAllDoubleClick(const QModelIndex &index)
{
const QAbstractItemModel *model = index.model();
QString item = model->data(index).toString();
nlinfo("all primitives was double clicked: %s", item.toAscii().data());
m_filteredProxyModel->removeRows(index.row(),1);
QStringList list = m_selectedPrimitivesModel->stringList();
list << item;
m_selectedPrimitivesModel->setStringList(list);
}
void MissionCompilerMainWindow::compileMission(bool publish)
{
uint nbMission = 0;

View file

@ -38,11 +38,15 @@ public Q_SLOTS:
void handleValidation();
void handleCompile();
void handlePublish();
void handleAllDoubleClick(const QModelIndex &index);
void handleDataDirButton();
void handleDataDirChanged(const QString &text);
private:
Ui::MissionCompilerMainWindow *ui;
void updateCompileLog();
void populateAllPrimitives(const QString &dataDir = QString());
bool parsePrimForMissions(NLLIGO::IPrimitive const *prim, TMissionContainer &missions);
void compileMission(bool publish=false);
@ -53,6 +57,7 @@ private:
QSortFilterProxyModel *m_filteredProxyModel;
QRegExp *m_regexpFilter;
QString m_compileLog;
QString m_lastDir;
NLLIGO::CLigoConfig m_ligoConfig;
};

View file

@ -33,7 +33,7 @@
<string>Mission Compiler Options</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="4">
<item row="5" column="4">
<layout class="QVBoxLayout" name="addRemoveLayout">
<item>
<spacer name="verticalSpacer_3">
@ -132,7 +132,7 @@
</item>
</layout>
</item>
<item row="3" column="3">
<item row="5" column="3">
<widget class="QListView" name="allPrimitivesList">
<property name="acceptDrops">
<bool>true</bool>
@ -157,7 +157,7 @@
</property>
</widget>
</item>
<item row="3" column="5">
<item row="5" column="5">
<widget class="QListView" name="selectedPrimitivesList">
<property name="acceptDrops">
<bool>true</bool>
@ -182,21 +182,48 @@
</property>
</widget>
</item>
<item row="0" column="3">
<item row="4" column="3">
<widget class="QLabel" name="allPrimitivesLabel">
<property name="text">
<string>All Primitives</string>
</property>
</widget>
</item>
<item row="0" column="5">
<item row="4" column="5">
<widget class="QLabel" name="selectedPrimitivesLabel">
<property name="text">
<string>Selected Primitives</string>
</property>
</widget>
</item>
<item row="1" column="3">
<item row="0" column="3" colspan="3">
<widget class="QGroupBox" name="filterGroupBox">
<property name="title">
<string>Filter Criteria</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<layout class="QHBoxLayout" name="dataDirLayout">
<item>
<widget class="QLabel" name="dataDirLabel">
<property name="text">
<string>Data Directory</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="dataDirEdit"/>
</item>
<item>
<widget class="QToolButton" name="dataDirButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="filterLayout">
<item>
<widget class="QLabel" name="filterLabel">
@ -215,8 +242,23 @@
</layout>
</item>
</layout>
<zorder>horizontalLayoutWidget</zorder>
<zorder>dataDirLabel</zorder>
<zorder>horizontalLayoutWidget</zorder>
<zorder></zorder>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="publishOptionsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>776</width>
<height>426</height>
</rect>
</property>
<attribute name="label">
<string>Publish Options</string>
</attribute>