65 #ifndef RECENTFILES_HH
66 #define RECENTFILES_HH
69 #include <QStringList>
72 #include <QFileDialog>
88 void addRecentFile(QString _file,
DataType _type);
97 void rememberRecentItem(
const QString &propName,
const QString &itemName,
const int RECENT_ITEMS_MAX_SIZE = 10);
103 QStringList getRecentItems(
const QString &propName);
110 QString getMostRecentItem(
const QString &propName);
119 inline static void updateComboBox(QComboBox *cb,
const QString &value,
const char *propName) {
122 if (value.length() > 0)
123 rememberRecentItem(QString::fromUtf8(propName), value);
124 const QStringList content = getRecentItems(QString::fromUtf8(propName));
125 cb->insertItems(0, content);
127 cb->setEditText(value);
144 inline static QString obtainPathName(QComboBox *cb,
const char *title,
const char *filters,
145 const char *propName, DialogType dialog_type = DT_OPEN) {
147 switch (dialog_type) {
149 result = QFileDialog::getOpenFileName(0, QObject::tr(title), cb->currentText(), QObject::tr(filters));
152 result = QFileDialog::getSaveFileName(0, QObject::tr(title), cb->currentText(), QObject::tr(filters));
155 result = QFileDialog::getExistingDirectory(0, QObject::tr(title), cb->currentText());
158 throw std::logic_error(
"Unknown value for dialog_type.");
161 if (result.length() > 0)
162 updateComboBox(cb, result, propName);
173 #endif // OPTIONS_HH defined