Skip to content

Commit

Permalink
Use the loadClassContentString API for cut, copy and paste (#11598)
Browse files Browse the repository at this point in the history
Instead of using the OMEdit internal structures for pasting elements use `loadClassContentString` to merge.
Generate the Modelica code from the selected elements and then merge the code using `loadClassContentString`.
Put the data in the form of string and JSON on the clipboard. Use it when paste is called.
  • Loading branch information
adeas31 committed Nov 27, 2023
1 parent a654bda commit 2794f15
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 163 deletions.
26 changes: 18 additions & 8 deletions OMEdit/OMEditLIB/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -2793,13 +2793,6 @@ void unloadHelper(LibraryTreeItem *pLibraryTreeItem)
MainWindow *pMainWindow = MainWindow::instance();
/* close the ModelWidget of LibraryTreeItem. */
if (pLibraryTreeItem->getModelWidget()) {
// clear model from clipboard
if (QApplication::clipboard()->mimeData() && QApplication::clipboard()->mimeData()->hasFormat(Helper::cutCopyPasteFormat)) {
const MimeData *pMimeData = qobject_cast<const MimeData*>(QApplication::clipboard()->mimeData());
if (pMimeData && pMimeData->getName().compare(pLibraryTreeItem->getNameStructure()) == 0) {
QApplication::clipboard()->clear();
}
}
// if ModelWidget is used by DiagramWindow
if (MainWindow::instance()->getPlotWindowContainer()->getDiagramSubWindowFromMdi()
&& MainWindow::instance()->getPlotWindowContainer()->getDiagramWindow()->getModelWidget() == pLibraryTreeItem->getModelWidget()) {
Expand Down Expand Up @@ -3196,7 +3189,24 @@ void LibraryTreeView::libraryTreeItemExpanded(LibraryTreeItem *pLibraryTreeItem)
*/
void LibraryTreeView::copyClassPathHelper(const QString &classPath)
{
QApplication::clipboard()->setText(classPath);
QClipboard *pClipboard = QApplication::clipboard();
if (!pClipboard) {
MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, "Unable to get the clipboard using QApplication::clipboard().",
Helper::scriptingKind, Helper::errorLevel));
pClipboard = qApp->clipboard();
if (!pClipboard) {
MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, "Unable to get the clipboard using qApp->clipboard().",
Helper::scriptingKind, Helper::errorLevel));
pClipboard = QGuiApplication::clipboard();
if (!pClipboard) {
MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, "Unable to get the clipboard using QGuiApplication::clipboard().",
Helper::scriptingKind, Helper::errorLevel));
}
}
}
if (pClipboard) {
pClipboard->setText(classPath);
}
}

/*!
Expand Down

0 comments on commit 2794f15

Please sign in to comment.