Skip to content

Commit

Permalink
Merge branch 'master' into enh/code_cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Young <[email protected]>
  • Loading branch information
TactfulDeity authored Nov 15, 2024
2 parents 3beea37 + ad91707 commit 2cff23d
Show file tree
Hide file tree
Showing 62 changed files with 2,371 additions and 3,311 deletions.
25 changes: 15 additions & 10 deletions .github/workflows/build_qt6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name: Qt6 Build Matrix
on: [push, pull_request, workflow_dispatch]

env:
QT_VERSION: 6.5.3
QT_VERSION: 6.8.0
# this is different from MACOSX_DEPLOYMENT_TARGET to prevent build problems
# we set MACOSX_DEPLOYMENT_TARGET later
MACOS_TARGET: 10.15
Expand Down Expand Up @@ -39,10 +39,10 @@ jobs:
}
- {
name: "macOS Qt6", artifact: "",
os: macos-13,
os: macos-latest,
cc: "clang", cxx: "clang++",
build_type: "Release",
cmake_flags: "-G Ninja",
cmake_flags: "-G Ninja -DCMAKE_OSX_ARCHITECTURES='arm64;x86_64'",
cpack_flags: "-G DragNDrop",
}
- {
Expand All @@ -65,11 +65,7 @@ jobs:
- name: Install Dependencies (macOS)
if: runner.os == 'macOS'
run: |
if uname -p | grep -q "arm" ; then
export PATH=/opt/homebrew/bin:$PATH
else # not self-hosted runner
brew install ninja eigen glew
fi
brew install ninja eigen glew
- name: Install Dependencies (Windows)
if: runner.os == 'Windows'
run: choco install ninja
Expand All @@ -92,11 +88,20 @@ jobs:
path: avogadrolibs

- name: Install Qt
if: runner.os != 'Windows'
uses: jurplel/install-qt-action@v3
with:
version: ${{ env.QT_VERSION }}
aqtversion: '==3.1.*'

- name: Install Qt (Windows)
if: runner.os == 'Windows'
uses: jurplel/install-qt-action@v3
with:
version: ${{ env.QT_VERSION }}
aqtversion: '==3.1.*'
modules: 'qt5compat'
host: windows
arch: win64_msvc2022_64

- name: Configure MSVC Command Prompt
if: runner.os == 'Windows'
Expand Down Expand Up @@ -135,7 +140,7 @@ jobs:
if (NOT result EQUAL 0)
message(FATAL_ERROR "Running tests failed!")
endif()
- name: Upload
if: matrix.config.artifact != 0
uses: actions/upload-artifact@v4
Expand Down
101 changes: 101 additions & 0 deletions .github/workflows/flatpak.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Build Flatpak

on: [push, pull_request, workflow_dispatch]

jobs:
flatpak:
name: "Flatpak"
runs-on: ubuntu-latest

steps:
- name: Install dependencies
run: sudo apt update -qq && sudo apt install -y -qq flatpak flatpak-builder

- name: Configure flatpak
run: flatpak remote-add --if-not-exists --user flathub https://dl.flathub.org/repo/flathub.flatpakrepo

- name: Configure git
run: git config --global protocol.file.allow always
# Have to do this because for a while git's handling of submodules was broken
# See https://github.com/flatpak/flatpak-builder/issues/495

- name: Checkout openchemistry
uses: actions/checkout@v4
with:
repository: openchemistry/openchemistry
submodules: false
path: openchemistry

- name: Checkout avogadroapp
uses: actions/checkout@v4
with:
repository: openchemistry/avogadroapp
path: openchemistry/avogadroapp

- name: Checkout avogadrolibs
uses: actions/checkout@v4
with:
path: openchemistry/avogadrolibs

- name: Checkout i18n
uses: actions/checkout@v4
with:
repository: openchemistry/avogadro-i18n
path: openchemistry/avogadro-i18n

- name: Checkout avogadrogenerators
uses: actions/checkout@v4
with:
repository: openchemistry/avogenerators
path: openchemistry/avogadrogenerators

- name: Checkout crystals
uses: actions/checkout@v4
with:
repository: openchemistry/crystals
path: openchemistry/crystals

- name: Checkout fragments
uses: actions/checkout@v4
with:
repository: openchemistry/fragments
path: openchemistry/fragments

- name: Checkout molecules
uses: actions/checkout@v4
with:
repository: openchemistry/molecules
path: openchemistry/molecules

- name: Checkout Flathub shared-modules
uses: actions/checkout@v4
with:
repository: flathub/shared-modules
path: shared-modules

- name: Set up tmate session
if: failure()
uses: mxschmitt/action-tmate@v3

- name: Move manifest
run: mv openchemistry/avogadroapp/flatpak/org.openchemistry.Avogadro2.yaml ./

- name: Build with flatpak-builder
run: flatpak-builder --force-clean --user --install-deps-from=flathub --arch=x86_64 --default-branch=test --repo=repo builddir org.openchemistry.Avogadro2.yaml

- name: Create bundle
run: flatpak build-bundle repo Avogadro2.flatpak org.openchemistry.Avogadro2 test

- name: Upload bundle
uses: actions/upload-artifact@v4
with:
path: Avogadro2.flatpak

- name: Cleanup
if: ${{ always() }} # To ensure this step runs even when earlier steps fail
shell: bash
run: |
ls -la ./
rm -rf ./* || true
rm -rf ./.??* || true
ls -la ./
2 changes: 2 additions & 0 deletions avogadro/core/layermanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ struct LayerData

virtual ~LayerData() = default;

virtual LayerData* clone() { return new LayerData(serialize()); };

/** get the saved data */
std::string getSave() const { return m_save; }

Expand Down
17 changes: 14 additions & 3 deletions avogadro/core/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#ifndef AVOGADRO_CORE_UTILITIES_H
#define AVOGADRO_CORE_UTILITIES_H

#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
Expand Down Expand Up @@ -39,10 +40,20 @@ inline std::vector<std::string> split(const std::string& string, char delimiter,
* @param search String that will be searched for.
* @return True if the string contains search, false otherwise.
*/
inline bool contains(const std::string& input, const std::string& search)
inline bool contains(const std::string& input, const std::string& search,
bool caseSensitive = true)
{
size_t found = input.find(search);
return found != std::string::npos;
if (caseSensitive) {
return input.find(search) != std::string::npos;
} else {
std::string inputLower = input;
std::string searchLower = search;
std::transform(inputLower.begin(), inputLower.end(), inputLower.begin(),
::tolower);
std::transform(searchLower.begin(), searchLower.end(), searchLower.begin(),
::tolower);
return inputLower.find(searchLower) != std::string::npos;
}
}

/**
Expand Down
10 changes: 7 additions & 3 deletions avogadro/qtgui/pluginlayermanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <avogadro/core/layermanager.h>
#include <cassert>
#include <iostream>

namespace Avogadro {
namespace QtGui {
Expand Down Expand Up @@ -79,22 +80,25 @@ class AVOGADROQTGUI_EXPORT PluginLayerManager : protected Core::LayerManager
/** @return custom data T derived from LayerData. if @p layer is equal to
* MaxIndex returns activeLayer */
template <typename T>
T& getSetting(size_t layer = MaxIndex)
T* getSetting(size_t layer = MaxIndex)
{
auto info = m_molToInfo[m_activeMolecule];

if (layer == MaxIndex) {
layer = info->layer.activeLayer();
}

assert(layer <= info->layer.maxLayer());
if (info->settings.find(m_name) == info->settings.end()) {
info->settings[m_name] = Core::Array<Core::LayerData*>();
}

// do we need to create new layers in the array?
while (info->settings[m_name].size() < layer + 1) {
info->settings[m_name].push_back(new T());
}
auto result = static_cast<T*>(info->settings[m_name][layer]);
return *result;
auto* result = static_cast<T*>(info->settings[m_name][layer]);
return result;
}

private:
Expand Down
10 changes: 6 additions & 4 deletions avogadro/qtgui/rwlayermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class AddLayerCommand : public QUndoCommand
auto value = names.second[activeLayer];
m_settings[names.first] = value;
}

}

void redo() override
Expand All @@ -59,7 +58,9 @@ class AddLayerCommand : public QUndoCommand
m_moleculeInfo->enable[enable.first].push_back(enable.second);
}
for (const auto& settings : m_settings) {
m_moleculeInfo->settings[settings.first].push_back(settings.second);
// create newSettings pointer with the same type as settings.second
auto* newSettings = settings.second->clone();
m_moleculeInfo->settings[settings.first].push_back(newSettings);
}

m_moleculeInfo->layer.addLayer();
Expand Down Expand Up @@ -130,7 +131,8 @@ class RemoveLayerCommand : public QUndoCommand
RemoveLayerCommand(shared_ptr<MoleculeInfo> mol, size_t layer)
: QUndoCommand(QObject::tr("Modify Layers")), m_moleculeInfo(mol),
m_layer(layer)
{}
{
}

void redo() override
{
Expand Down Expand Up @@ -285,4 +287,4 @@ Array<std::pair<size_t, string>> RWLayerManager::activeMoleculeNames() const
return result;
}

} // namespace Avogadro
} // namespace Avogadro::QtGui
Loading

0 comments on commit 2cff23d

Please sign in to comment.