This repository has been archived by the owner on Jun 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marek A. Ruszczyński
committed
Dec 3, 2008
1 parent
1a3524f
commit 8224ac4
Showing
34 changed files
with
2,748 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# ------------------------------------------------- | ||
# Project created by QtCreator 2008-11-07T13:37:18 | ||
# ------------------------------------------------- | ||
CONFIG -= debug | ||
CONFIG += release | ||
TARGET = ModX | ||
TEMPLATE = app | ||
SOURCES += main.cpp \ | ||
mainwindow.cpp \ | ||
modxapp.cpp \ | ||
modxreader.cpp \ | ||
pages/generalpage.cpp \ | ||
modxdata.cpp \ | ||
pages/changelogpage.cpp \ | ||
pages/authorgrouppage.cpp \ | ||
modxwriter.cpp \ | ||
pages/sqlpage.cpp \ | ||
pages/filepage.cpp \ | ||
pages/diypage.cpp | ||
HEADERS += mainwindow.h \ | ||
modxapp.h \ | ||
modxreader.h \ | ||
pages/generalpage.h \ | ||
modxdata.h \ | ||
pages/page.h \ | ||
pages/changelogpage.h \ | ||
pages/authorgrouppage.h \ | ||
modxwriter.h \ | ||
pages/sqlpage.h \ | ||
pages/filepage.h \ | ||
pages/diypage.h \ | ||
listmodel.h | ||
FORMS += mainwindow.ui \ | ||
pages/generalpage.ui \ | ||
pages/changelogpage.ui \ | ||
pages/authorgrouppage.ui \ | ||
pages/sqlpage.ui \ | ||
pages/filepage.ui \ | ||
pages/diypage.ui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include "listmodel.h" | ||
|
||
ListModel::ListModel() | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#ifndef LISTMODEL_H | ||
#define LISTMODEL_H | ||
|
||
#include <QAbstractListModel> | ||
#include <QItemSelectionModel> | ||
|
||
#include <QDebug> | ||
|
||
template<typename T> class ListModel : public QAbstractListModel | ||
{ | ||
public: | ||
ListModel(QObject *parent = 0) : QAbstractListModel(parent) {} | ||
|
||
QList<T> list() const | ||
{ | ||
return m_data; | ||
} | ||
|
||
void setList(QList<T> data) | ||
{ | ||
m_data = data; | ||
reset(); | ||
} | ||
|
||
int rowCount(const QModelIndex &parent = QModelIndex()) const | ||
{ | ||
if (parent != QModelIndex()) | ||
{ | ||
return 0; | ||
} | ||
|
||
return m_data.count(); | ||
} | ||
|
||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const | ||
{ | ||
if (index.row() < 0 || index.row() > rowCount() - 1) | ||
return QVariant(); | ||
|
||
if (role == Qt::DisplayRole) | ||
{ | ||
return QVariant(QString(m_data.at(index.row()))); | ||
} | ||
else if (role == Qt::EditRole) | ||
{ | ||
return QVariant::fromValue(m_data.at(index.row())); | ||
} | ||
else | ||
{ | ||
return QVariant(); | ||
} | ||
} | ||
|
||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) | ||
{ | ||
if (role != Qt::EditRole) | ||
return false; | ||
|
||
m_data[index.row()] = value.value<T>(); | ||
emit dataChanged(index, index); | ||
return true; | ||
} | ||
|
||
bool insertRows(int row, int count, const QModelIndex &parent) | ||
{ | ||
if (parent != QModelIndex()) | ||
return false; | ||
|
||
beginInsertRows(parent, row, row + count); | ||
for (int i = 0; i < count; ++i) | ||
{ | ||
m_data.insert(row, T()); | ||
} | ||
endInsertRows(); | ||
return true; | ||
} | ||
|
||
bool removeRows(int row, int count, const QModelIndex &parent) | ||
{ | ||
if (parent != QModelIndex()) | ||
return false; | ||
|
||
beginRemoveRows(parent, row, row + count); | ||
for (int i = 0; i < count; ++i) | ||
{ | ||
m_data.removeAt(row); | ||
} | ||
endRemoveRows(); | ||
|
||
return true; | ||
} | ||
|
||
int moveUp(int row) | ||
{ | ||
if (!row || m_data.isEmpty()) | ||
return row; | ||
|
||
m_data.swap(row, row - 1); | ||
emit dataChanged(createIndex(row - 1, 0), createIndex(row, 0)); | ||
return row - 1; | ||
} | ||
|
||
int moveDown(int row) | ||
{ | ||
if (m_data.isEmpty() || row == rowCount() - 1) | ||
return row; | ||
|
||
m_data.swap(row, row + 1); | ||
emit dataChanged(createIndex(row, 0), createIndex(row + 1, 0)); | ||
return row + 1; | ||
} | ||
|
||
private: | ||
QList<T> m_data; | ||
}; | ||
|
||
#endif // LISTMODEL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include "modxapp.h" | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QCoreApplication::setApplicationVersion("0.5.0"); | ||
ModXApp app(argc, argv); | ||
return app.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
#include "mainwindow.h" | ||
|
||
#include "modxapp.h" | ||
#include "modxreader.h" | ||
#include "modxwriter.h" | ||
#include "modxdata.h" | ||
#include "pages/generalpage.h" | ||
#include "pages/authorgrouppage.h" | ||
#include "pages/changelogpage.h" | ||
#include "pages/sqlpage.h" | ||
#include "pages/filepage.h" | ||
#include "pages/diypage.h" | ||
|
||
|
||
#include <QFileDialog> | ||
#include <QDesktopServices> | ||
#include <QListWidgetItem> | ||
|
||
#include <QDebug> | ||
|
||
MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags) | ||
: QMainWindow(parent, flags) | ||
{ | ||
ui.setupUi(this); | ||
|
||
setCurrentFile("Untitled"); | ||
|
||
connect(ui.actionNew, SIGNAL(triggered()), this, SLOT(newFile())); | ||
connect(ui.actionOpen, SIGNAL(triggered()), this, SLOT(loadFile())); | ||
connect(ui.actionSave, SIGNAL(triggered()), this, SLOT(saveFile())); | ||
connect(ui.actionSaveAs,SIGNAL(triggered()), this, SLOT(saveFileAs())); | ||
connect(ui.actionQuit, SIGNAL(triggered()), qApp, SLOT(quit())); | ||
|
||
connect(ui.pageList, SIGNAL(currentRowChanged(int)), this, SLOT(changePage(int))); | ||
|
||
ui.stackedWidget->removeWidget(ui.stackedWidget->currentWidget()); | ||
addPage(tr("General Info"), new GeneralPage(ui.stackedWidget)); | ||
addPage(tr("Authors"), new AuthorGroupPage(ui.stackedWidget)); | ||
addPage(tr("Changelog"), new ChangelogPage(ui.stackedWidget)); | ||
addPage(tr("SQL"), new SqlPage(ui.stackedWidget)); | ||
addPage(tr("Files"), new FilePage(ui.stackedWidget)); | ||
addPage(tr("Do-It-Yourself"), new DIYPage(ui.stackedWidget)); | ||
|
||
ui.pageList->setCurrentRow(0); | ||
} | ||
|
||
MainWindow::~MainWindow() | ||
{ | ||
|
||
} | ||
|
||
void MainWindow::newFile() | ||
{ | ||
ModXData data; | ||
setData(&data); | ||
} | ||
|
||
void MainWindow::loadFile() | ||
{ | ||
QString fileName = QFileDialog::getOpenFileName( | ||
this, | ||
tr("Open ModX file..."), | ||
QDesktopServices::storageLocation(QDesktopServices::HomeLocation), | ||
"ModX files (*.xml *.modx)"); | ||
|
||
if (fileName == "") | ||
return; | ||
|
||
setCurrentFile(fileName); | ||
|
||
ModXReader reader; | ||
QFile file(fileName); | ||
file.open(QIODevice::ReadOnly); | ||
|
||
if(!reader.read(&file)) | ||
{ | ||
qDebug() << "FAIL!!"; | ||
return; | ||
} | ||
qDebug() << "SUCESS!!"; | ||
|
||
ModXData *data = reader.data(); | ||
|
||
|
||
setData(data); | ||
|
||
delete data; | ||
} | ||
|
||
void MainWindow::saveFile() | ||
{ | ||
if (ModXApp::currentFile == "Untitled") | ||
{ | ||
saveFileAs(); | ||
return; | ||
} | ||
|
||
ModXData data; | ||
|
||
for (int i = 0; i < ui.stackedWidget->count(); ++i) | ||
{ | ||
qobject_cast<Page *>(ui.stackedWidget->widget(i))->getData(&data); | ||
} | ||
|
||
QFile file(ModXApp::currentFile); | ||
file.open(QIODevice::WriteOnly); | ||
|
||
ModXWriter writer; | ||
writer.setData(&data); | ||
|
||
writer.write(&file); | ||
} | ||
|
||
|
||
void MainWindow::saveFileAs() | ||
{ | ||
QString fileName = QFileDialog::getSaveFileName( | ||
this, | ||
tr("Save file as..."), | ||
QDesktopServices::storageLocation(QDesktopServices::HomeLocation), | ||
"ModX files (*.xml *.modx)"); | ||
|
||
if (fileName == "") | ||
return; | ||
|
||
setCurrentFile(fileName); | ||
saveFile(); | ||
} | ||
|
||
|
||
void MainWindow::changePage(int i) | ||
{ | ||
ui.stackedWidget->setCurrentIndex(i); | ||
} | ||
|
||
void MainWindow::addPage(const QString &title, Page *page) | ||
{ | ||
page->show(); | ||
ui.pageList->addItem(title); | ||
ui.stackedWidget->addWidget(page); | ||
} | ||
|
||
void MainWindow::setData(const ModXData *data) | ||
{ | ||
for (int i = 0; i < ui.stackedWidget->count(); ++i) | ||
{ | ||
qobject_cast<Page *>(ui.stackedWidget->widget(i))->setData(data); | ||
} | ||
} | ||
|
||
void MainWindow::setCurrentFile(const QString &file) | ||
{ | ||
ModXApp::currentFile = file; | ||
setWindowTitle(tr("ModX Editor - %1 [*]").arg(file)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#ifndef MAINWINDOW_H | ||
#define MAINWINDOW_H | ||
|
||
#include <QtGui/QMainWindow> | ||
#include "ui_mainwindow.h" | ||
|
||
class Page; | ||
class ModXData; | ||
|
||
class MainWindow : public QMainWindow | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
MainWindow(QWidget *parent = 0, Qt::WFlags flags = 0); | ||
~MainWindow(); | ||
|
||
public slots: | ||
void newFile(); | ||
void loadFile(); | ||
void saveFile(); | ||
void saveFileAs(); | ||
|
||
void changePage(int i); | ||
|
||
private: | ||
void addPage(const QString &title, Page *page); | ||
void setData(const ModXData *data); | ||
|
||
void setCurrentFile(const QString &file); | ||
|
||
QString currentFile; | ||
|
||
Ui::MainWindowClass ui; | ||
}; | ||
|
||
#endif // MAINWINDOW_H |
Oops, something went wrong.