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.

This commit is contained in:
dfighter1985 2012-07-19 08:11:08 +02:00
parent 19a087a0f7
commit b75a4a827e
9 changed files with 196 additions and 67 deletions

View file

@ -138,12 +138,10 @@ namespace GUIEditor
setCursor( Qt::ArrowCursor );
return;
}
std::vector< std::string > fileNames;
parser.getProjectFileNames( fileNames );
SProjectFiles projectFiles;
parser.getProjectFiles( projectFiles );
currentProject = parser.getProjectName().c_str();
projectWindow->setupFileList( fileNames );
projectWindow->setupFiles( projectFiles );
setCursor( Qt::ArrowCursor );
}

View file

@ -1,17 +1,17 @@
// 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
// 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/>.

View file

@ -1,17 +1,17 @@
// 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
// 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/>.

View file

@ -44,10 +44,12 @@ namespace GUIEditor
return true;
}
void CProjectFileParser::getProjectFileNames( std::vector< std::string > &names ) const
void CProjectFileParser::getProjectFiles( SProjectFiles &projectFiles ) const
{
names.resize( fileNames.size() );
std::copy( fileNames.begin(), fileNames.end(), names.begin() );
projectFiles.guiFiles.resize( files.guiFiles.size() );
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)
@ -72,7 +74,10 @@ namespace GUIEditor
if( !parseHeader( reader ) )
return false;
if( !parseFiles( reader ) )
if( !parseGUIFiles( reader ) )
return false;
if( !parseMapFiles( reader ) )
return false;
return true;
@ -98,25 +103,57 @@ namespace GUIEditor
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();
if( reader.atEnd() )
return false;
while( !reader.atEnd() && !( reader.isEndElement() && ( reader.name() == "files" ) ) )
while( !reader.atEnd() && !( reader.isEndElement() && ( reader.name() == "guifiles" ) ) )
{
if( reader.isStartElement() && ( reader.name() == "file" ) )
{
QString fileName = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement );
if( !fileName.isEmpty() )
fileNames.push_back( fileName.toStdString() );
if( fileName.isEmpty() )
return false;
files.guiFiles.push_back( fileName.toStdString() );
}
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 true;

View file

@ -22,6 +22,7 @@
#include <string>
#include <QFile>
#include <QXmlStreamReader>
#include "project_files.h"
namespace GUIEditor
{
@ -34,14 +35,15 @@ namespace GUIEditor
bool parseProjectFile( std::string &name );
const std::string& getProjectName() const{ return projectName; }
void getProjectFileNames( std::vector< std::string > &names ) const;
void getProjectFiles( SProjectFiles &projectFiles ) const;
private:
bool parseXMLFile( QFile &f );
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;
};
}

View file

@ -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

View file

@ -36,21 +36,57 @@ namespace GUIEditor
{
}
void ProjectWindow::setupFileList( const std::vector< std::string > &fileNames )
void ProjectWindow::setupFiles( SProjectFiles &projectFiles )
{
fileList->clear();
std::vector< std::string >::const_iterator itr;
for( itr = fileNames.begin(); itr != fileNames.end(); ++itr )
QTreeWidgetItem *topItem = fileTree->topLevelItem( 0 );
if( topItem != NULL )
{
const std::string &s = *itr;
fileList->addItem( s.c_str() );
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.guiFiles.begin(); itr != projectFiles.guiFiles.end(); ++itr )
{
QTreeWidgetItem *item = new QTreeWidgetItem( topItem );
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()
{
if( fileTree->currentItem() == NULL )
return;
QTreeWidgetItem *item = fileTree->currentItem();
QTreeWidgetItem *parent = item->parent();
while( parent != NULL )
{
item = parent;
parent = parent->parent();
}
bool ok;
QString newFile = QInputDialog::getText( this,
tr( "Adding file to project" ),
@ -61,30 +97,33 @@ namespace GUIEditor
if( ok )
{
fileList->addItem( newFile );
fileList->sortItems();
QTreeWidgetItem *newItem = new QTreeWidgetItem( item );
newItem->setText( 0, newFile );
}
}
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;
QMessageBox::StandardButton reply;
QString text;
if( fileList->currentRow() >= 0 )
text = fileList->item( fileList->currentRow() )->text();
QString text = fileTree->currentItem()->text( 0 );
reply = QMessageBox::question( this,
tr( "Removing file from project" ),
tr( "Are you sure you want to remove '%1' from the project?" ).arg( text ),
QMessageBox::Yes | QMessageBox::Cancel );
QListWidgetItem *item;
if( reply == QMessageBox::Yes )
item = fileList->takeItem( fileList->currentRow() );
delete item;
fileTree->currentItem()->parent()->removeChild( fileTree->currentItem() );
}
}

View file

@ -21,6 +21,7 @@
#include <vector>
#include <string>
#include "ui_project_window.h"
#include "project_files.h"
namespace GUIEditor
{
@ -31,7 +32,7 @@ namespace GUIEditor
ProjectWindow( QWidget *parent = NULL );
~ProjectWindow();
void setupFileList( const std::vector< std::string > &fileNames );
void setupFiles( SProjectFiles &projectFiles );
private Q_SLOTS:
void onAddButtonClicked();

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>379</width>
<height>335</height>
<width>451</width>
<height>320</height>
</rect>
</property>
<property name="windowTitle">
@ -15,7 +15,23 @@
</property>
<layout class="QGridLayout" name="gridLayout">
<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 row="0" column="2">
<layout class="QVBoxLayout" name="verticalLayout">