Skip to content

Commit

Permalink
Rework interaction energy infodocuments (WIP), remove build cache for…
Browse files Browse the repository at this point in the history
… gh actions
  • Loading branch information
peterspackman committed Aug 28, 2024
1 parent 674795d commit df52e60
Show file tree
Hide file tree
Showing 15 changed files with 363 additions and 970 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ jobs:
with:
path: |
${{env.CPM_SOURCE_CACHE}}
${{github.workspace}}/build
key: crystalexplorer-cache-${{ matrix.name }}

- name: Install Qt
Expand Down
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ add_library(cx_core
"${CMAKE_CURRENT_SOURCE_DIR}/generic_atom_index.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/globalconfiguration.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/hbond_criteria.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/infotable.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/isosurface.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/isosurface_parameters.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/mesh.cpp"
Expand Down
68 changes: 68 additions & 0 deletions src/core/infotable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "infotable.h"
#include <QTextTableFormat>
#include <QTextCharFormat>
#include <QTextBlockFormat>

InfoTable::InfoTable(QTextCursor& cursor, int rows, int cols)
{
QTextTableFormat format;
format.setCellPadding(5.0);
format.setBorderStyle(QTextFrameFormat::BorderStyle_None);
format.setCellSpacing(-1.0);
format.setBorder(1.0);

m_table = cursor.insertTable(rows, cols, format);
}

InfoTable::~InfoTable()
{
// The QTextTable object is owned by the QTextDocument,
// so we don't need to delete it here.
}

void InfoTable::insertTableHeader(const QStringList& tableHeader)
{
const int row = 0;
QTextCharFormat format;
format.setFontWeight(QFont::Bold);

for (int column = 0; column < tableHeader.size() && column < m_table->columns(); ++column) {
QTextCursor cursor = getCellCursor(row, column);
cursor.setCharFormat(format);
cursor.insertText(tableHeader[column]);
}
}

void InfoTable::insertColorBlock(int row, int column, const QColor& color)
{
if (!color.isValid()) {
return;
}

QTextTableCell cell = m_table->cellAt(row, column);
QTextCharFormat format = cell.format();
format.setBackground(color);
cell.setFormat(format);

QTextCursor cursor = getCellCursor(row, column);
cursor.insertText(" ");
}

void InfoTable::insertCellValue(int row, int column, const QString& valueString, Qt::Alignment alignment)
{
QTextCursor cursor = getCellCursor(row, column);
QTextBlockFormat blockFormat = cursor.blockFormat();

// Preserve vertical alignment
Qt::Alignment vertAlign = blockFormat.alignment() & Qt::AlignVertical_Mask;
Qt::Alignment combAlign = alignment | vertAlign;

blockFormat.setAlignment(combAlign);
cursor.setBlockFormat(blockFormat);
cursor.insertText(valueString);
}

QTextCursor InfoTable::getCellCursor(int row, int column) const
{
return m_table->cellAt(row, column).firstCursorPosition();
}
21 changes: 21 additions & 0 deletions src/core/infotable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once
#include <QTextTable>
#include <QTextCursor>
#include <QStringList>
#include <QColor>

class InfoTable {
public:
InfoTable(QTextCursor& cursor, int rows, int cols);
~InfoTable();

void insertTableHeader(const QStringList& tableHeader);
void insertColorBlock(int row, int column, const QColor& color);
void insertCellValue(int row, int column, const QString& valueString, Qt::Alignment alignment = Qt::AlignLeft);

QTextTable* table() const { return m_table; }

private:
QTextCursor getCellCursor(int row, int column) const;
QTextTable* m_table;
};
29 changes: 8 additions & 21 deletions src/crystalx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
#include <QUrl>
#include <QtDebug>

#include "atominfodocument.h"
#include "confirmationbox.h"
#include "crystalx.h"
#include "dialoghtml.h"
#include "elementdata.h"
#include "exportdialog.h"
#include "infodocuments.h"
#include "isosurface_calculator.h"
#include "mathconstants.h"
#include "pair_energy_calculator.h"
Expand Down Expand Up @@ -196,8 +194,6 @@ void Crystalx::initFingerprintWindow() {
void Crystalx::initInfoViewer() {
infoViewer = new InfoViewer(this);
connect(infoViewer, &InfoViewer::tabChangedTo, this, &Crystalx::updateInfo);
connect(infoViewer, &InfoViewer::tabChangedTo, this,
&Crystalx::setInfoTabSpecificViewOptions);
connect(infoViewer, &InfoViewer::infoViewerClosed, this,
&Crystalx::tidyUpAfterInfoViewerClosed);
}
Expand Down Expand Up @@ -1904,31 +1900,22 @@ void Crystalx::handleStructureChange() {
// Info Documents
//
////////////////////////////////////////////////////////////////////////////////////
void Crystalx::showInfoViewer() { infoViewer->show(); }
void Crystalx::showInfoViewer() {
updateInfo(infoViewer->currentTab());
infoViewer->show();
}

void Crystalx::showInfo(InfoType infoType) {
updateInfo(infoType);
infoViewer->setTab(infoType);
showInfoViewer();
}

void Crystalx::updateInfo(InfoType infoType) {
Scene *scene = project->currentScene();
Q_ASSERT(scene);

switch (infoType) {
default: {
infoViewer->setScene(scene);
break;
}
case InfoType::InteractionEnergy: {
QTextDocument *document = infoViewer->document(infoType);
document->clear();
InfoDocuments::insertInteractionEnergiesIntoTextDocument(document, scene);
infoViewer->setDocument(document, infoType);
break;
}
}
if (!scene)
return;
setInfoTabSpecificViewOptions(infoType);
infoViewer->setScene(scene);
}

void Crystalx::setInfoTabSpecificViewOptions(InfoType infoType) {
Expand Down
3 changes: 1 addition & 2 deletions src/dialogs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ qt_add_library(cx_dialogs STATIC
"${CMAKE_CURRENT_SOURCE_DIR}/celllimitsdialog.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/closecontactcriteriawidget.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/closecontactsdialog.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/collapsibledocument.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/colordelegate.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/crystalinfodocument.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/depthfadingandclippingdialog.cpp"
Expand All @@ -37,8 +36,8 @@ qt_add_library(cx_dialogs STATIC
"${CMAKE_CURRENT_SOURCE_DIR}/fingerprintwindow.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/fileeditor.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/fragmentstatedialog.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/infodocuments.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/infoviewer.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/interactioninfodocument.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/packingdialog.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/periodictabledialog.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/planegenerationdialog.cpp"
Expand Down
104 changes: 0 additions & 104 deletions src/dialogs/collapsibledocument.cpp

This file was deleted.

42 changes: 0 additions & 42 deletions src/dialogs/collapsibledocument.h

This file was deleted.

Loading

0 comments on commit df52e60

Please sign in to comment.