Commit c7771ed1 authored by Gerrit Erichsen's avatar Gerrit Erichsen
Browse files

data clearance upon project loading

parent 38076c45
......@@ -1085,7 +1085,8 @@ bool CharLGui::saveProject()
bool CharLGui::loadProject()
{
QString filename = QFileDialog::getOpenFileName(this, tr("CharL - Load Project"), "", tr("XML File (*.xml);;All Files (*.*)"));
QString filename = QFileDialog::getOpenFileName(this, tr("CharL - Load Project"), "",
tr("XML File (*.xml);;All Files (*.*)"));
QFile file(filename);
if (!file.open(QIODevice::ReadOnly))
{
......@@ -1104,6 +1105,23 @@ bool CharLGui::loadProject()
return false;
}
file.close();
//requesting if user already entered data and - if so - if to delete data or abort ------------
if (hasAnyoneData())
{
int reply = QMessageBox::warning(this, tr("CharL - About to delete data"),
tr("Loading project requires to remove entered data\n"
"Proceed?"),
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes)
{
clearAllData();
}
else
{
return false;
}
}
//actually read data --------------------------------------------------------------------------
QDomElement root = project.firstChildElement("CharL_project");
if (!root.isNull())
{
......@@ -1281,4 +1299,41 @@ bool CharLGui::loadProject()
return false;
}
return true;
}
}
bool CharLGui::hasAnyoneData()
{
if (m_modelConventional->rowCount() > 0) return true;
if (m_modelStorage->rowCount() > 0) return true;
if (m_modelWind->rowCount() > 0) return true;
if (m_modelSolar->rowCount() > 0) return true;
if (m_modelWindData->rowCount() > 0) return true;
if (m_modelSolarData->rowCount() > 0) return true;
if (m_modelTemperatureData->rowCount() > 0) return true;
if (m_modelPowerDemandData->rowCount() > 0) return true;
if (m_modelModulesPV->rowCount() > 1) return true;
if (m_modelGridCapacities->rowCount() > 0) return true;
if (m_modelGridImpedances->rowCount() > 0) return true;
if (m_modelGridImpedancesReactance->rowCount() > 0) return true;
if (m_modelLocations->rowCount() > 0) return true;
if (m_modelNodes->rowCount() > 0) return true;
return false;
}
void CharLGui::clearAllData()
{
m_modelConventional->clearData();
m_modelStorage->clearData();
m_modelWind->clearData();
m_modelSolar->clearData();
m_modelWindData->clearData();
m_modelSolarData->clearData();
m_modelTemperatureData->clearData();
m_modelPowerDemandData->clearData();
m_modelModulesPV->clearData();
m_modelGridCapacities->clearData();
m_modelGridImpedances->clearData();
m_modelGridImpedancesReactance->clearData();
m_modelLocations->clearData();
m_modelNodes->clearData();
}
......@@ -80,6 +80,8 @@ private:
void updateOptimisationProgressBar(int current);
bool saveProject();
bool loadProject();
bool hasAnyoneData();
void clearAllData();
private:
/// Layout and widgets
......
......@@ -56,6 +56,8 @@ public:
virtual void readFromXml(QDomElement element);
virtual QString getParentXmlTag() const;
virtual void clearData() = 0;
protected:
QString m_xmlTagParent;
QString m_xmlTag;
......
......@@ -63,6 +63,8 @@ public:
virtual void writeToXml(QDomDocument doc, QDomElement element);
virtual void readFromXml(QDomElement element);
virtual void clearData() = 0;
void showEconomics(bool show);
bool displaysEconomics() const;
......
......@@ -619,6 +619,16 @@ const AbstractCharLItem * ConfigTableModel::getItem(int row) const
return nullptr;
}
void ConfigTableModel::clearData()
{
if (m_data.count() > 0)
{
beginRemoveRows(QModelIndex(), 0, m_data.count() - 1);
m_data.clear();
endRemoveRows();
}
}
/////////////////////////////////////////////////////////////////////////////////////
/// \brief ConfigTableModel::getNumberOfVariationsForItem
/// \param itemIndex
......
......@@ -78,22 +78,24 @@ class ConfigTableModel : public AbstractCharLTableModel
public:
enum class AdditionalInfo {Capacity, Area, None};
public:
ConfigTableModel(AdditionalInfo addInfo = AdditionalInfo::None, QObject * parent = 0);
ConfigTableModel(AdditionalInfo addInfo = AdditionalInfo::None, QObject * parent = nullptr);
// default functions reimplemented as demanden by QAbstractTableModel
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
// own functions
void addItem(const AbstractCharLItem & item);
bool addItem(const QStringList & entries);
void addItem(const AbstractCharLItem & item) override;
bool addItem(const QStringList & entries) override;
void addItem(const ConfigTableItem & item);
bool removeItem(const QModelIndex & index);
const AbstractCharLItem * getItem(int row) const;
bool removeItem(const QModelIndex & index) override;
const AbstractCharLItem * getItem(int row) const override;
void clearData() override;
void setSelectorModelProducer(SelectorListModel * model);
void setSelectorModelLocations(SelectorListModel * model);
......
......@@ -681,3 +681,13 @@ const AbstractCharLItem * ConventionalTableModel::getItem(int row) const
}
return nullptr;
}
void ConventionalTableModel::clearData()
{
if (m_data.count() > 0)
{
beginRemoveRows(QModelIndex(), 0, m_data.count() - 1);
m_data.clear();
endRemoveRows();
}
}
......@@ -146,17 +146,19 @@ class ConventionalTableModel : public AbstractPlantTableModel
public:
explicit ConventionalTableModel(QObject * parent = nullptr);
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex &index, int role) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override;
virtual QVariant data(const QModelIndex &index, int role) const override;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role) override;
virtual void addItem(const AbstractCharLItem & item);
virtual bool addItem(const QStringList & entries);
virtual void addItem(const AbstractCharLItem & item) override;
virtual bool addItem(const QStringList & entries) override;
virtual void addItem(const ConventionalTableItem & item);
virtual bool removeItem(const QModelIndex &index);
virtual const AbstractCharLItem * getItem(int row) const;
virtual bool removeItem(const QModelIndex &index) override;
virtual const AbstractCharLItem * getItem(int row) const override;
virtual void clearData() override;
private:
QVector<ConventionalTableItem> m_data;
......
......@@ -1024,6 +1024,16 @@ const AbstractCharLItem *DataTableModel::getItem(int row) const
return nullptr;
}
void DataTableModel::clearData()
{
if (m_data.count() > 0)
{
beginRemoveRows(QModelIndex(), 0, m_data.count() - 1);
m_data.clear();
endRemoveRows();
}
}
//////////////////////////////////////////
/// DELEGATE IMPLEMENTATION ///////////////////////////////////////////////////////////////////
//////////////////////////////////////////
......
......@@ -119,20 +119,22 @@ public:
DataTableModel(Preferences * preferences, DataType type = Wind, QObject * parent = nullptr);
// default functions reimplemented as demanden by QAbstractTableModel
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
// own functions
void addItem(const AbstractCharLItem & item);
bool addItem(const QStringList & entries);
void addItem(const AbstractCharLItem & item) override;
bool addItem(const QStringList & entries) override;
void addItem(const DataTableItem & item);
void addItem();
bool removeItem(const QModelIndex &index);
const AbstractCharLItem * getItem(int row) const;
bool removeItem(const QModelIndex &index) override;
const AbstractCharLItem * getItem(int row) const override;
virtual void clearData() override;
private:
QVector<DataTableItem> m_data; // collection of table items
......
......@@ -262,6 +262,17 @@ void GridTableModel::readFromXml(QDomElement element)
static_cast<int>(m_data.size()) - 1));
}
void GridTableModel::clearData()
{
if (m_data.size() > 0)
{
beginRemoveRows(QModelIndex(), 0, m_data.size() - 1);
m_data.clear();
m_names.clear();
endRemoveRows();
}
}
void GridTableModel::onNameChange(QModelIndex index, QString name)
{
if (index.row() < m_names.count())
......
......@@ -51,6 +51,8 @@ public:
void writeToXml(QDomDocument doc, QDomElement element);
void readFromXml(QDomElement element);
virtual void clearData() override;
public slots:
void onNameChange(QModelIndex index, QString name);
void onNewNetwork(const AbstractCharLItem & node);
......
......@@ -627,6 +627,16 @@ LocationsTableItem * LocationsTableModel::getMutableItem(int row)
return nullptr;
}
void LocationsTableModel::clearData()
{
if (m_data.count() > 0)
{
beginRemoveRows(QModelIndex(), 0, m_data.count() - 1);
m_data.clear();
endRemoveRows();
}
}
bool LocationsTableModel::matchLocationsToNodes()
{
qDebug() << endl << "Matching locations to nodes";
......
......@@ -146,6 +146,8 @@ public:
bool removeItem(const QModelIndex &index) override;
virtual const AbstractCharLItem * getItem(int row) const override;
LocationsTableItem * getMutableItem(int row);
virtual void clearData() override;
bool matchLocationsToNodes();
......
......@@ -374,6 +374,16 @@ NodesTableItem * NodesTableModel::getItemNonConst(int row)
return nullptr;
}
void NodesTableModel::clearData()
{
if (m_data.count() > 0)
{
beginRemoveRows(QModelIndex(), 0, m_data.count() - 1);
m_data.clear();
endRemoveRows();
}
}
void NodesTableModel::onLocationChangedNode(int locationId, int oldNodeIndex, int newNodeIndex)
{
if (oldNodeIndex >= 0 && oldNodeIndex < m_data.count())
......
......@@ -95,22 +95,24 @@ public:
NodesTableModel(QObject * parent = nullptr);
// default functions reimplemented as demanden by QAbstractTableModel
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
// own functions --------------------------------------
virtual void addItem(const AbstractCharLItem & item);
virtual bool addItem(const QStringList & entries);
virtual void addItem(const AbstractCharLItem & item) override;
virtual bool addItem(const QStringList & entries) override;
virtual void addItem(const NodesTableItem & item);
void addItem();
bool removeItem(const QModelIndex &index);
virtual const AbstractCharLItem * getItem(int row) const;
bool removeItem(const QModelIndex &index) override;
virtual const AbstractCharLItem * getItem(int row) const override;
virtual NodesTableItem * getItemNonConst(int row);
virtual void clearData() override;
public slots:
void onLocationChangedNode(int locationId,
int oldNodeIndex,
......
......@@ -477,6 +477,19 @@ void PhotovoltaicTableModel::writeToXml(QDomDocument doc, QDomElement element)
}
}
void PhotovoltaicTableModel::clearData()
{
if (m_data.count() > 1)
{
beginRemoveRows(QModelIndex(), 1, m_data.count() - 1);
for (int i = m_data.count(); i > 1; --i)
{
m_data.remove(i);
}
endRemoveRows();
}
}
//////////////////////////////////////////
/// DELEGATE IMPLEMENTATION //////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////
......
......@@ -107,20 +107,22 @@ class PhotovoltaicTableModel : public AbstractCharLTableModel
public:
PhotovoltaicTableModel(QObject * parent = nullptr);
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex &index, int role) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
void addItem(const AbstractCharLItem & item);
bool addItem(const QStringList & entries);
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override;
virtual QVariant data(const QModelIndex &index, int role) const override;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role) override;
void addItem(const AbstractCharLItem & item) override;
bool addItem(const QStringList & entries) override;
void addItem(const PhotovoltaicTableItem & item);
bool removeItem(const QModelIndex &index);
virtual const AbstractCharLItem * getItem(int row) const;
bool removeItem(const QModelIndex &index) override;
virtual const AbstractCharLItem * getItem(int row) const override;
void writeToXml(QDomDocument doc, QDomElement element) override;
virtual void clearData() override;
private:
QVector<PhotovoltaicTableItem> m_data;
};
......
......@@ -362,6 +362,16 @@ const AbstractCharLItem * SolarTableModel::getItem(int row) const
return nullptr;
}
void SolarTableModel::clearData()
{
if (m_data.count() > 0)
{
beginRemoveRows(QModelIndex(), 0, m_data.count() - 1);
m_data.clear();
endRemoveRows();
}
}
//////////////////////////////////////////
/// DELEGATE IMPLEMENTATION //////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////
......
......@@ -81,17 +81,19 @@ public:
SolarTableModel(SelectorListModel * listModel,
QObject * parent = nullptr);
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex &index, int role) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
virtual void addItem(const AbstractCharLItem & item);
virtual bool addItem(const QStringList & entries);
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override;
virtual QVariant data(const QModelIndex &index, int role) const override;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
virtual void addItem(const AbstractCharLItem & item) override;
virtual bool addItem(const QStringList & entries) override;
virtual void addItem(const SolarTableItem & item);
virtual bool removeItem(const QModelIndex &index);
virtual const AbstractCharLItem * getItem(int row) const;
virtual bool removeItem(const QModelIndex &index) override;
virtual const AbstractCharLItem * getItem(int row) const override;
virtual void clearData() override;
private:
QVector<SolarTableItem> m_data;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment