Textractor/include/qtcommon.h

35 lines
1.2 KiB
C
Raw Normal View History

2018-08-22 12:24:55 -04:00
#pragma once
#include <QString>
#include <QVector>
2018-11-01 14:46:37 -04:00
#include <QHash>
#include <QFile>
#include <QFileInfo>
#include <QDir>
2019-06-29 08:46:31 +05:30
#include <QSettings>
#include <QMainWindow>
#include <QDialog>
#include <QLayout>
#include <QFormLayout>
#include <QLabel>
#include <QPushButton>
#include <QCheckBox>
#include <QSpinBox>
#include <QListWidget>
#include <QMessageBox>
#include <QInputDialog>
2019-03-13 11:44:21 -04:00
2019-09-16 17:14:59 -04:00
static thread_local bool ok;
2020-03-05 01:51:36 -07:00
constexpr auto CONFIG_FILE = u8"Textractor.ini";
constexpr auto WINDOW = u8"Window";
inline QSettings openSettings(QObject* parent = nullptr) { return { CONFIG_FILE, QSettings::IniFormat, parent }; }
2019-03-13 11:44:21 -04:00
struct QTextFile : QFile { QTextFile(QString name, QIODevice::OpenMode mode) : QFile(name) { open(mode | QIODevice::Text); } };
inline std::wstring S(const QString& s) { return { s.toStdWString() }; }
inline QString S(const std::string& s) { return QString::fromStdString(s); }
inline QString S(const std::wstring& s) { return QString::fromStdWString(s); }
// TODO: allow paired surrogates
inline void sanitize(QString& s) { s.chop(std::distance(std::remove_if(s.begin(), s.end(), [](QChar ch) { return ch.isSurrogate(); }), s.end())); }
2020-09-09 14:54:15 -06:00
inline QString sanitize(QString&& s) { sanitize(s); return std::move(s); }