File indexing completed on 2024-04-21 05:43:35

0001 /***************************************************************************
0002  *   Copyright (C) 2004 by David Saxton                                    *
0003  *   david@bluehaze.org                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #ifndef SUBCIRCUITS_H
0012 #define SUBCIRCUITS_H
0013 
0014 #include <QObject>
0015 
0016 class CircuitDocument;
0017 class ECSubcircuit;
0018 class Subcircuits;
0019 inline Subcircuits *subcircuits();
0020 
0021 /**
0022 Interface for dealing with loading / saving / etc of subcircuits
0023 @author David Saxton
0024 */
0025 class Subcircuits : public QObject
0026 {
0027     Q_OBJECT
0028 public:
0029     ~Subcircuits() override;
0030     /**
0031      * Handles subcircuit creation when the user selects the subcircuit to be
0032      * created.
0033      * @param id Id of subcircuit; e.g. "sc/10"
0034      */
0035     static ECSubcircuit *createSubcircuit(int id, CircuitDocument *circuitDocument, bool newItem, const char *newId);
0036     /**
0037      * Loads a subcircuit into a subcircuit component
0038      */
0039     static void initECSubcircuit(int subcircuitId, ECSubcircuit *ecSubcircuit);
0040     /**
0041      * Reads in the config entries and adds the subcircuits found to the
0042      * component selector
0043      */
0044     static void loadSubcircuits();
0045     /**
0046      * Saves the given subcircuit to the appdata dir, updates the appropriate
0047      * config entries, and adds the subcircuit to the component selector.
0048      */
0049     static void addSubcircuit(const QString &name, const QString &subcircuitXml);
0050     /**
0051      * returns a path to the appdata dir, e.g. genFileName(2) might return
0052      * ~/.kde/share/apps/ktechlab/subcircuit_2.circuit
0053      */
0054     static QString genFileName(const int nextId);
0055     /**
0056      * Adds the given entry to the component selector
0057      */
0058     static void updateComponentSelector(int id, const QString &name);
0059 
0060 protected slots:
0061     void slotItemRemoved(const QString &id);
0062 
0063 private:
0064     Subcircuits();
0065 
0066     friend Subcircuits *subcircuits();
0067 };
0068 
0069 inline Subcircuits *subcircuits()
0070 {
0071     static Subcircuits *_subcircuits = new Subcircuits();
0072     return _subcircuits;
0073 }
0074 
0075 #endif