Skip to content

Commit

Permalink
add tests for mainwindow (#58)
Browse files Browse the repository at this point in the history
* add tests for mainwindow

* Fix unselecting viewport style, changed ambient light dialog to not block the app, and added tests

* unselect the viewport style when adding custom viewports

* fix crash when pressing remove on empty scene

* removed unecessary todo

* Fix GH Actions breaking

* fix actions
  • Loading branch information
fernandotonon committed Mar 31, 2024
1 parent 3aa0f3f commit 5808820
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 28 deletions.
24 changes: 18 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: change folder permissions
run: sudo chmod -R 777 /usr/local
run: |
sudo chmod -R 777 /usr/local/lib
sudo chmod -R 777 /usr/local/include
- name: Cache Assimp
id: cache-assimp-linux
Expand Down Expand Up @@ -278,7 +280,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: change folder permissions
run: sudo chmod -R 777 /usr/local
run: |
sudo chmod -R 777 /usr/local/lib
sudo chmod -R 777 /usr/local/include
sudo chmod -R 777 /usr/local/share
- name: Cache Ogre
id: cache-ogre-linux
Expand Down Expand Up @@ -366,7 +371,11 @@ jobs:
target: 'desktop'
arch: 'gcc_64'

- run: sudo chmod -R 777 /usr/local
- name: change folder permissions
run: |
sudo chmod -R 777 /usr/local/lib
sudo chmod -R 777 /usr/local/include
sudo chmod -R 777 /usr/local/share
- name: Cache Assimp
id: cache-assimp-linux
Expand Down Expand Up @@ -503,9 +512,11 @@ jobs:
target: 'desktop'
arch: 'gcc_64'

- run: sudo chmod -R 777 /usr/local/lib
- run: sudo chmod -R 777 /usr/local/include
- run: sudo chmod -R 777 /usr/local/share
- name: change folder permissions
run: |
sudo chmod -R 777 /usr/local/lib
sudo chmod -R 777 /usr/local/include
sudo chmod -R 777 /usr/local/share
- name: Cache Assimp
id: cache-assimp-linux
Expand Down Expand Up @@ -582,6 +593,7 @@ jobs:
env:
QT_QPA_PLATFORM: minimal
QT_DEBUG_PLUGINS: 1
DISPLAY: :99
run: |
export QT_QPA_PLATFORM="minimal"
export QT_DEBUG_PLUGINS=1
Expand Down
4 changes: 2 additions & 2 deletions src/Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void Manager::destroySceneNode(const QString & name)
}
void Manager::destroySceneNode(Ogre::SceneNode* node)
{
if(!node)
if(!node || isForbiddenNodeName(node->getName().c_str()))
return;


Expand Down Expand Up @@ -300,7 +300,7 @@ bool Manager::isForbiddenNodeName(const QString &_name)
||_name=="GridLine_node" //TODO add a define for GridLine_node
||_name==SELECTIONBOX_OBJECT_NAME
||_name==TRANSFORM_OBJECT_NAME
||_name.startsWith("Unnamed_")); //TODO find what is this <- Done, it's the cameras's nodes
||_name.startsWith("Unnamed_")); //This is the cameras's nodes
}

bool Manager::hasAnimationName(Ogre::Entity *entity, const QString &_name)
Expand Down
49 changes: 36 additions & 13 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
#include "animationcontrolwidget.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::MainWindow)
,isPlaying(false), m_pRoot(nullptr), m_pTimer(nullptr)
,m_pTransformWidget(nullptr),m_pPrimitivesWidget(nullptr), m_pMaterialWidget(nullptr),
customPaletteColorDialog(new QColorDialog(this))
QMainWindow(parent), ui(new Ui::MainWindow),
isPlaying(false), m_pRoot(nullptr), m_pTimer(nullptr),
m_pTransformWidget(nullptr),m_pPrimitivesWidget(nullptr), m_pMaterialWidget(nullptr),
customPaletteColorDialog(new QColorDialog(this)),
ambientLightColorDialog(new QColorDialog(this))
{
ui->setupUi(this);

Expand Down Expand Up @@ -56,11 +57,20 @@ MainWindow::MainWindow(QWidget *parent) :
} else {
ui->actionDark->setChecked(true);
}

customPaletteColorDialog->setOption(QColorDialog::DontUseNativeDialog);
customPaletteColorDialog->setObjectName("Custom Color Dialog");
QObject::connect(customPaletteColorDialog,&QColorDialog::colorSelected,this,[=](const QColor &color){
custom_Palette_Color_Selected(color);
});

ambientLightColorDialog->setOption(QColorDialog::DontUseNativeDialog);
ambientLightColorDialog->setObjectName("Ambient Light Color Dialog");
QObject::connect(ambientLightColorDialog,&QColorDialog::colorSelected,this,[=](const QColor &color){
if(color.isValid())
Manager::getSingleton()->getSceneMgr()->setAmbientLight( Ogre::ColourValue(color.redF(),color.greenF(),color.blueF()) );
});

///// Workaround, when using mRoot->startRendering() there's a flickering effect on the grid
m_pTimer = new QTimer(this);
connect(m_pTimer, &QTimer::timeout, this, [this](){
Expand Down Expand Up @@ -378,11 +388,6 @@ void MainWindow::importMeshs(const QStringList &_uriList)
MeshImporterExporter::importer(_uriList/*, &lastImported*/);
}

QColorDialog* MainWindow::getCustomPaletteColorDialog() const
{
return customPaletteColorDialog;
}

void MainWindow::on_actionExport_Selected_triggered()
{
// TODO add a descritpion so that the user could know what he is saving (scenenode name in MeshExporter)
Expand Down Expand Up @@ -518,6 +523,16 @@ void MainWindow::createEditorViewport(/*TODO add the type of view (perspective,

// TODO add some procedure to determine where to create the new widget so that it looks like 2x2 matrix view
// it should determine the position of the existing Docked Widget

ui->actionSingle->blockSignals(true);
ui->action1x1_Side_by_Side->blockSignals(true);
ui->action1x1_Upper_and_Lower->blockSignals(true);
ui->actionSingle->setChecked(false);
ui->action1x1_Side_by_Side->setChecked(false);
ui->action1x1_Upper_and_Lower->setChecked(false);
ui->actionSingle->blockSignals(false);
ui->action1x1_Side_by_Side->blockSignals(false);
ui->action1x1_Upper_and_Lower->blockSignals(false);
}

void MainWindow::onWidgetClosing(EditorViewport* const& widget)
Expand All @@ -544,6 +559,9 @@ void MainWindow::on_actionSingle_toggled(bool arg1)
ui->actionSingle->setChecked(true);
ui->action1x1_Side_by_Side->setChecked(false);
ui->action1x1_Upper_and_Lower->setChecked(false);
} else { //Doesn't allow unchecking
ui->actionSingle->setChecked( !ui->action1x1_Side_by_Side->isChecked() &&
!ui->action1x1_Upper_and_Lower->isChecked());
}
}

Expand All @@ -565,6 +583,9 @@ void MainWindow::on_action1x1_Side_by_Side_toggled(bool arg1)
ui->actionSingle->setChecked(false);
ui->action1x1_Side_by_Side->setChecked(true);
ui->action1x1_Upper_and_Lower->setChecked(false);
} else { //Doesn't allow unchecking
ui->action1x1_Side_by_Side->setChecked( !ui->actionSingle->isChecked() &&
!ui->action1x1_Upper_and_Lower->isChecked());
}
}

Expand All @@ -587,6 +608,9 @@ void MainWindow::on_action1x1_Upper_and_Lower_toggled(bool arg1)
ui->actionSingle->setChecked(false);
ui->action1x1_Side_by_Side->setChecked(false);
ui->action1x1_Upper_and_Lower->setChecked(true);
} else { //Doesn't allow unchecking
ui->action1x1_Upper_and_Lower->setChecked( !ui->actionSingle->isChecked() &&
!ui->action1x1_Upper_and_Lower->isChecked());
}
}

Expand All @@ -610,10 +634,9 @@ void MainWindow::on_actionAdd_Resource_location_triggered()

void MainWindow::on_actionChange_Ambient_Light_triggered()
{
Ogre::ColourValue ambientLightColour = Manager::getSingleton()->getSceneMgr()->getAmbientLight();
QColor c = QColorDialog::getColor(QColor::fromRgbF(ambientLightColour.r, ambientLightColour.g, ambientLightColour.b), this, tr("Choose background color"), QColorDialog::DontUseNativeDialog);
if(c.isValid())
Manager::getSingleton()->getSceneMgr()->setAmbientLight( Ogre::ColourValue(c.redF(),c.greenF(),c.blueF()) );
Ogre::ColourValue c = Manager::getSingleton()->getSceneMgr()->getAmbientLight();
ambientLightColorDialog->setCurrentColor(QColor(c.r*255,c.g*255,c.b*255,c.a*255));
ambientLightColorDialog->show();
}

void MainWindow::on_actionLight_toggled(bool arg1)
Expand Down
2 changes: 1 addition & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class MainWindow : public QMainWindow, public Ogre::FrameListener
explicit MainWindow(QWidget *parent = nullptr);
virtual ~MainWindow();
void importMeshs(const QStringList &_uriList);
QColorDialog* getCustomPaletteColorDialog(void) const;

private slots:
void on_actionImport_triggered();
Expand Down Expand Up @@ -87,6 +86,7 @@ public slots:
bool isPlaying;
QString mCurrentPalette;
QColorDialog* customPaletteColorDialog;
QColorDialog* ambientLightColorDialog;

void custom_Palette_Color_Selected(const QColor& color);
protected:
Expand Down
Loading

0 comments on commit 5808820

Please sign in to comment.