From 3189ca5efc5826405bf2e9c7d9949ad5ea9a8a10 Mon Sep 17 00:00:00 2001 From: Treeki Date: Wed, 12 Sep 2012 14:57:44 +0200 Subject: initial un-exporter version --- lsseteditor.h | 160 ---------------------------------------------------------- 1 file changed, 160 deletions(-) delete mode 100644 lsseteditor.h (limited to 'lsseteditor.h') diff --git a/lsseteditor.h b/lsseteditor.h deleted file mode 100644 index 0b09ca6..0000000 --- a/lsseteditor.h +++ /dev/null @@ -1,160 +0,0 @@ -#ifndef LSSETEDITOR_H -#define LSSETEDITOR_H - -#include -#include -#include - -class _LSSetEntryEditorBaseBase : public QWidget { - Q_OBJECT -protected: - explicit _LSSetEntryEditorBaseBase(QWidget *parent = 0) : - QWidget(parent) { } - -signals: - void dataEdited(); -}; - -// class prototype -template -class LSSetEditor; - -template -class LSSetEntryEditorBase : public _LSSetEntryEditorBaseBase { -protected: - explicit LSSetEntryEditorBase(QWidget *parent = 0) : - _LSSetEntryEditorBaseBase(parent) { } - -public: - void setCurrentEntry(TData &entry) { - m_currentEntry = &entry; - loadEntryFrom(entry); - } - -private: - TData *m_currentEntry; - -protected: - virtual void loadEntryFrom(const TData &entry) = 0; - TData *currentEntry() const { return m_currentEntry; } -}; - - - - -class _LSSetEditorBase : public QWidget { - Q_OBJECT -public: - explicit _LSSetEditorBase(int maxEntries, QWidget *parent = 0); - -protected: - int m_maxEntries; - QSpinBox *m_entryCount; - QComboBox *m_chooser; - - QWidget *m_setEditorWidget; - - int m_loadingThings; - - void setup(QWidget *eWidget); - - virtual void changeEntryCountTo(int count) = 0; - virtual void showEntry(int index) = 0; - virtual void resizeDataListTo(int count) = 0; - -private slots: - void handleEntryCountChanged(int count); - void handleEntrySelected(int index); - -signals: - void dataEdited(); - -}; - -template -class LSSetEditor : public _LSSetEditorBase { -public: - explicit LSSetEditor(int maxEntries, QWidget *parent = 0) : - _LSSetEditorBase(maxEntries, parent) { - - TWidget *w = new TWidget(this); - setup(w); - - m_setEditorWidget = w; - m_typedSetEditorWidget = w; - - LSSetEntryEditorBase *checkMe = w; - connect(checkMe, SIGNAL(dataEdited()), SIGNAL(dataEdited())); - } - - void setData(QList *newData) { - m_loadingThings++; - - m_data = newData; - m_entryCount->setValue(newData->count()); - changeEntryCountTo(newData->count()); - - m_chooser->setCurrentIndex(newData->count() ? 0 : -1); - showEntry(newData->count() ? 0 : -1); - - m_loadingThings--; - } - -protected: - QList *m_data; - TWidget *m_typedSetEditorWidget; - - void changeEntryCountTo(int count) { - m_loadingThings++; - - int existingCount = m_chooser->count(); - - if (existingCount > count) { - // remove something - int nowSelected = m_chooser->currentIndex(); - - if (nowSelected >= count) { - // oops, we'll need to select something else - showEntry(count - 1); - m_chooser->setCurrentIndex(count - 1); - } - - for (int i = (existingCount - 1); i >= count; i--) - m_chooser->removeItem(i); - - } else if (count > existingCount) { - // add something - - for (int i = existingCount; i < count; i++) - m_chooser->addItem(QString("Set %1").arg(i + 1)); - } - - m_loadingThings--; - } - - void resizeDataListTo(int count) { - m_data->reserve(count); - - while (m_data->count() < count) - m_data->append(TData()); - while (m_data->count() > count) - m_data->removeLast(); - } - - void showEntry(int index) { - m_loadingThings++; - - if (index == -1) { - m_setEditorWidget->setEnabled(false); - } else { - m_setEditorWidget->setEnabled(true); - TData &entry = (*m_data)[index]; - m_typedSetEditorWidget->setCurrentEntry(entry); - } - } -}; - - - - -#endif // LSSETEDITOR_H -- cgit v1.2.3