mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-04 17:24:47 +00:00
CHANGED: #1471 project files and project window now work differently. Project files define 2 kinds of files and the project window now displays both kinds in a treeview.
--HG-- branch : gsoc2012-gui-editor
This commit is contained in:
parent
f9bcc43d8c
commit
efb1d8a6aa
9 changed files with 196 additions and 67 deletions
|
@ -138,12 +138,10 @@ namespace GUIEditor
|
||||||
setCursor( Qt::ArrowCursor );
|
setCursor( Qt::ArrowCursor );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
SProjectFiles projectFiles;
|
||||||
std::vector< std::string > fileNames;
|
parser.getProjectFiles( projectFiles );
|
||||||
|
|
||||||
parser.getProjectFileNames( fileNames );
|
|
||||||
currentProject = parser.getProjectName().c_str();
|
currentProject = parser.getProjectName().c_str();
|
||||||
projectWindow->setupFileList( fileNames );
|
projectWindow->setupFiles( projectFiles );
|
||||||
|
|
||||||
setCursor( Qt::ArrowCursor );
|
setCursor( Qt::ArrowCursor );
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,10 +44,12 @@ namespace GUIEditor
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CProjectFileParser::getProjectFileNames( std::vector< std::string > &names ) const
|
void CProjectFileParser::getProjectFiles( SProjectFiles &projectFiles ) const
|
||||||
{
|
{
|
||||||
names.resize( fileNames.size() );
|
projectFiles.guiFiles.resize( files.guiFiles.size() );
|
||||||
std::copy( fileNames.begin(), fileNames.end(), names.begin() );
|
projectFiles.mapFiles.resize( files.mapFiles.size() );
|
||||||
|
std::copy( files.guiFiles.begin(), files.guiFiles.end(), projectFiles.guiFiles.begin() );
|
||||||
|
std::copy( files.mapFiles.begin(), files.mapFiles.end(), projectFiles.mapFiles.begin() );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CProjectFileParser::parseXMLFile(QFile &f)
|
bool CProjectFileParser::parseXMLFile(QFile &f)
|
||||||
|
@ -72,7 +74,10 @@ namespace GUIEditor
|
||||||
if( !parseHeader( reader ) )
|
if( !parseHeader( reader ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( !parseFiles( reader ) )
|
if( !parseGUIFiles( reader ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if( !parseMapFiles( reader ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -98,25 +103,57 @@ namespace GUIEditor
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CProjectFileParser::parseFiles( QXmlStreamReader &reader )
|
bool CProjectFileParser::parseGUIFiles( QXmlStreamReader &reader )
|
||||||
{
|
{
|
||||||
while( !reader.atEnd() && !( reader.isStartElement() && reader.name() == "files" ) )
|
while( !reader.atEnd() && !( reader.isStartElement() && reader.name() == "guifiles" ) )
|
||||||
reader.readNext();
|
reader.readNext();
|
||||||
if( reader.atEnd() )
|
if( reader.atEnd() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
while( !reader.atEnd() && !( reader.isEndElement() && ( reader.name() == "files" ) ) )
|
while( !reader.atEnd() && !( reader.isEndElement() && ( reader.name() == "guifiles" ) ) )
|
||||||
{
|
{
|
||||||
if( reader.isStartElement() && ( reader.name() == "file" ) )
|
if( reader.isStartElement() && ( reader.name() == "file" ) )
|
||||||
{
|
{
|
||||||
QString fileName = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement );
|
QString fileName = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement );
|
||||||
if( !fileName.isEmpty() )
|
if( fileName.isEmpty() )
|
||||||
fileNames.push_back( fileName.toStdString() );
|
return false;
|
||||||
|
files.guiFiles.push_back( fileName.toStdString() );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.readNext();
|
reader.readNext();
|
||||||
}
|
}
|
||||||
if( fileNames.empty() )
|
reader.readNext();
|
||||||
|
if( reader.atEnd() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if( files.guiFiles.empty() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CProjectFileParser::parseMapFiles( QXmlStreamReader &reader )
|
||||||
|
{
|
||||||
|
while( !reader.atEnd() && !( reader.isStartElement() && reader.name() == "mapfiles" ) )
|
||||||
|
reader.readNext();
|
||||||
|
if( reader.atEnd() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
while( !reader.atEnd() && !( reader.isEndElement() && ( reader.name() == "mapfiles" ) ) )
|
||||||
|
{
|
||||||
|
if( reader.isStartElement() && ( reader.name() == "file" ) )
|
||||||
|
{
|
||||||
|
QString fileName = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement );
|
||||||
|
if( fileName.isEmpty() )
|
||||||
|
return false;
|
||||||
|
files.mapFiles.push_back( fileName.toStdString() );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
reader.readNext();
|
||||||
|
}
|
||||||
|
if( files.mapFiles.empty() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
|
#include "project_files.h"
|
||||||
|
|
||||||
namespace GUIEditor
|
namespace GUIEditor
|
||||||
{
|
{
|
||||||
|
@ -34,14 +35,15 @@ namespace GUIEditor
|
||||||
|
|
||||||
bool parseProjectFile( std::string &name );
|
bool parseProjectFile( std::string &name );
|
||||||
const std::string& getProjectName() const{ return projectName; }
|
const std::string& getProjectName() const{ return projectName; }
|
||||||
void getProjectFileNames( std::vector< std::string > &names ) const;
|
void getProjectFiles( SProjectFiles &projectFiles ) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool parseXMLFile( QFile &f );
|
bool parseXMLFile( QFile &f );
|
||||||
bool parseHeader( QXmlStreamReader &reader );
|
bool parseHeader( QXmlStreamReader &reader );
|
||||||
bool parseFiles( QXmlStreamReader &reader );
|
bool parseGUIFiles( QXmlStreamReader &reader );
|
||||||
|
bool parseMapFiles( QXmlStreamReader &reader );
|
||||||
|
|
||||||
std::vector< std::string > fileNames;
|
SProjectFiles files;
|
||||||
std::string projectName;
|
std::string projectName;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
// Object Viewer Qt GUI Editor plugin <http://dev.ryzom.com/projects/ryzom/>
|
||||||
|
// 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 PROJECT_FILES_H
|
||||||
|
#define PROJECT_FILES_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace GUIEditor
|
||||||
|
{
|
||||||
|
struct SProjectFiles
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::vector< std::string > guiFiles;
|
||||||
|
std::vector< std::string > mapFiles;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -36,21 +36,57 @@ namespace GUIEditor
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectWindow::setupFileList( const std::vector< std::string > &fileNames )
|
void ProjectWindow::setupFiles( SProjectFiles &projectFiles )
|
||||||
{
|
{
|
||||||
fileList->clear();
|
QTreeWidgetItem *topItem = fileTree->topLevelItem( 0 );
|
||||||
|
if( topItem != NULL )
|
||||||
|
{
|
||||||
|
QList< QTreeWidgetItem* > childList = topItem->takeChildren();
|
||||||
|
QListIterator< QTreeWidgetItem* > it( childList );
|
||||||
|
while( it.hasNext() )
|
||||||
|
delete it.next();
|
||||||
|
childList.clear();
|
||||||
|
|
||||||
std::vector< std::string >::const_iterator itr;
|
std::vector< std::string >::iterator itr;
|
||||||
for( itr = fileNames.begin(); itr != fileNames.end(); ++itr )
|
for( itr = projectFiles.guiFiles.begin(); itr != projectFiles.guiFiles.end(); ++itr )
|
||||||
{
|
{
|
||||||
const std::string &s = *itr;
|
QTreeWidgetItem *item = new QTreeWidgetItem( topItem );
|
||||||
fileList->addItem( s.c_str() );
|
item->setText( 0, itr->c_str() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
topItem = fileTree->topLevelItem( 1 );
|
||||||
|
if( topItem != NULL )
|
||||||
|
{
|
||||||
|
QList< QTreeWidgetItem* > childList = topItem->takeChildren();
|
||||||
|
QListIterator< QTreeWidgetItem* > it( childList );
|
||||||
|
while( it.hasNext() )
|
||||||
|
delete it.next();
|
||||||
|
childList.clear();
|
||||||
|
|
||||||
|
std::vector< std::string >::iterator itr;
|
||||||
|
for( itr = projectFiles.mapFiles.begin(); itr != projectFiles.mapFiles.end(); ++itr )
|
||||||
|
{
|
||||||
|
QTreeWidgetItem *item = new QTreeWidgetItem( topItem );
|
||||||
|
item->setText( 0, itr->c_str() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fileList->sortItems();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectWindow::onAddButtonClicked()
|
void ProjectWindow::onAddButtonClicked()
|
||||||
{
|
{
|
||||||
|
if( fileTree->currentItem() == NULL )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QTreeWidgetItem *item = fileTree->currentItem();
|
||||||
|
QTreeWidgetItem *parent = item->parent();
|
||||||
|
|
||||||
|
while( parent != NULL )
|
||||||
|
{
|
||||||
|
item = parent;
|
||||||
|
parent = parent->parent();
|
||||||
|
}
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
QString newFile = QInputDialog::getText( this,
|
QString newFile = QInputDialog::getText( this,
|
||||||
tr( "Adding file to project" ),
|
tr( "Adding file to project" ),
|
||||||
|
@ -61,30 +97,33 @@ namespace GUIEditor
|
||||||
|
|
||||||
if( ok )
|
if( ok )
|
||||||
{
|
{
|
||||||
fileList->addItem( newFile );
|
QTreeWidgetItem *newItem = new QTreeWidgetItem( item );
|
||||||
fileList->sortItems();
|
newItem->setText( 0, newFile );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectWindow::onRemoveButtonClicked()
|
void ProjectWindow::onRemoveButtonClicked()
|
||||||
{
|
{
|
||||||
if( fileList->count() == 0 )
|
if( fileTree->currentItem() == NULL )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if( ( fileTree->topLevelItem( 0 )->childCount() == 0 ) || ( fileTree->topLevelItem( 1 )->childCount() == 0 ) )
|
||||||
|
return;
|
||||||
|
// Can't delete top-level item
|
||||||
|
if( fileTree->currentItem()->parent() == NULL )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QMessageBox::StandardButton reply;
|
QMessageBox::StandardButton reply;
|
||||||
QString text;
|
QString text = fileTree->currentItem()->text( 0 );
|
||||||
if( fileList->currentRow() >= 0 )
|
|
||||||
text = fileList->item( fileList->currentRow() )->text();
|
|
||||||
|
|
||||||
reply = QMessageBox::question( this,
|
reply = QMessageBox::question( this,
|
||||||
tr( "Removing file from project" ),
|
tr( "Removing file from project" ),
|
||||||
tr( "Are you sure you want to remove '%1' from the project?" ).arg( text ),
|
tr( "Are you sure you want to remove '%1' from the project?" ).arg( text ),
|
||||||
QMessageBox::Yes | QMessageBox::Cancel );
|
QMessageBox::Yes | QMessageBox::Cancel );
|
||||||
|
|
||||||
QListWidgetItem *item;
|
|
||||||
if( reply == QMessageBox::Yes )
|
if( reply == QMessageBox::Yes )
|
||||||
item = fileList->takeItem( fileList->currentRow() );
|
fileTree->currentItem()->parent()->removeChild( fileTree->currentItem() );
|
||||||
delete item;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "ui_project_window.h"
|
#include "ui_project_window.h"
|
||||||
|
#include "project_files.h"
|
||||||
|
|
||||||
namespace GUIEditor
|
namespace GUIEditor
|
||||||
{
|
{
|
||||||
|
@ -31,7 +32,7 @@ namespace GUIEditor
|
||||||
ProjectWindow( QWidget *parent = NULL );
|
ProjectWindow( QWidget *parent = NULL );
|
||||||
~ProjectWindow();
|
~ProjectWindow();
|
||||||
|
|
||||||
void setupFileList( const std::vector< std::string > &fileNames );
|
void setupFiles( SProjectFiles &projectFiles );
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void onAddButtonClicked();
|
void onAddButtonClicked();
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>379</width>
|
<width>451</width>
|
||||||
<height>335</height>
|
<height>320</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -15,7 +15,23 @@
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="0" column="0" rowspan="2" colspan="2">
|
<item row="0" column="0" rowspan="2" colspan="2">
|
||||||
<widget class="QListWidget" name="fileList"/>
|
<widget class="QTreeWidget" name="fileTree">
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Files</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>GUI XML files</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Texture map files</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="2">
|
<item row="0" column="2">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
|
Loading…
Reference in a new issue