Skip to content

Commit

Permalink
Finishing preamble editation in UI which fixed dvorka#143.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvorka committed Mar 2, 2018
1 parent 5c061df commit 4d3ac33
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 16 deletions.
7 changes: 3 additions & 4 deletions lib/src/gear/file_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,16 @@ void pathToDirectoryAndFile(const std::string& path, std::string& directory, std
}
}

bool stringToLines(const string* text, vector<string*>& lines, unsigned long int &filesize)
bool stringToLines(const string* text, vector<string*>& lines)
{
if(text) {
filesize = text->size();
if(text && text->size()) {
istringstream input{*text};
string line;
while(getline(input, line)) {
// IMPROVE heap allocation possibly expensive
lines.push_back(new string{line});
}
return filesize>0;
return true;
} else {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/gear/file_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct File
};

void pathToDirectoryAndFile(const std::string& path, std::string& directory, std::string& file);
bool stringToLines(const std::string* text, std::vector<std::string*>& lines, unsigned long int &filesize);
bool stringToLines(const std::string* text, std::vector<std::string*>& lines);
bool fileToLines(const std::string* filename, std::vector<std::string*>& lines, unsigned long int &filesize);
std::string* fileToString(const std::string& filename);
void stringToFile(const std::string& filename, const std::string& content);
Expand Down
6 changes: 3 additions & 3 deletions lib/src/mind/mind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ string Mind::outlineNew(
const int8_t urgency,
const int8_t progress,
const vector<const Tag*>* tags,
const string* preamble,
const vector<string*>* preamble,
Stencil* outlineStencil)
{
string key = memory.createOutlineKey(name);
Expand All @@ -396,8 +396,8 @@ string Mind::outlineNew(
outline = new Outline{ontology().getDefaultOutlineType()};
}

if(preamble) {
outline->setPreamble(preamble);
if(preamble && preamble->size()) {
outline->setPreamble(*preamble);
}

if(outline) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/mind/mind.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ class Mind
const int8_t urgency = 0,
const int8_t progress = 0,
const std::vector<const Tag*>* tags = nullptr,
const std::string* preamble = nullptr,
Stencil *outlineStencil = nullptr);
const std::vector<std::string*>* preamble = nullptr,
Stencil* outlineStencil = nullptr);

Outline* outlineClone(const std::string& outlineKey);

Expand Down
3 changes: 1 addition & 2 deletions lib/src/representations/markdown/markdown_lexer_sections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ void MarkdownLexerSections::tokenize()

void MarkdownLexerSections::tokenize(const string* text)
{
fileSize = 0;
if(stringToLines(text, lines, fileSize)) {
if(stringToLines(text, lines)) {
// IMPROVE body of this function can be shared by file & text
lexems.push_back(MarkdownSymbolTable::LEXEM.BEGIN_DOC);

Expand Down
2 changes: 1 addition & 1 deletion lib/test/mindforger-lib-unit-tests.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.0.1, 2018-03-02T14:45:23. -->
<!-- Written by QtCreator 3.0.1, 2018-03-02T21:22:24. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
Expand Down
2 changes: 1 addition & 1 deletion mindforger.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.0.1, 2018-03-02T20:14:10. -->
<!-- Written by QtCreator 3.0.1, 2018-03-02T21:22:49. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
Expand Down
43 changes: 43 additions & 0 deletions src/qt/dialogs/outline_header_edit_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,32 @@ OutlineHeaderEditDialog::GeneralTab::~GeneralTab()
delete progressSpin;
}

/*
* Preamble tab
*/

OutlineHeaderEditDialog::PreambleTab::PreambleTab(QWidget *parent)
: QWidget(parent)
{
preambleLabel = new QLabel{tr("Text")+":", this};
preambleText = new QTextEdit{this};

QGroupBox* preambleGroup = new QGroupBox{tr("Preamble"), this};
QVBoxLayout* locationLayout = new QVBoxLayout{this};
locationLayout->addWidget(preambleLabel);
locationLayout->addWidget(preambleText);
preambleGroup->setLayout(locationLayout);

QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(preambleGroup);
mainLayout->addStretch();
setLayout(mainLayout);
}

OutlineHeaderEditDialog::PreambleTab::~PreambleTab()
{
}

/*
* Advanced tab
*/
Expand Down Expand Up @@ -172,6 +198,9 @@ OutlineHeaderEditDialog::OutlineHeaderEditDialog(Ontology& ontology, QWidget *pa
generalTab = new GeneralTab(ontology, this);
tabWidget->addTab(generalTab, tr("General"));

preambleTab = new PreambleTab(this);
tabWidget->addTab(preambleTab, tr("Preamble"));

advancedTab = new AdvancedTab{this};
tabWidget->addTab(advancedTab, tr("Advanced"));

Expand All @@ -197,6 +226,9 @@ OutlineHeaderEditDialog::OutlineHeaderEditDialog(Ontology& ontology, QWidget *pa

OutlineHeaderEditDialog::~OutlineHeaderEditDialog()
{
if(generalTab) delete generalTab;
if(preambleTab) delete preambleTab;
if(advancedTab) delete advancedTab;
}

void OutlineHeaderEditDialog::show()
Expand All @@ -216,6 +248,8 @@ void OutlineHeaderEditDialog::show()
generalTab->progressSpin->setValue(currentOutline->getProgress());
generalTab->editTagsGroup->refresh(currentOutline->getTags());

preambleTab->preambleText->setText(QString::fromStdString(currentOutline->getPreambleAsString()));

// RDONLY
advancedTab->createdLine->setText(QString::fromStdString(datetimeToString(currentOutline->getCreated())));
advancedTab->modifiedPanel->setText(QString::fromStdString(datetimeToString(currentOutline->getModified())));
Expand All @@ -238,6 +272,15 @@ void OutlineHeaderEditDialog::toOutline()
currentOutline->setUrgency(generalTab->urgencyCombo->currentIndex());
currentOutline->setProgress(generalTab->progressSpin->value());
currentOutline->setTags(generalTab->editTagsGroup->getTags());

// preamble
std::vector<std::string*> preamble;
if(preambleTab->getPreambleText().size()) {
std::string* preambleText = new std::string{preambleTab->getPreambleText().toStdString()};
stringToLines(preambleText, preamble);
delete preambleText;
}
currentOutline->setPreamble(preamble);
} else {
qDebug("Attempt to save data from dialog to Outline, but no Outline is set.");
}
Expand Down
24 changes: 24 additions & 0 deletions src/qt/dialogs/outline_header_edit_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ class OutlineHeaderEditDialog : public QDialog
Q_OBJECT

class GeneralTab;
class PreambleTab;
class AdvancedTab;

private:
Outline* currentOutline;
Ontology& ontology;

QTabWidget* tabWidget;
PreambleTab* preambleTag;
GeneralTab* generalTab;
PreambleTab* preambleTab;
AdvancedTab* advancedTab;

QDialogButtonBox *buttonBox;
Expand Down Expand Up @@ -104,6 +107,27 @@ class OutlineHeaderEditDialog::GeneralTab : public QWidget
~GeneralTab();
};

/**
* @brief Preamble tab of edit Outline dialog.
*/
class OutlineHeaderEditDialog::PreambleTab : public QWidget
{
Q_OBJECT

friend class OutlineHeaderEditDialog;

private:
QLabel* preambleLabel;
QTextEdit* preambleText;

public:
explicit PreambleTab(QWidget* parent);
~PreambleTab();

void refreshPreambleText(QString& t) { preambleText->setText(t); }
QString getPreambleText() const { return preambleText->toPlainText(); }
};

/**
* @brief Advanced tab of edit Outline dialog.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/qt/dialogs/outline_new_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ Stencil* OutlineNewDialog::getStencil() const
return generalTab->getStencilCombo()->itemData(generalTab->getStencilCombo()->currentIndex()).value<Stencil*>();
}

QString OutlineNewDialog::getPreamble() const
{
return preambleTab->getPreambleText();
}

const OutlineType* OutlineNewDialog::getOutlineType() const
{
return (const OutlineType*)(generalTab->getTypeCombo()->itemData(generalTab->getTypeCombo()->currentIndex(), Qt::UserRole).value<const OutlineType*>());
Expand Down
2 changes: 1 addition & 1 deletion src/qt/dialogs/outline_new_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class OutlineNewDialog : public QDialog
~OutlineNewDialog();

QString getOutlineName() const;
QString getPreamble() const { return preambleTab->getPreambleText(); }
QString getPreamble() const;
Stencil* getStencil() const;
const OutlineType* getOutlineType() const;
int8_t getImportance() const;
Expand Down
11 changes: 11 additions & 0 deletions src/qt/main_window_presenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,24 @@ void MainWindowPresenter::doActionOutlineNew()
void MainWindowPresenter::handleOutlineNew()
{
string name = newOutlineDialog->getOutlineName().toStdString();

// preamble
vector<string*>* preamble = nullptr;
if(newOutlineDialog->getPreamble().size()) {
string* preambleText = new string{newOutlineDialog->getPreamble().toStdString()};
preamble = new vector<string*>{};
stringToLines(preambleText, *preamble);
delete preambleText;
}

mind->outlineNew(
&name,
newOutlineDialog->getOutlineType(),
newOutlineDialog->getImportance(),
newOutlineDialog->getUrgency(),
newOutlineDialog->getProgress(),
newOutlineDialog->getTags(),
preamble,
newOutlineDialog->getStencil());

if(orloj->isFacetActive(OrlojPresenterFacets::FACET_LIST_OUTLINES)) {
Expand Down
2 changes: 1 addition & 1 deletion src/qt/outline_header_edit_presenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void OutlineHeaderEditPresenter::slotSaveOutlineHeader()
currentOutline->clearDescription();
}

// Outline metada (type, tags, progress, deadline) are set by Outline header edit dialog on it's close
// Outline metada (preamble, type, tags, progress, deadline) are set by Outline header edit dialog on it's close
// (if user doesn't open dialog, nothing is blindly saved there & here)

// IMPROVE if fields below are set on remembering (save) of Outline, then delete code below
Expand Down

0 comments on commit 4d3ac33

Please sign in to comment.