Skip to content

Commit

Permalink
Fixed file creation bug, stale filter bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Bowman committed May 25, 2010
1 parent 8478294 commit 500aef0
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2010-05-25 JMB Fixed file creation bug, stale filter bug

Fixed a rather serious bug introduced by the support for read-only files,
which prevented any new files from being created. Also fixed a bug where
the current filter might contain stale data after major format changes.

2010-05-24 JMB Chinese & Czech updates, Debian/Maemo description updates

Added the updated Chinese and Czech UI translations, and the Chinese help
Expand Down
29 changes: 24 additions & 5 deletions database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ Database::Database(const QString &path, OpenResult *result, bool encrypt)
updatePreferences();

QFileInfo info(path);
if (info.exists() && !info.isReadable()) {
*result = Failure;
return;
bool canWrite = true;
if (info.exists()) {
if (!info.isReadable()) {
*result = Failure;
return;
}
canWrite = info.isWritable();
}
bool canWrite = info.isWritable();
#if defined(Q_WS_WIN)
file = new c4_Storage(path.toUtf8(), canWrite);
#else
Expand Down Expand Up @@ -813,6 +816,11 @@ void Database::deleteColumn(const QString &name)
deleteCalc(cId (columns[index]));
// remove the column from the definition
columns.RemoveAt(index);
// clear the current filter cache, it may need to be reloaded
if (curFilter) {
delete curFilter;
curFilter = 0;
}
}

/**
Expand Down Expand Up @@ -853,6 +861,11 @@ void Database::renameColumn(const QString &oldName, const QString &newName)
// rename the column in the format definition
int index = columns.Find(cName [utf8OldName]);
cName (columns[index]) = utf8NewName;
// clear the current filter cache, it may need to be reloaded
if (curFilter) {
delete curFilter;
curFilter = 0;
}
}

/**
Expand Down Expand Up @@ -1205,7 +1218,8 @@ QStringList Database::listFilters()

/**
* Get the definition of the named filter. Also sets the retrieved filter to
* be the one currently in use.
* be the one currently in use. The loaded filter is cached internally and
* deleted when appropriate, so it shouldn't be cached elsewhere.
*
* @param name The name of the filter to get
* @return The filter's definition
Expand Down Expand Up @@ -2009,6 +2023,11 @@ void Database::replaceEnumOption(int enumId, const QString &oldOption,
+ fcConstant [utf8OldOption]);
}
}
// clear the current filter cache, it may need to be reloaded
if (curFilter) {
delete curFilter;
curFilter = 0;
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion datamodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ Database *DataModel::database()
}

/**
* Set the database from which data is to be shown.
* Set the database from which data is to be shown. Called when a file is
* created, opened, or significantly altered.
*
* @param dbase The database now in use.
*/
Expand Down
11 changes: 9 additions & 2 deletions enummanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@
#include "enumeditor.h"
#include "enummanager.h"
#include "factory.h"
#include "viewdisplay.h"

/**
* Constructor.
*
* @param dbase The database to be edited
* @param parent This dialog's parent widget
* @param viewDisplay The main data display widget
*/
EnumManager::EnumManager(Database *dbase, QWidget *parent)
: PBDialog(tr("Enum Manager"), parent), contentChanged(false), orderChanged(false)
EnumManager::EnumManager(Database *dbase, QWidget *parent, ViewDisplay *viewDisplay)
: PBDialog(tr("Enum Manager"), parent), viewer(viewDisplay),
contentChanged(false), orderChanged(false)
{
stack = new QStackedWidget(this);
vbox->addWidget(stack, 1);
Expand Down Expand Up @@ -90,7 +93,9 @@ void EnumManager::editEnum()
QString enumName = item->text();
EnumEditor enumEditor(this);
if (enumEditor.edit(db, enumName)) {
viewer->closeView();
enumEditor.applyChanges();
viewer->setDatabase(db);
item->setText(enumEditor.getName());
contentChanged = true;
}
Expand Down Expand Up @@ -121,7 +126,9 @@ void EnumManager::deleteEnum()
return;
}
}
viewer->closeView();
db->deleteEnum(enumName);
viewer->setDatabase(db);
delete item;
if (listWidget->count() == 0) {
stack->setCurrentWidget(noEnums);
Expand Down
4 changes: 3 additions & 1 deletion enummanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Database;
class QLabel;
class QListWidget;
class QStackedWidget;
class ViewDisplay;

/**
* Dialog for managing a database's enumeration column types.
Expand All @@ -30,7 +31,7 @@ class EnumManager: public PBDialog
{
Q_OBJECT
public:
EnumManager(Database *dbase, QWidget *parent = 0);
EnumManager(Database *dbase, QWidget *parent, ViewDisplay *viewDisplay);

void applyChanges();
bool changesMade();
Expand All @@ -43,6 +44,7 @@ private slots:
void moveDown();

private:
ViewDisplay *viewer; /**< The main data display widget */
QStackedWidget *stack; /**< Main widget stack (enum list and "no enums" label) */
QListWidget *listWidget; /**< Display list of all defined enumerations */
QLabel *noEnums; /**< "No enums" placeholder label */
Expand Down
7 changes: 1 addition & 6 deletions portabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,18 +445,13 @@ bool PortaBase::editColumns()
*/
void PortaBase::editEnums()
{
EnumManager manager(db, this);
viewer->closeView();
EnumManager manager(db, this, viewer);
if (manager.exec()) {
manager.applyChanges();
}
if (manager.changesMade()) {
viewer->setDatabase(db);
setEdited(true);
}
else {
viewer->setView(db->currentView());
}
}

/**
Expand Down

0 comments on commit 500aef0

Please sign in to comment.