mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-12-26 02:20:54 +00:00
Changed: #1307 Added option for SaveAs and a windows list
This commit is contained in:
parent
99647c12aa
commit
c3af517233
2 changed files with 180 additions and 12 deletions
|
@ -37,6 +37,10 @@
|
||||||
#include <QtGui/QGridLayout>
|
#include <QtGui/QGridLayout>
|
||||||
#include <QtGui/QMdiSubWindow>
|
#include <QtGui/QMdiSubWindow>
|
||||||
#include <QtGui/QFileDialog>
|
#include <QtGui/QFileDialog>
|
||||||
|
#include <QtCore/QResource>
|
||||||
|
#include <QtGui/QMenuBar>
|
||||||
|
#include <QtCore/QFileInfo>
|
||||||
|
|
||||||
|
|
||||||
struct TEntryInfo
|
struct TEntryInfo
|
||||||
{
|
{
|
||||||
|
@ -54,7 +58,8 @@ CMainWindow::CMainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
{
|
{
|
||||||
_ui.setupUi(this);
|
_ui.setupUi(this);
|
||||||
|
_ui.mdiArea->closeAllSubWindows();
|
||||||
|
connect(_ui.mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)),this, SLOT(activeSubWindowChanged()));
|
||||||
|
|
||||||
readSettings();
|
readSettings();
|
||||||
createToolbar();
|
createToolbar();
|
||||||
|
@ -73,18 +78,54 @@ void CMainWindow::createToolbar()
|
||||||
|
|
||||||
|
|
||||||
// File menu
|
// File menu
|
||||||
//QAction *action = menuManager->action(Core::Constants::NEW);
|
openAct = new QAction(QIcon(Core::Constants::ICON_OPEN), "&Open...", this);
|
||||||
//_ui.toolBar->addAction(action);
|
|
||||||
openAct = menuManager->action(Core::Constants::OPEN);
|
|
||||||
_ui.toolBar->addAction(openAct);
|
_ui.toolBar->addAction(openAct);
|
||||||
connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
|
connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
|
||||||
|
|
||||||
saveAct = menuManager->action(Core::Constants::SAVE);
|
saveAct = new QAction(QIcon(Core::Constants::ICON_SAVE), "&Save...", this);
|
||||||
_ui.toolBar->addAction(saveAct);
|
_ui.toolBar->addAction(saveAct);
|
||||||
connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
|
connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
|
||||||
//action = menuManager->action(Core::Constants::SAVE_AS);
|
|
||||||
//_ui.toolBar->addAction(action);
|
|
||||||
|
|
||||||
|
saveAsAct = new QAction(QIcon(Core::Constants::ICON_SAVE_AS), "&Save as...", this);
|
||||||
|
_ui.toolBar->addAction(saveAsAct);
|
||||||
|
connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
|
||||||
|
|
||||||
|
// Windows menu
|
||||||
|
windowMapper = new QSignalMapper(this);
|
||||||
|
connect(windowMapper, SIGNAL(mapped(QWidget*)), this, SLOT(setActiveSubWindow(QWidget*)));
|
||||||
|
windowMenu = new QMenu(tr("&Windows..."), _ui.toolBar);
|
||||||
|
windowMenu->setIcon(QIcon(Core::Constants::ICON_PILL));
|
||||||
|
_ui.toolBar->addAction(windowMenu->menuAction());
|
||||||
|
connect(windowMenu, SIGNAL(aboutToShow()), this, SLOT(updateWindowsList()));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMainWindow::activeSubWindowChanged()
|
||||||
|
{
|
||||||
|
updateWindowsList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMainWindow::updateWindowsList()
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
windowMenu->clear();
|
||||||
|
QList<QMdiSubWindow *> windows = _ui.mdiArea->subWindowList();
|
||||||
|
for (QList<QMdiSubWindow*>::iterator it = windows.begin(); it != windows.end(); ++it) {
|
||||||
|
QString window_file = QFileInfo((*it)->widget()->windowFilePath()).fileName();
|
||||||
|
QString action_text;
|
||||||
|
if (i < 9) {
|
||||||
|
action_text = tr("&%1 %2").arg(i + 1).arg(window_file);
|
||||||
|
} else {
|
||||||
|
action_text = tr("%1 %2").arg(i + 1).arg(window_file);
|
||||||
|
}
|
||||||
|
QAction *action = windowMenu->addAction(action_text);
|
||||||
|
action->setCheckable(true);
|
||||||
|
action->setChecked((*it) == _ui.mdiArea->activeSubWindow());
|
||||||
|
connect(action, SIGNAL(triggered()), windowMapper, SLOT(map()));
|
||||||
|
windowMapper->setMapping(action, windows.at(i));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMainWindow::open()
|
void CMainWindow::open()
|
||||||
|
@ -127,23 +168,126 @@ void CMainWindow::open()
|
||||||
wk_table->resizeRowsToContents();
|
wk_table->resizeRowsToContents();
|
||||||
wk_table->showMaximized();
|
wk_table->showMaximized();
|
||||||
sub_window->activateWindow();
|
sub_window->activateWindow();
|
||||||
//_ui.mdiArea->addSubWindow(sub_window);
|
|
||||||
// set editor signals
|
// set editor signals
|
||||||
connect(wk_table, SIGNAL(cellChanged(int,int) ), this, SLOT(sheetEditorChanged(int,int)));
|
connect(wk_table, SIGNAL(cellChanged(int,int) ), this, SLOT(sheetEditorChanged(int,int)));
|
||||||
|
// windows menu
|
||||||
|
updateWindowsList();
|
||||||
|
} else {
|
||||||
|
QErrorMessage error_settings;
|
||||||
|
error_settings.showMessage("This file is not a worksheet file.");
|
||||||
|
error_settings.exec();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMainWindow::sheetEditorChanged(int, int)
|
void CMainWindow::sheetEditorChanged(int row, int column)
|
||||||
{
|
{
|
||||||
saveAct->setEnabled(true);
|
saveAct->setEnabled(true);
|
||||||
|
QMdiSubWindow *current_window = _ui.mdiArea->currentSubWindow();
|
||||||
|
if(modifiedCells.find(current_window) != modifiedCells.end()) // founded
|
||||||
|
{
|
||||||
|
list<CCelPos> cells = modifiedCells[current_window];
|
||||||
|
bool overwriteResult = false;
|
||||||
|
for(list<CCelPos>::iterator it = cells.begin(); it != cells.end(); ++it)
|
||||||
|
{
|
||||||
|
if((*it).row == row && (*it).col == column )
|
||||||
|
overwriteResult = true;
|
||||||
|
}
|
||||||
|
if(overwriteResult == false)
|
||||||
|
{
|
||||||
|
CCelPos v;
|
||||||
|
v.row = row;
|
||||||
|
v.col = column;
|
||||||
|
cells.push_back(v);
|
||||||
|
}
|
||||||
|
} else { // not found
|
||||||
|
list<CCelPos> cells;
|
||||||
|
CCelPos v;
|
||||||
|
v.row = row;
|
||||||
|
v.col = column;
|
||||||
|
cells.push_back(v);
|
||||||
|
modifiedCells[current_window] = cells;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMainWindow::save()
|
void CMainWindow::save()
|
||||||
{
|
{
|
||||||
QMdiSubWindow *current_window = _ui.mdiArea->currentSubWindow();
|
QMdiSubWindow *current_window = _ui.mdiArea->currentSubWindow();
|
||||||
|
|
||||||
|
if(QString(current_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor
|
||||||
|
{
|
||||||
|
QWidget *subwindow_widget = current_window->widget();
|
||||||
|
QTableWidget *table_editor = qobject_cast<QTableWidget*>(subwindow_widget);
|
||||||
|
QString file_path = table_editor->windowFilePath();
|
||||||
|
|
||||||
|
if(modifiedCells.find(current_window) != modifiedCells.end())
|
||||||
|
{
|
||||||
|
STRING_MANAGER::TWorksheet wk_file;
|
||||||
|
loadExcelSheet(file_path.toStdString(), wk_file, true);
|
||||||
|
list<CCelPos> cells = modifiedCells[current_window];
|
||||||
|
for(list<CCelPos>::iterator it = cells.begin(); it != cells.end(); ++it)
|
||||||
|
{
|
||||||
|
QTableWidgetItem* edited_item = table_editor->item((*it).row, (*it).col);
|
||||||
|
wk_file.setData((*it).row + 1, (*it).col, ucstring(edited_item->text().toStdString()));
|
||||||
|
cells.erase(it);
|
||||||
|
}
|
||||||
|
ucstring s = prepareExcelSheet(wk_file);
|
||||||
|
NLMISC::CI18N::writeTextFile(file_path.toStdString(), s, false);
|
||||||
|
if(cells.size() == 0)
|
||||||
|
modifiedCells.erase(current_window);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMainWindow::saveAs()
|
||||||
|
{
|
||||||
|
QString file_name;
|
||||||
|
if (_ui.mdiArea->isActiveWindow())
|
||||||
|
{
|
||||||
|
file_name = QFileDialog::getSaveFileName(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file_name.isEmpty())
|
||||||
|
{
|
||||||
|
QMdiSubWindow *current_window = _ui.mdiArea->currentSubWindow();
|
||||||
|
|
||||||
|
if(QString(current_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor
|
||||||
|
{
|
||||||
|
QWidget *subwindow_widget = current_window->widget();
|
||||||
|
QTableWidget *table_editor = qobject_cast<QTableWidget*>(subwindow_widget);
|
||||||
|
QString orig_file_path = table_editor->windowFilePath();
|
||||||
|
STRING_MANAGER::TWorksheet new_file, wk_file;
|
||||||
|
loadExcelSheet(orig_file_path.toStdString(), wk_file, true);
|
||||||
|
// set columns
|
||||||
|
new_file.resize(new_file.size() + 1);
|
||||||
|
for(unsigned int i = 0; i < wk_file.ColCount; i++)
|
||||||
|
{
|
||||||
|
ucstring col_name = wk_file.getData(0, i);
|
||||||
|
new_file.insertColumn(new_file.ColCount);
|
||||||
|
new_file.setData(0, new_file.ColCount - 1, col_name);
|
||||||
|
}
|
||||||
|
// read all the rows from table
|
||||||
|
uint rowIdx;
|
||||||
|
for(int i = 0; i < table_editor->rowCount(); i++)
|
||||||
|
{
|
||||||
|
rowIdx = new_file.size();
|
||||||
|
new_file.resize(new_file.size() + 1);
|
||||||
|
for(int j = 0; j < table_editor->columnCount(); j++)
|
||||||
|
{
|
||||||
|
QTableWidgetItem* item = table_editor->item(i, j);
|
||||||
|
new_file.setData(rowIdx, j, ucstring(item->text().toStdString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ucstring s = prepareExcelSheet(new_file);
|
||||||
|
NLMISC::CI18N::writeTextFile(file_name.toStdString(), s, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QErrorMessage error_settings;
|
||||||
|
error_settings.showMessage( file_name);
|
||||||
|
error_settings.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMainWindow::readSettings()
|
void CMainWindow::readSettings()
|
||||||
|
@ -213,6 +357,13 @@ bool CMainWindow::verifySettings()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMainWindow::setActiveSubWindow(QWidget *window)
|
||||||
|
{
|
||||||
|
if (!window)
|
||||||
|
return;
|
||||||
|
_ui.mdiArea->setActiveSubWindow(qobject_cast<QMdiSubWindow *>(window));
|
||||||
|
}
|
||||||
|
|
||||||
list<string> CMainWindow::convertQStringList(QStringList listq)
|
list<string> CMainWindow::convertQStringList(QStringList listq)
|
||||||
{
|
{
|
||||||
std::list<std::string> stdlist;
|
std::list<std::string> stdlist;
|
||||||
|
|
|
@ -36,6 +36,8 @@
|
||||||
#include <QtGui/QTabWidget>
|
#include <QtGui/QTabWidget>
|
||||||
#include <QtGui/QMenu>
|
#include <QtGui/QMenu>
|
||||||
#include <QtGui/QMdiSubWindow>
|
#include <QtGui/QMdiSubWindow>
|
||||||
|
#include <QtCore/QSignalMapper>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "ui_translation_manager_main_window.h"
|
#include "ui_translation_manager_main_window.h"
|
||||||
|
@ -48,6 +50,12 @@ using namespace std;
|
||||||
namespace Plugin
|
namespace Plugin
|
||||||
{
|
{
|
||||||
|
|
||||||
|
struct CCelPos
|
||||||
|
{
|
||||||
|
int col;
|
||||||
|
int row;
|
||||||
|
};
|
||||||
|
|
||||||
class CMainWindow : public QMainWindow
|
class CMainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -57,9 +65,14 @@ public:
|
||||||
QUndoStack *m_undoStack;
|
QUndoStack *m_undoStack;
|
||||||
private:
|
private:
|
||||||
Ui::CMainWindow _ui;
|
Ui::CMainWindow _ui;
|
||||||
|
|
||||||
|
map<QMdiSubWindow*, list<CCelPos> > modifiedCells;
|
||||||
// actions
|
// actions
|
||||||
QAction *openAct;
|
QAction *openAct;
|
||||||
QAction *saveAct;
|
QAction *saveAct;
|
||||||
|
QAction *saveAsAct;
|
||||||
|
QMenu *windowMenu;
|
||||||
|
QSignalMapper *windowMapper;
|
||||||
// config
|
// config
|
||||||
map<string, list<string> > config_paths;
|
map<string, list<string> > config_paths;
|
||||||
list<string> languages;
|
list<string> languages;
|
||||||
|
@ -70,13 +83,17 @@ private Q_SLOTS:
|
||||||
void extractBotNames();
|
void extractBotNames();
|
||||||
void open();
|
void open();
|
||||||
void save();
|
void save();
|
||||||
|
void saveAs();
|
||||||
void sheetEditorChanged(int, int);
|
void sheetEditorChanged(int, int);
|
||||||
|
void setActiveSubWindow(QWidget *window);
|
||||||
|
void activeSubWindowChanged();
|
||||||
private:
|
private:
|
||||||
void compareBotNames();
|
void compareBotNames();
|
||||||
bool verifySettings();
|
bool verifySettings();
|
||||||
void readSettings();
|
void readSettings();
|
||||||
void createMenus();
|
void createMenus();
|
||||||
void createToolbar();
|
void createToolbar();
|
||||||
|
void updateWindowsList();
|
||||||
list<string> convertQStringList(QStringList listq);
|
list<string> convertQStringList(QStringList listq);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue