Documentation for OpenFLUID 2.2.1
WareSrcWidgetCollection.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2021-2026, INRAE
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30  */
31 
32 
33 /**
34  @file WareSrcWidgetCollection.hpp
35 
36  @author Aline LIBRES <aline.libres@gmail.com>
37  @author Jean-Christophe Fabre <jean-christophe.fabre@inra.fr>
38  @author Armel THÖNI <armel.thoni@inrae.fr>
39 */
40 
41 
42 #ifndef __OPENFLUID_UIWARESDEV_WARESRCWIDGETCOLLECTION_HPP__
43 #define __OPENFLUID_UIWARESDEV_WARESRCWIDGETCOLLECTION_HPP__
44 
45 
46 #include <QObject>
47 #include <QMap>
48 #include <QString>
49 #include <QTextDocument>
50 
51 #include <openfluid/dllexport.hpp>
59 
60 
61 class QTabWidget;
62 
63 
64 namespace openfluid {
65 
66 namespace waresdev {
67 class WareSrcEnquirer;
68 }
69 
70 
71 namespace ui { namespace waresdev {
72 
73 class WareSrcWidget;
74 class FindReplaceDialog;
75 
76 
77 class MigrationWorker : public QObject
78 {
79  Q_OBJECT
80 
81  private:
82 
83  QString m_WarePath;
84 
85  bool m_Verbose;
86 
87  bool m_CheckoutNew;
88 
89 
90  signals:
91 
92  void finished(bool Ok, const QString& Message);
93 
94  void info(const QString& Message);
95 
96  void warning(const QString& Message);
97 
98  void error(const QString& Message);
99 
100  void progressed(int Value);
101 
102  public slots :
103 
104  void run()
105  {
106  auto Listener = std::make_unique<WareMigrationListener>();
107 
108  Listener->setVerbose(m_Verbose);
109 
110  connect(Listener.get(), SIGNAL(info(const QString&)), this,
111  SIGNAL(info(const QString&)));
112  connect(Listener.get(), SIGNAL(warning(const QString&)), this,
113  SIGNAL(warning(const QString&)));
114  connect(Listener.get(), SIGNAL(error(const QString&)), this,
115  SIGNAL(error(const QString&)));
116  connect(Listener.get(), SIGNAL(progressed(int)), this,
117  SIGNAL(progressed(int)));
118 
119  auto Migrator = openfluid::waresdev::WareSrcMigrator(m_WarePath.toStdString(),
120  Listener.get());
121 
122  try
123  {
124  Migrator.performMigration();
125 
126  // no thrown exception means that migration is successful
127  if (m_CheckoutNew)
128  {
129  GitUIProxy Git;
130  bool SuccessfulCheckout = false;
131  if (Git.checkout(m_WarePath, GitUIProxy::getCurrentOpenFLUIDBranchName(), false))
132  {
133  SuccessfulCheckout = true;
134  }
135  else
136  {
137  if (Git.checkout(m_WarePath, GitUIProxy::getCurrentOpenFLUIDBranchName(), true))
138  {
139  SuccessfulCheckout = true;
140  }
141  }
142 
143  if(SuccessfulCheckout)
144  {
145  emit info(tr("Successful checkout of the current OpenFLUID version branch"));
146  }
147  else
148  {
149  emit error(tr("Unable to checkout branch corresponding to current OpenFLUID version branch."));
150  }
151  }
152  emit finished(true, "Migration succeeded");
153  }
154  catch (std::exception& e)
155  {
156  emit error(e.what());
157  emit finished(false, "Migration failed");
158  }
159  }
160 
161 
162  public:
163 
164  explicit MigrationWorker(const QString& WarePath, bool Verbose=false, bool CheckoutNew=false):
165  m_WarePath(WarePath), m_Verbose(Verbose), m_CheckoutNew(CheckoutNew)
166  {
167  }
168 
169 };
170 
171 
173 {
174  Q_OBJECT
175 
176 
177  private slots:
178 
179  void onWareTxtModified(WareSrcWidget* Widget, bool Modified);
180 
181  void onCloseWareTabRequested(int Index);
182 
183  void onCurrentTabChanged(int Index);
184 
185  void onFindReplaceRequested(FindReplaceDialog::FindReplaceAction Action, const QString& StringToFind,
186  const QString& StringForReplace, QTextDocument::FindFlags Options);
187 
188  void checkModifiedStatus();
189 
190  void notifyConfigureLaunched(openfluid::ware::WareType Type, const QString& ID);
191 
192  void notifyConfigureFinished(openfluid::ware::WareType Type, const QString& ID);
193 
194  void notifyBuildLaunched(openfluid::ware::WareType Type, const QString& ID);
195 
196  void notifyBuildFinished(openfluid::ware::WareType Type, const QString& ID);
197 
198  void onOperationRequestedOnWare(const QString& OperationCode, const QString& WarePath);
199 
200 
201  private:
202 
203  QTabWidget* mp_TabWidget;
204 
205  bool m_IsStandalone;
206 
207  openfluid::waresdev::WareBuildOptions m_DefaultWareBuildOptions;
208 
209  const openfluid::base::WorkspaceManager* mp_Manager;
210 
211  /**
212  * List of opened ware widgets by their absolute path
213  */
214  QMap<QString, WareSrcWidget*> m_WareSrcWidgetByPath;
215 
218  unsigned int m_DefaultBuildJobs;
219 
220  FindReplaceDialog* mp_FindReplaceDialog;
221 
222  WareSrcWidget* currentWareWidget();
223 
224  bool isModified() const;
225 
226  bool isProcessRunning() const;
227 
228  void closeWareTab(WareSrcWidget* Ware);
229 
230  void openWare(openfluid::ware::WareType Type, const QString& Title);
231 
232  void newWare(openfluid::ware::WareType Type);
233 
234  bool requestWareTabClosing(WareSrcWidget* Ware);
235 
236 
237  signals:
238 
239  void editorSaved();
240 
241  void currentTabChanged(const QString& Path);
242 
243  void modifiedStatusChanged(bool CurrentEditorModified, bool FileOpen, bool CurrentWareModified);
244 
245  void testStatusChanged(bool Enabled);
246 
247  void configureLaunched(openfluid::ware::WareType Type, const QString& ID);
248 
249  void configureFinished(openfluid::ware::WareType Type, const QString& ID);
250 
251  void buildLaunched(openfluid::ware::WareType Type, const QString& ID);
252 
253  void buildFinished(openfluid::ware::WareType Type, const QString& ID);
254 
255 
256  public slots:
257 
258  void editSignatureRequested(const QString& Path="");
259 
260  bool openPath(const QString& Path);
261 
262  // generates ware widget and opens signature dialog if asked
263  void openWarePath(const std::string& WarePath, bool EditSignature);
264 
265  void setCurrent(const QString& Path);
266 
267  QString getContextualPath(const QString& Path);
268 
270 
271  void openExplorer(const QString& Path = "");
272 
274 
275  void openTerminal(const QString& Path = "");
276 
277  void openExternalTool(const QString& Command, const QString& Path = "");
278 
280 
282 
283  void setBuildJobs(unsigned int Jobs);
284 
285  void configure();
286 
287  void build();
288 
289  void test();
290 
291  void generateDoc();
292 
294 
295  /**
296  @param TopDirectory The path to the topmost directory where may be saved the file,
297  an empty string meaning the current ware directory
298  @return The path where has been saved the file if it's above this ware, an empty string otherwise
299  */
300  QString saveAs(const QString& TopDirectory = "");
301 
303 
305 
306  void openFile();
307 
309 
310  void openObserver();
311 
313 
314  void newFile();
315 
317 
318  void newSimulator();
319 
321 
322  void newObserver();
323 
325 
327 
328  void copyText();
329 
330  void cutText();
331 
332  void pasteText();
333 
334  void openAPIDoc();
335 
336  void goToLine();
337 
338  void closeEditor(const QString& FilePath);
339 
340  void closeEditorsInFolderFromWare(const QString& WarePath, const QString& FolderPath, const bool Confirm);
341 
343 
344  void onWareChange(const QString& WarePath);
345 
346 
347  public:
348 
349  WareSrcWidgetCollection(QTabWidget* TabWidget, bool IsStandalone);
350 
352 
353  /**
354  Returns false is there is unchanged modifications and user chooses to cancel closing, true otherwise
355  */
357 
358  QStringList getOpenWarePaths();
359 
361 
362  bool isFileOpen();
363 
364  bool isDebugMode();
365 
367 
368  void duplicateWare(const QString& WarePath, const QString& NewWareName);
369 
370  void deleteWare(const QString& WarePath);
371 
372 };
373 
374 
375 } } } // namespaces
376 
377 
378 #endif /* __OPENFLUID_UIWARESDEV_WARESRCWIDGETCOLLECTION_HPP__ */
Definition: WorkspaceManager.hpp:55
Definition: FindReplaceDialog.hpp:62
FindReplaceAction
Definition: FindReplaceDialog.hpp:68
Definition: GitUIProxy.hpp:64
bool checkout(const QString &Path, const QString &BranchName, bool New=false)
static QString getCurrentOpenFLUIDBranchName()
Definition: WareSrcWidgetCollection.hpp:78
void warning(const QString &Message)
void error(const QString &Message)
void info(const QString &Message)
MigrationWorker(const QString &WarePath, bool Verbose=false, bool CheckoutNew=false)
Definition: WareSrcWidgetCollection.hpp:164
void run()
Definition: WareSrcWidgetCollection.hpp:104
void finished(bool Ok, const QString &Message)
Definition: WareSrcWidgetCollection.hpp:173
void configureFinished(openfluid::ware::WareType Type, const QString &ID)
void setBuildMode(openfluid::waresdev::WareSrcContainer::BuildMode Mode)
void onWareChange(const QString &WarePath)
QString saveAs(const QString &TopDirectory="")
void closeEditor(const QString &FilePath)
void modifiedStatusChanged(bool CurrentEditorModified, bool FileOpen, bool CurrentWareModified)
void openWarePath(const std::string &WarePath, bool EditSignature)
QString getContextualPath(const QString &Path)
WareSrcWidgetCollection(QTabWidget *TabWidget, bool IsStandalone)
void buildLaunched(openfluid::ware::WareType Type, const QString &ID)
void setConfigureMode(openfluid::waresdev::WareSrcContainer::ConfigMode Mode)
void buildFinished(openfluid::ware::WareType Type, const QString &ID)
void duplicateWare(const QString &WarePath, const QString &NewWareName)
void newSimulatorFromGhost(const openfluid::ware::SimulatorSignature &Signature)
void configureLaunched(openfluid::ware::WareType Type, const QString &ID)
void deleteWare(const QString &WarePath)
void editSignatureRequested(const QString &Path="")
void closeEditorsInFolderFromWare(const QString &WarePath, const QString &FolderPath, const bool Confirm)
void openExternalTool(const QString &Command, const QString &Path="")
Definition: WareSrcWidget.hpp:71
Definition: SimulatorSignature.hpp:262
BuildMode
Definition: WareSrcContainer.hpp:66
ConfigMode
Definition: WareSrcContainer.hpp:61
Definition: WareSrcMigrator.hpp:58
#define OPENFLUID_API
Definition: dllexport.hpp:86
FilesystemPath Path
Definition: FilesystemPath.hpp:308
WareType
Definition: TypeDefs.hpp:61
Definition: ApplicationException.hpp:47
Definition: WareBuildOptions.hpp:60