Skip to content

Commit

Permalink
undo some more changes and move init of databaseinterface singleton t…
Browse files Browse the repository at this point in the history
…o inside singleton() (but without creating the actual tablestructure, this remains the prerogative of DataSetPackage)
  • Loading branch information
JorisGoosen committed Jan 15, 2025
1 parent 631bbb5 commit 5560bed
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CommonData/databaseinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,12 @@ std::string DatabaseInterface::dbFile(bool onlyName) const

DatabaseInterface *DatabaseInterface::singleton()
{
if(!_singleton)
{
Log::log() << "No DatabaseInterface::singleton available here yet, creating an interface for internal.sqlite without recreating the dbstructure" << std::endl;
_singleton = new DatabaseInterface(false);
}

return _singleton;
}

Expand Down
6 changes: 0 additions & 6 deletions CommonData/dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,9 +619,3 @@ bool DataSet::initColumnWithStrings(int colIndex, const std::string & newName, c
return anyChanges || column->type() != prevType;
}

bool DataSet::isFilterNameFree(const std::string& filterName)
{
return -1 == db().filterGetId(filterName);
}


1 change: 0 additions & 1 deletion CommonData/dataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class DataSet : public DataSetBaseNode
void setWorkspaceEmptyValues( const stringset& values);
const std::string & description() const { return _description; }
void setDescription( const std::string& desc);
bool isFilterNameFree( const std::string& filterName);

private:
void upgradeTo019(const Json::Value & emptyVals);
Expand Down
5 changes: 5 additions & 0 deletions CommonData/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ bool Filter::checkForUpdates()
return false;
}

bool Filter::filterNameIsFree(const std::string &filterName)
{
return -1 == DatabaseInterface::singleton()->filterGetId(filterName);
}

void Filter::reset()
{
if(!_data->writeBatchedToDB())
Expand Down
7 changes: 5 additions & 2 deletions CommonData/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ class Filter : public DataSetBaseNode
void dbLoad();
bool dbLoadResultAndError(); ///< Loads (updated) filtervalues from database and the (possible) error msg, returns true if an error is set
void dbDelete();
void incRevision() override;
bool checkForUpdates();
void incRevision() override;
bool checkForUpdates();

static bool filterNameIsFree(const std::string & filterName);

void reset();

DatabaseInterface & db();
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions QMLComponents/models/listmodelfiltereddataentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ ListModelFilteredDataEntry::ListModelFilteredDataEntry(TableViewBase * parent)
connect(_tableView, SIGNAL(colNameSignal(QString)), this, SLOT(setColName(QString)) );
connect(_tableView, SIGNAL(extraColSignal(QString)), this, SLOT(setExtraCol(QString)) );

DataSet* dataSet = VariableInfo::info()->dataSet();
static int counter = 0;
do
{
_filterName = "ListModelFilteredDataEntry_" + std::to_string(counter++);
}
while(!dataSet->isFilterNameFree(_filterName));
while(!Filter::filterNameIsFree(_filterName));

connect(VariableInfo::info(), &VariableInfo::dataSetChanged, this, &ListModelFilteredDataEntry::dataSetChangedHandler);
}
Expand Down
3 changes: 0 additions & 3 deletions QMLComponents/variableinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,5 @@ bool VariableInfo::dataAvailable()

DataSet *VariableInfo::dataSet()
{
if(!DatabaseInterface::singleton())
new DatabaseInterface(false);

return _provider ? reinterpret_cast<DataSet*>(_provider->provideInfo(VariableInfo::DataSetPointer).value<void*>()) : nullptr;
}

0 comments on commit 5560bed

Please sign in to comment.